Skip to content

Commit

Permalink
Changed the character creation parameters to use the folder locator i…
Browse files Browse the repository at this point in the history
…nstead of raw paths
  • Loading branch information
Clément Couture committed Oct 21, 2021
1 parent cfa8e92 commit 11c9e75
Show file tree
Hide file tree
Showing 12 changed files with 1,448 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b5a3c15419c89c94aaee17490243dc93, type: 3}
m_Name: CharacterCreationParameters
m_EditorClassIdentifier:
characterFolder: Assets/Characters
characterPrefabFolderName: Prefabs
characterPreviewFolderName: Previews
characterDataFolderName: Data
characterPrefabFolderId: CharacterCreationTool.Destination.Prefab
characterPreviewFolderId: CharacterCreationTool.Destination.Preview
characterDataFolderId: CharacterCreationTool.Destination.Data
CharacterLogicPrefab: {fileID: 7450849567795141773, guid: 6363cc0f634bd004ea859073a8534f2a,
type: 3}
CharacterAnimatorController: {fileID: 9100000, guid: 8b9a677f24793ba45bdc27a1dab7745e,
Expand Down
31 changes: 20 additions & 11 deletions Assets/CharacterCreationTool/Editor/CharacterCreationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
public class CharacterCreationParameters : ScriptableObject {

public static CharacterCreationParameters Instance => AssetDatabaseUtils.GetSingle<CharacterCreationParameters>();

[SerializeField]
private string characterFolder = "Assets/";

[Header("Folder Names")]

[Header("Folders")]
[SerializeField]
private string characterPrefabFolderName;
private string characterPrefabFolderId;
[SerializeField]
private string characterPreviewFolderName;
private string characterPreviewFolderId;
[SerializeField]
private string characterDataFolderName;
private string characterDataFolderId;

[Header("References")]
public GameObject CharacterLogicPrefab;
Expand All @@ -29,9 +26,21 @@ public class CharacterCreationParameters : ScriptableObject {
[Dropdown(nameof(CreateDropdownList))]
public string Separator = ",";

public string CharacterPrefabFolder => Path.Combine(characterFolder, characterPrefabFolderName);
public string CharacterPreviewFolder => Path.Combine(characterFolder, characterPreviewFolderName);
public string CharacterDataFolder => Path.Combine(characterFolder, characterDataFolderName);
private string _characterPrefabFolder;
public string CharacterPrefabFolder =>
_characterPrefabFolder ??
(_characterPrefabFolder = FolderLocator.GetFolder(characterPrefabFolderId));


private string _characterPreviewFolder;
public string CharacterPreviewFolder =>
_characterPreviewFolder ??
(_characterPreviewFolder = FolderLocator.GetFolder(characterPreviewFolderId));

private string _characterDataFolder;
public string CharacterDataFolder =>
_characterDataFolder ??
(_characterDataFolder = FolderLocator.GetFolder(characterDataFolderId));

private DropdownList<string> CreateDropdownList() {
return new DropdownList<string> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.SceneManagement;
Expand Down Expand Up @@ -72,7 +73,11 @@ private void InSceneCreatePreview(GameObject previewTargetPrefab, string targetF
DestroyImmediate(outputTexture);
DestroyImmediate(previewTarget);
characterPreview.SetActive(true);


// Must wait here to force the loading of the sprite in the asset database
// before changing the import settings, otherwise it would not work.
AssetDatabase.ImportAsset(targetFile);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

ChangeImportSettings(targetFile);
Expand Down
1 change: 1 addition & 0 deletions Assets/Characters/CharacterList.asset
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ MonoBehaviour:
Characters:
- {fileID: 11400000, guid: 005506bef8dbb5547b4a558abd2080e6, type: 2}
- {fileID: 11400000, guid: b7b7d3808c2437e408bccb69d5019351, type: 2}
- {fileID: 11400000, guid: 6a153d3a3eca97545a04840ffb5f12ed, type: 2}
15 changes: 15 additions & 0 deletions Assets/Characters/Data/CharacterDataFolderLocator.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 16c0adaa0cf0a5549917b8a094766a50, type: 3}
m_Name: CharacterDataFolderLocator
m_EditorClassIdentifier:
FolderId: CharacterCreationTool.Destination.Data
8 changes: 8 additions & 0 deletions Assets/Characters/Data/CharacterDataFolderLocator.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Assets/Characters/Prefabs/CharacterPrefabFolderLocator.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 16c0adaa0cf0a5549917b8a094766a50, type: 3}
m_Name: CharacterPrefabFolderLocator
m_EditorClassIdentifier:
FolderId: CharacterCreationTool.Destination.Prefab

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Assets/Characters/Previews/CharacterPreviewFolderLocator.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 16c0adaa0cf0a5549917b8a094766a50, type: 3}
m_Name: CharacterPreviewFolderLocator
m_EditorClassIdentifier:
FolderId: CharacterCreationTool.Destination.Preview

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Assets/EditorPlus/Editor/FolderLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public static string GetFolder(string id) {

foreach (var folderLocator in locators) {
if (folderLocator.FolderId == id) {
return Path.GetFullPath(Path.GetDirectoryName(AssetDatabase.GetAssetPath(folderLocator)));
string folderPath = AssetDatabase.GetAssetPath(folderLocator);
return folderPath.Substring(0, folderPath.LastIndexOfAny(new []{
Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar
}));
}
}

Expand Down
Loading

0 comments on commit 11c9e75

Please sign in to comment.