From 741807ac9c42f8e49e81e7e500c92ab2b344d602 Mon Sep 17 00:00:00 2001 From: Sam Streed Date: Mon, 9 Sep 2019 16:41:31 -0500 Subject: [PATCH 1/7] Started work on FeatureLibrary --- Assets/Labrys/FeatureEditor/FeatureLibrary.cs | 172 ++++++++++++++++++ .../FeatureEditor/FeatureLibrary.cs.meta | 11 ++ 2 files changed, 183 insertions(+) create mode 100644 Assets/Labrys/FeatureEditor/FeatureLibrary.cs create mode 100644 Assets/Labrys/FeatureEditor/FeatureLibrary.cs.meta diff --git a/Assets/Labrys/FeatureEditor/FeatureLibrary.cs b/Assets/Labrys/FeatureEditor/FeatureLibrary.cs new file mode 100644 index 0000000..be82b6e --- /dev/null +++ b/Assets/Labrys/FeatureEditor/FeatureLibrary.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Labrys.FeatureEditor +{ + public class FeatureLibrary : IEnumerable + { + private const int INITIAL_ARR_SIZE = 4; + + private Dictionary nameToFAID; + private FeatureAsset[] features; + private int head; + + public int Count { get; private set; } + + public bool IsReadOnly => false; + + /// + /// With this enanabled, all Feature Asset IDs are persistent for the life of this library object. + /// WARNING: this may cause the space to run out sooner under high churn conditions. + /// + public bool PreserveFAIDs => false; + + public FeatureAsset this[ushort faid] + { + get + { + if (faid >= 0 && faid < features.Length) + { + return features[faid]; + } + return null; + } + } + + public FeatureAsset this[string name] + { + get => this[GetId(name)]; + set => Add(name, value); + } + + public FeatureLibrary() + { + nameToFAID = new Dictionary(); + features = new FeatureAsset[INITIAL_ARR_SIZE]; + Count = 0; + } + + public bool Add(string name, FeatureAsset feature) + { + if (name == null || feature == null) + return false; + + if (Count >= features.Length && !TryResize()) + { + throw new ArgumentOutOfRangeException($"This {nameof(FeatureLibrary)} is out of space!"); + } + + nameToFAID.Add(name, (ushort)head); + features[head] = feature; + + head++; + Count++; + + return true; + } + + public bool Remove(string name) + { + if (name == null) + return false; + + features[GetId(name)] = null; + return nameToFAID.Remove(name); + } + + public bool Remove(short faid) + { + features[faid] = null; + + List names = new List(); + foreach(KeyValuePair pair in nameToFAID) + { + if (pair.Value == faid) + names.Add(pair.Key); + } + + if (names.Count > 0) + { + foreach (string name in names) + { + nameToFAID.Remove(name); + } + Count--; + return true; + } + return false; + } + + public bool Contains(string name) => nameToFAID.ContainsKey(name); + + public void Clear() + { + nameToFAID.Clear(); + features = new FeatureAsset[INITIAL_ARR_SIZE]; + } + + public ushort GetId(string name) + { + if (nameToFAID.TryGetValue(name, out ushort faid)) + { + return faid; + } + throw new ArgumentException($"Unknown name: {name}."); + } + + /// + /// If PreserveFAIDs is set to false, then the array will be compacted + /// + /// + private bool TryResize() + { + if (Count >= short.MaxValue) + return false; + + FeatureAsset[] newArr = new FeatureAsset[features.Length * 2]; + if (PreserveFAIDs) + { + for (int i = 0; i < features.Length; i++) + { + if (features[i] != null) + { + newArr[i] = features[i]; + } + } + features = newArr; + return true; + } + else + { + //TODO: rebuild nameToFAID dictionary after compression + //NOTE: maybe use FeatureAsset#name instead of allowing user to set name + Dictionary newDict = new Dictionary(); + int j = 0; + for (int i = 0; i < features.Length; i++) + { + if (features[i] != null) + { + newArr[j] = features[i]; + newDict.Add + j++; + } + } + + head = j; + features = newArr; + return true; + } + } + + public IEnumerator GetEnumerator() + { + return ((IEnumerable)features).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)features).GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/Assets/Labrys/FeatureEditor/FeatureLibrary.cs.meta b/Assets/Labrys/FeatureEditor/FeatureLibrary.cs.meta new file mode 100644 index 0000000..3e5e9a7 --- /dev/null +++ b/Assets/Labrys/FeatureEditor/FeatureLibrary.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 56cac0c8c64b38c47bc5fc13147ebc83 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From c18ff6f2fdb26aae19d3adffe3989f559e86d39a Mon Sep 17 00:00:00 2001 From: Sam Streed Date: Wed, 11 Sep 2019 14:08:27 -0500 Subject: [PATCH 2/7] Checkpoint because running this code could break things... --- Assets/Labrys/FeatureEditor/FeatureLibrary.cs | 136 ++++-------------- 1 file changed, 30 insertions(+), 106 deletions(-) diff --git a/Assets/Labrys/FeatureEditor/FeatureLibrary.cs b/Assets/Labrys/FeatureEditor/FeatureLibrary.cs index be82b6e..5795394 100644 --- a/Assets/Labrys/FeatureEditor/FeatureLibrary.cs +++ b/Assets/Labrys/FeatureEditor/FeatureLibrary.cs @@ -1,26 +1,20 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; +#if UNITY_EDITOR +using UnityEditor; +#endif +using UnityEngine; namespace Labrys.FeatureEditor { - public class FeatureLibrary : IEnumerable + public class FeatureLibrary : ScriptableObject, IEnumerable { - private const int INITIAL_ARR_SIZE = 4; - private Dictionary nameToFAID; private FeatureAsset[] features; - private int head; - - public int Count { get; private set; } - - public bool IsReadOnly => false; - /// - /// With this enanabled, all Feature Asset IDs are persistent for the life of this library object. - /// WARNING: this may cause the space to run out sooner under high churn conditions. - /// - public bool PreserveFAIDs => false; + public int Count => features.Length; public FeatureAsset this[ushort faid] { @@ -37,75 +31,49 @@ public FeatureAsset this[ushort faid] public FeatureAsset this[string name] { get => this[GetId(name)]; - set => Add(name, value); + private set => Add(name, value); } - public FeatureLibrary() +#if UNITY_EDITOR + [MenuItem("Assets/Create/Labrys/Feature Library")] + private static void FromDirectory() { - nameToFAID = new Dictionary(); - features = new FeatureAsset[INITIAL_ARR_SIZE]; - Count = 0; - } + string loadPath = $"Assets/{EditorUtility.OpenFolderPanel("Select target folder", "Assets", "").Replace(Application.dataPath, "")}"; + string savePath = $"{AssetDatabase.GetAssetPath(Selection.activeInstanceID)}/NewFeatureLibrary.asset"; - public bool Add(string name, FeatureAsset feature) - { - if (name == null || feature == null) - return false; + Debug.Log($"Load path: {loadPath}"); + Debug.Log($"Save path: {savePath}"); + string[] assets = AssetDatabase.FindAssets("t:FeatureAsset", new string[] { loadPath }); - if (Count >= features.Length && !TryResize()) + FeatureLibrary library = CreateInstance(); + foreach (string asset in assets) { - throw new ArgumentOutOfRangeException($"This {nameof(FeatureLibrary)} is out of space!"); + library.Add(asset, AssetDatabase.LoadAssetAtPath(asset)); } - nameToFAID.Add(name, (ushort)head); - features[head] = feature; - - head++; - Count++; - - return true; + ProjectWindowUtil.CreateAsset(library, savePath); } +#endif - public bool Remove(string name) + private FeatureLibrary(int capacity) { - if (name == null) - return false; - - features[GetId(name)] = null; - return nameToFAID.Remove(name); + nameToFAID = new Dictionary(); + features = new FeatureAsset[capacity]; } - public bool Remove(short faid) + private bool Add(string name, FeatureAsset feature) { - features[faid] = null; + if (name == null || feature == null) + return false; - List names = new List(); - foreach(KeyValuePair pair in nameToFAID) - { - if (pair.Value == faid) - names.Add(pair.Key); - } + nameToFAID.Add(name, (ushort)nameToFAID.Count); + features[nameToFAID.Count] = feature; - if (names.Count > 0) - { - foreach (string name in names) - { - nameToFAID.Remove(name); - } - Count--; - return true; - } - return false; + return true; } public bool Contains(string name) => nameToFAID.ContainsKey(name); - public void Clear() - { - nameToFAID.Clear(); - features = new FeatureAsset[INITIAL_ARR_SIZE]; - } - public ushort GetId(string name) { if (nameToFAID.TryGetValue(name, out ushort faid)) @@ -115,50 +83,6 @@ public ushort GetId(string name) throw new ArgumentException($"Unknown name: {name}."); } - /// - /// If PreserveFAIDs is set to false, then the array will be compacted - /// - /// - private bool TryResize() - { - if (Count >= short.MaxValue) - return false; - - FeatureAsset[] newArr = new FeatureAsset[features.Length * 2]; - if (PreserveFAIDs) - { - for (int i = 0; i < features.Length; i++) - { - if (features[i] != null) - { - newArr[i] = features[i]; - } - } - features = newArr; - return true; - } - else - { - //TODO: rebuild nameToFAID dictionary after compression - //NOTE: maybe use FeatureAsset#name instead of allowing user to set name - Dictionary newDict = new Dictionary(); - int j = 0; - for (int i = 0; i < features.Length; i++) - { - if (features[i] != null) - { - newArr[j] = features[i]; - newDict.Add - j++; - } - } - - head = j; - features = newArr; - return true; - } - } - public IEnumerator GetEnumerator() { return ((IEnumerable)features).GetEnumerator(); From 48975b88d9de0639c5fe8063928f398b6bb55447 Mon Sep 17 00:00:00 2001 From: Sam Streed Date: Wed, 11 Sep 2019 16:45:34 -0500 Subject: [PATCH 3/7] Working prototype. Generated names aren't working properly. --- Assets/Labrys/FeatureEditor/FeatureLibrary.cs | 100 ++++++++++++++---- 1 file changed, 78 insertions(+), 22 deletions(-) diff --git a/Assets/Labrys/FeatureEditor/FeatureLibrary.cs b/Assets/Labrys/FeatureEditor/FeatureLibrary.cs index 5795394..e66ab81 100644 --- a/Assets/Labrys/FeatureEditor/FeatureLibrary.cs +++ b/Assets/Labrys/FeatureEditor/FeatureLibrary.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.IO; #if UNITY_EDITOR using UnityEditor; #endif @@ -9,24 +8,18 @@ namespace Labrys.FeatureEditor { - public class FeatureLibrary : ScriptableObject, IEnumerable + public class FeatureLibrary : ScriptableObject, IEnumerable, ISerializationCallbackReceiver { + [field: SerializeField] + //[field: HideInInspector] + public string TargetDirectory { get; private set; } + private Dictionary nameToFAID; private FeatureAsset[] features; public int Count => features.Length; - public FeatureAsset this[ushort faid] - { - get - { - if (faid >= 0 && faid < features.Length) - { - return features[faid]; - } - return null; - } - } + public FeatureAsset this[ushort faid] => Contains(faid) ? features[faid] : null; public FeatureAsset this[string name] { @@ -38,42 +31,65 @@ public FeatureAsset this[string name] [MenuItem("Assets/Create/Labrys/Feature Library")] private static void FromDirectory() { - string loadPath = $"Assets/{EditorUtility.OpenFolderPanel("Select target folder", "Assets", "").Replace(Application.dataPath, "")}"; + string loadPath = $"Assets/{EditorUtility.OpenFolderPanel("Select target Feature folder", "Assets", "").Replace(Application.dataPath, "")}"; string savePath = $"{AssetDatabase.GetAssetPath(Selection.activeInstanceID)}/NewFeatureLibrary.asset"; - Debug.Log($"Load path: {loadPath}"); - Debug.Log($"Save path: {savePath}"); - string[] assets = AssetDatabase.FindAssets("t:FeatureAsset", new string[] { loadPath }); + string[] assetGUIDs = AssetDatabase.FindAssets($"t:{nameof(FeatureAsset)}", new string[] { loadPath }); FeatureLibrary library = CreateInstance(); - foreach (string asset in assets) + library.TargetDirectory = loadPath; + library.features = new FeatureAsset[assetGUIDs.Length]; + foreach (string guid in assetGUIDs) { - library.Add(asset, AssetDatabase.LoadAssetAtPath(asset)); + string path = AssetDatabase.GUIDToAssetPath(guid); + string name = path.Replace(library.TargetDirectory, "").Replace(".asset", ""); + library.Add(name, AssetDatabase.LoadAssetAtPath(path)); } ProjectWindowUtil.CreateAsset(library, savePath); } #endif - private FeatureLibrary(int capacity) + private FeatureLibrary() { nameToFAID = new Dictionary(); - features = new FeatureAsset[capacity]; + features = new FeatureAsset[0]; + } + +#if UNITY_EDITOR + public void Refresh() + { + string[] assetGUIDs = AssetDatabase.FindAssets($"t:{nameof(FeatureAsset)}", new string[] { TargetDirectory }); + nameToFAID.Clear(); + features = new FeatureAsset[assetGUIDs.Length]; + + foreach (string guid in assetGUIDs) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + Add(path.Replace(TargetDirectory, "").Replace(".asset", ""), AssetDatabase.LoadAssetAtPath(path)); + } } +#endif private bool Add(string name, FeatureAsset feature) { if (name == null || feature == null) return false; - nameToFAID.Add(name, (ushort)nameToFAID.Count); features[nameToFAID.Count] = feature; + nameToFAID.Add(name, (ushort)nameToFAID.Count); return true; } + public FeatureAsset GetFeature(string name) => this[name]; + + public FeatureAsset GetFeature(ushort faid) => this[faid]; + public bool Contains(string name) => nameToFAID.ContainsKey(name); + public bool Contains(ushort faid) => 0 <= faid && faid < features.Length; + public ushort GetId(string name) { if (nameToFAID.TryGetValue(name, out ushort faid)) @@ -92,5 +108,45 @@ IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)features).GetEnumerator(); } + +#region SERIALIZATION + [SerializeField] + private List serializedNames; + [SerializeField] + private List serializedFeatures; + + public void OnBeforeSerialize() + { + if (nameToFAID == null || features == null) + return; + + serializedNames = new List(); + serializedFeatures = new List(); + foreach(KeyValuePair pair in nameToFAID) + { + serializedNames.Add(pair.Key); + serializedFeatures.Add(features[pair.Value]); + } + nameToFAID = null; + features = null; + } + + public void OnAfterDeserialize() + { + if (serializedNames == null + || serializedFeatures == null + || serializedNames.Count != serializedFeatures.Count) + return; + + nameToFAID = new Dictionary(); + features = new FeatureAsset[serializedFeatures.Count]; + for (int i = 0; i < serializedNames.Count; i++) + { + Add(serializedNames[i], serializedFeatures[i]); + } + serializedNames = null; + serializedFeatures = null; + } +#endregion } } \ No newline at end of file From b9e9b8a3d68e36294a3d1d89470e0a138c9d4be4 Mon Sep 17 00:00:00 2001 From: Sam Streed Date: Thu, 12 Sep 2019 17:00:52 -0500 Subject: [PATCH 4/7] Tweaks and polish to FeatureLibrary creating and refreshing. Created custom FeatureLibrary inspector --- .../FeatureEditor/FeatureEditorWindow.cs | 2 +- .../Labrys/Editor/FeatureLibraryInspector.cs | 63 +++++++++++++++++++ .../Editor/FeatureLibraryInspector.cs.meta | 11 ++++ .../Labrys/FeatureEditor/AnotherFeature.asset | 19 ++++++ .../FeatureEditor/AnotherFeature.asset.meta | 8 +++ Assets/Labrys/FeatureEditor/FeatureLib.asset | 26 ++++++++ .../FeatureEditor/FeatureLib.asset.meta | 8 +++ .../{FeatureEditor => }/FeatureLibrary.cs | 60 +++++++++++------- .../FeatureLibrary.cs.meta | 0 9 files changed, 173 insertions(+), 24 deletions(-) create mode 100644 Assets/Labrys/Editor/FeatureLibraryInspector.cs create mode 100644 Assets/Labrys/Editor/FeatureLibraryInspector.cs.meta create mode 100644 Assets/Labrys/FeatureEditor/AnotherFeature.asset create mode 100644 Assets/Labrys/FeatureEditor/AnotherFeature.asset.meta create mode 100644 Assets/Labrys/FeatureEditor/FeatureLib.asset create mode 100644 Assets/Labrys/FeatureEditor/FeatureLib.asset.meta rename Assets/Labrys/{FeatureEditor => }/FeatureLibrary.cs (67%) rename Assets/Labrys/{FeatureEditor => }/FeatureLibrary.cs.meta (100%) diff --git a/Assets/Labrys/Editor/FeatureEditor/FeatureEditorWindow.cs b/Assets/Labrys/Editor/FeatureEditor/FeatureEditorWindow.cs index 99a758d..82837cc 100644 --- a/Assets/Labrys/Editor/FeatureEditor/FeatureEditorWindow.cs +++ b/Assets/Labrys/Editor/FeatureEditor/FeatureEditorWindow.cs @@ -22,7 +22,7 @@ public static FeatureEditorWindow GetInstance() return instance; } - [MenuItem("Window/Labrys Feature Editor")] + [MenuItem("Window/Labrys/Feature Editor")] private static FeatureEditorWindow OpenWindow() { FeatureEditorWindow window = GetWindow(); diff --git a/Assets/Labrys/Editor/FeatureLibraryInspector.cs b/Assets/Labrys/Editor/FeatureLibraryInspector.cs new file mode 100644 index 0000000..35bb642 --- /dev/null +++ b/Assets/Labrys/Editor/FeatureLibraryInspector.cs @@ -0,0 +1,63 @@ +using Labrys.FeatureEditor; +using UnityEngine; +using UnityEditor; +using System.Collections.Generic; + +namespace Labrys.Editor +{ + [CustomEditor(typeof(FeatureLibrary))] + public class FeatureLibraryInspector : UnityEditor.Editor + { + private FeatureLibrary library; + private bool autoRefresh; + private Vector2 scrollPosition; + + private void OnEnable() + { + library = (FeatureLibrary)target; + } + + public override void OnInspectorGUI() + { + serializedObject.UpdateIfRequiredOrScript(); + library.OnAfterDeserialize(); + + GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); + if (GUILayout.Button("Refresh")) + { + library.Refresh(); + } + + bool newAutoRefresh = GUILayout.Toggle(autoRefresh, "Auto"); + if (newAutoRefresh != autoRefresh) + { + autoRefresh = newAutoRefresh; + if (autoRefresh) + { + //TODO ??? + } + } + GUILayout.EndHorizontal(); + + GUILayout.Space(25); + GUILayout.Label("Contains:", EditorStyles.boldLabel); + scrollPosition = GUILayout.BeginScrollView(scrollPosition); + foreach(KeyValuePair entry in library) + { + if (GUILayout.Button(entry.Key)) + { + ProjectWindowUtil.ShowCreatedAsset(entry.Value); + } + } + GUILayout.EndScrollView(); + } + + private class AssetDatabaseListener : UnityEditor.AssetModificationProcessor + { + private static void OnWillCreateAsset(string assetName) + { + + } + } + } +} \ No newline at end of file diff --git a/Assets/Labrys/Editor/FeatureLibraryInspector.cs.meta b/Assets/Labrys/Editor/FeatureLibraryInspector.cs.meta new file mode 100644 index 0000000..ddbbd38 --- /dev/null +++ b/Assets/Labrys/Editor/FeatureLibraryInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c9c61dcb6aa00284a8a5e4bb17abb6b6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Labrys/FeatureEditor/AnotherFeature.asset b/Assets/Labrys/FeatureEditor/AnotherFeature.asset new file mode 100644 index 0000000..f95f897 --- /dev/null +++ b/Assets/Labrys/FeatureEditor/AnotherFeature.asset @@ -0,0 +1,19 @@ +%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: f132721a9c505654498a40770d09b4af, type: 3} + m_Name: AnotherFeature + m_EditorClassIdentifier: + sectionPositions: [] + sectionData: [] + linkPositions: [] + linkData: [] + selectionPositions: [] diff --git a/Assets/Labrys/FeatureEditor/AnotherFeature.asset.meta b/Assets/Labrys/FeatureEditor/AnotherFeature.asset.meta new file mode 100644 index 0000000..06e28dd --- /dev/null +++ b/Assets/Labrys/FeatureEditor/AnotherFeature.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d93a59ab44bab0e4dbfcdde325c92019 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Labrys/FeatureEditor/FeatureLib.asset b/Assets/Labrys/FeatureEditor/FeatureLib.asset new file mode 100644 index 0000000..3425d23 --- /dev/null +++ b/Assets/Labrys/FeatureEditor/FeatureLib.asset @@ -0,0 +1,26 @@ +%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: 56cac0c8c64b38c47bc5fc13147ebc83, type: 3} + m_Name: FeatureLib + m_EditorClassIdentifier: + k__BackingField: Assets/Labrys/FeatureEditor + k__BackingField: 0 + serializedNames: + - AnotherFeature + - FeatureFolder/AnotherSpecialFeature + - FeatureFolder/SpecialFeature + - TestFeature + serializedFeatures: + - {fileID: 11400000, guid: d93a59ab44bab0e4dbfcdde325c92019, type: 2} + - {fileID: 11400000, guid: 91df815d615dd4d41883592e5850eb45, type: 2} + - {fileID: 11400000, guid: 50e472b510a23de47a596b9e1e49581f, type: 2} + - {fileID: 11400000, guid: 3c9906764ccf06948a8aab32a03352b4, type: 2} diff --git a/Assets/Labrys/FeatureEditor/FeatureLib.asset.meta b/Assets/Labrys/FeatureEditor/FeatureLib.asset.meta new file mode 100644 index 0000000..cd4c71c --- /dev/null +++ b/Assets/Labrys/FeatureEditor/FeatureLib.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b137fd24c95d34044bbbec148036a3d8 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Labrys/FeatureEditor/FeatureLibrary.cs b/Assets/Labrys/FeatureLibrary.cs similarity index 67% rename from Assets/Labrys/FeatureEditor/FeatureLibrary.cs rename to Assets/Labrys/FeatureLibrary.cs index e66ab81..9ef87d8 100644 --- a/Assets/Labrys/FeatureEditor/FeatureLibrary.cs +++ b/Assets/Labrys/FeatureLibrary.cs @@ -1,17 +1,18 @@ +using Labrys.FeatureEditor; using System; using System.Collections; using System.Collections.Generic; +using System.IO; #if UNITY_EDITOR using UnityEditor; #endif using UnityEngine; -namespace Labrys.FeatureEditor +namespace Labrys { - public class FeatureLibrary : ScriptableObject, IEnumerable, ISerializationCallbackReceiver + public class FeatureLibrary : ScriptableObject, IEnumerable>, ISerializationCallbackReceiver { [field: SerializeField] - //[field: HideInInspector] public string TargetDirectory { get; private set; } private Dictionary nameToFAID; @@ -19,6 +20,11 @@ public class FeatureLibrary : ScriptableObject, IEnumerable, ISeri public int Count => features.Length; +#if UNITY_EDITOR + [field: SerializeField] + public bool AutoRefresh { get; set; } //TODO figure out how to hook into asset creation process for auto refresh; or maybe auto refresh on playmode start +#endif + public FeatureAsset this[ushort faid] => Contains(faid) ? features[faid] : null; public FeatureAsset this[string name] @@ -31,20 +37,18 @@ public FeatureAsset this[string name] [MenuItem("Assets/Create/Labrys/Feature Library")] private static void FromDirectory() { - string loadPath = $"Assets/{EditorUtility.OpenFolderPanel("Select target Feature folder", "Assets", "").Replace(Application.dataPath, "")}"; - string savePath = $"{AssetDatabase.GetAssetPath(Selection.activeInstanceID)}/NewFeatureLibrary.asset"; + string saveDir = AssetDatabase.GetAssetPath(Selection.activeInstanceID); + if (!File.GetAttributes(saveDir).HasFlag(FileAttributes.Directory)) + saveDir = saveDir.Replace(Path.GetFileName(saveDir), ""); + + string loadPath = $"Assets{EditorUtility.OpenFolderPanel("Select target Feature folder", saveDir, "").Replace(Application.dataPath, "")}"; + string savePath = $"{saveDir}/NewFeatureLibrary.asset"; string[] assetGUIDs = AssetDatabase.FindAssets($"t:{nameof(FeatureAsset)}", new string[] { loadPath }); FeatureLibrary library = CreateInstance(); library.TargetDirectory = loadPath; - library.features = new FeatureAsset[assetGUIDs.Length]; - foreach (string guid in assetGUIDs) - { - string path = AssetDatabase.GUIDToAssetPath(guid); - string name = path.Replace(library.TargetDirectory, "").Replace(".asset", ""); - library.Add(name, AssetDatabase.LoadAssetAtPath(path)); - } + library.Refresh(); ProjectWindowUtil.CreateAsset(library, savePath); } @@ -60,13 +64,17 @@ private FeatureLibrary() public void Refresh() { string[] assetGUIDs = AssetDatabase.FindAssets($"t:{nameof(FeatureAsset)}", new string[] { TargetDirectory }); - nameToFAID.Clear(); - features = new FeatureAsset[assetGUIDs.Length]; - - foreach (string guid in assetGUIDs) + if (features != null && assetGUIDs.Length != features.Length) { - string path = AssetDatabase.GUIDToAssetPath(guid); - Add(path.Replace(TargetDirectory, "").Replace(".asset", ""), AssetDatabase.LoadAssetAtPath(path)); + nameToFAID = new Dictionary(); + features = new FeatureAsset[assetGUIDs.Length]; + + foreach (string guid in assetGUIDs) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + Add(path.Replace(TargetDirectory, "").Replace(".asset", "").TrimStart('/'), + AssetDatabase.LoadAssetAtPath(path)); + } } } #endif @@ -99,17 +107,23 @@ public ushort GetId(string name) throw new ArgumentException($"Unknown name: {name}."); } - public IEnumerator GetEnumerator() + public IEnumerator> GetEnumerator() { - return ((IEnumerable)features).GetEnumerator(); + if (nameToFAID == null) + yield break; + + foreach(KeyValuePair entry in nameToFAID) + { + yield return new KeyValuePair(entry.Key, this[entry.Value]); + } } IEnumerator IEnumerable.GetEnumerator() { - return ((IEnumerable)features).GetEnumerator(); + return GetEnumerator(); } -#region SERIALIZATION + #region SERIALIZATION [SerializeField] private List serializedNames; [SerializeField] @@ -147,6 +161,6 @@ public void OnAfterDeserialize() serializedNames = null; serializedFeatures = null; } -#endregion + #endregion } } \ No newline at end of file diff --git a/Assets/Labrys/FeatureEditor/FeatureLibrary.cs.meta b/Assets/Labrys/FeatureLibrary.cs.meta similarity index 100% rename from Assets/Labrys/FeatureEditor/FeatureLibrary.cs.meta rename to Assets/Labrys/FeatureLibrary.cs.meta From 0b8ebe102e8a7113b3a5a03c80b9dc67a3c4976d Mon Sep 17 00:00:00 2001 From: Sam Streed Date: Fri, 13 Sep 2019 16:59:11 -0500 Subject: [PATCH 5/7] Cleaned up inspector GUI. Ditched auto-refresh, at least for now. --- Assets/Features.meta | 8 +++ Assets/Features/ABrandNewHell.asset | 19 +++++++ .../ABrandNewHell.asset.meta} | 2 +- Assets/Features/AThirdFeature.asset | 19 +++++++ Assets/Features/AThirdFeature.asset.meta | 8 +++ .../AnotherFeature.asset | 0 .../AnotherFeature.asset.meta | 0 Assets/Features/Special.meta | 8 +++ .../Special/ActuallyPrettySpecial.asset | 19 +++++++ .../Special/ActuallyPrettySpecial.asset.meta | 8 +++ .../Features/Special/ButNotThatSpecial.asset | 19 +++++++ .../Special/ButNotThatSpecial.asset.meta | 8 +++ .../Special/RidingSomeCoattails.asset | 19 +++++++ .../Special/RidingSomeCoattails.asset.meta | 8 +++ Assets/Features/Special/Specialer.meta | 8 +++ .../Specialer/OnlyTheBestFeatureEver.asset | 19 +++++++ .../OnlyTheBestFeatureEver.asset.meta | 8 +++ .../TestFeature.asset | 0 .../TestFeature.asset.meta | 0 .../TestLib.asset} | 19 ++++--- Assets/Features/TestLib.asset.meta | 8 +++ .../Labrys/Editor/FeatureLibraryInspector.cs | 34 +++-------- Assets/Labrys/FeatureLibrary.cs | 57 ++++++++++++------- 23 files changed, 244 insertions(+), 54 deletions(-) create mode 100644 Assets/Features.meta create mode 100644 Assets/Features/ABrandNewHell.asset rename Assets/{Labrys/FeatureEditor/FeatureLib.asset.meta => Features/ABrandNewHell.asset.meta} (79%) create mode 100644 Assets/Features/AThirdFeature.asset create mode 100644 Assets/Features/AThirdFeature.asset.meta rename Assets/{Labrys/FeatureEditor => Features}/AnotherFeature.asset (100%) rename Assets/{Labrys/FeatureEditor => Features}/AnotherFeature.asset.meta (100%) create mode 100644 Assets/Features/Special.meta create mode 100644 Assets/Features/Special/ActuallyPrettySpecial.asset create mode 100644 Assets/Features/Special/ActuallyPrettySpecial.asset.meta create mode 100644 Assets/Features/Special/ButNotThatSpecial.asset create mode 100644 Assets/Features/Special/ButNotThatSpecial.asset.meta create mode 100644 Assets/Features/Special/RidingSomeCoattails.asset create mode 100644 Assets/Features/Special/RidingSomeCoattails.asset.meta create mode 100644 Assets/Features/Special/Specialer.meta create mode 100644 Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset create mode 100644 Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset.meta rename Assets/{Labrys/FeatureEditor => Features}/TestFeature.asset (100%) rename Assets/{Labrys/FeatureEditor => Features}/TestFeature.asset.meta (100%) rename Assets/{Labrys/FeatureEditor/FeatureLib.asset => Features/TestLib.asset} (51%) create mode 100644 Assets/Features/TestLib.asset.meta diff --git a/Assets/Features.meta b/Assets/Features.meta new file mode 100644 index 0000000..2c6d03c --- /dev/null +++ b/Assets/Features.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 86fa19d9723e7f54880785c8f542ea52 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Features/ABrandNewHell.asset b/Assets/Features/ABrandNewHell.asset new file mode 100644 index 0000000..23fe9ee --- /dev/null +++ b/Assets/Features/ABrandNewHell.asset @@ -0,0 +1,19 @@ +%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: f132721a9c505654498a40770d09b4af, type: 3} + m_Name: ABrandNewHell + m_EditorClassIdentifier: + sectionPositions: [] + sectionData: [] + linkPositions: [] + linkData: [] + selectionPositions: [] diff --git a/Assets/Labrys/FeatureEditor/FeatureLib.asset.meta b/Assets/Features/ABrandNewHell.asset.meta similarity index 79% rename from Assets/Labrys/FeatureEditor/FeatureLib.asset.meta rename to Assets/Features/ABrandNewHell.asset.meta index cd4c71c..57a3e4c 100644 --- a/Assets/Labrys/FeatureEditor/FeatureLib.asset.meta +++ b/Assets/Features/ABrandNewHell.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b137fd24c95d34044bbbec148036a3d8 +guid: b681495fc9c35c7489630a9339b5ff25 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/Assets/Features/AThirdFeature.asset b/Assets/Features/AThirdFeature.asset new file mode 100644 index 0000000..17c0000 --- /dev/null +++ b/Assets/Features/AThirdFeature.asset @@ -0,0 +1,19 @@ +%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: f132721a9c505654498a40770d09b4af, type: 3} + m_Name: AThirdFeature + m_EditorClassIdentifier: + sectionPositions: [] + sectionData: [] + linkPositions: [] + linkData: [] + selectionPositions: [] diff --git a/Assets/Features/AThirdFeature.asset.meta b/Assets/Features/AThirdFeature.asset.meta new file mode 100644 index 0000000..69242f4 --- /dev/null +++ b/Assets/Features/AThirdFeature.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8f89382a948fc644aa755003901f95b4 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Labrys/FeatureEditor/AnotherFeature.asset b/Assets/Features/AnotherFeature.asset similarity index 100% rename from Assets/Labrys/FeatureEditor/AnotherFeature.asset rename to Assets/Features/AnotherFeature.asset diff --git a/Assets/Labrys/FeatureEditor/AnotherFeature.asset.meta b/Assets/Features/AnotherFeature.asset.meta similarity index 100% rename from Assets/Labrys/FeatureEditor/AnotherFeature.asset.meta rename to Assets/Features/AnotherFeature.asset.meta diff --git a/Assets/Features/Special.meta b/Assets/Features/Special.meta new file mode 100644 index 0000000..40d3a9b --- /dev/null +++ b/Assets/Features/Special.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e8c7f09b4b306944b96e46781987451d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Features/Special/ActuallyPrettySpecial.asset b/Assets/Features/Special/ActuallyPrettySpecial.asset new file mode 100644 index 0000000..5f5d2b9 --- /dev/null +++ b/Assets/Features/Special/ActuallyPrettySpecial.asset @@ -0,0 +1,19 @@ +%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: f132721a9c505654498a40770d09b4af, type: 3} + m_Name: ActuallyPrettySpecial + m_EditorClassIdentifier: + sectionPositions: [] + sectionData: [] + linkPositions: [] + linkData: [] + selectionPositions: [] diff --git a/Assets/Features/Special/ActuallyPrettySpecial.asset.meta b/Assets/Features/Special/ActuallyPrettySpecial.asset.meta new file mode 100644 index 0000000..f08d93b --- /dev/null +++ b/Assets/Features/Special/ActuallyPrettySpecial.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6a523fcf115a9c04a92515fdc06e638f +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Features/Special/ButNotThatSpecial.asset b/Assets/Features/Special/ButNotThatSpecial.asset new file mode 100644 index 0000000..8e6759c --- /dev/null +++ b/Assets/Features/Special/ButNotThatSpecial.asset @@ -0,0 +1,19 @@ +%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: f132721a9c505654498a40770d09b4af, type: 3} + m_Name: ButNotThatSpecial + m_EditorClassIdentifier: + sectionPositions: [] + sectionData: [] + linkPositions: [] + linkData: [] + selectionPositions: [] diff --git a/Assets/Features/Special/ButNotThatSpecial.asset.meta b/Assets/Features/Special/ButNotThatSpecial.asset.meta new file mode 100644 index 0000000..29968f2 --- /dev/null +++ b/Assets/Features/Special/ButNotThatSpecial.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 655f469db20febe4cbf90188ae201aaf +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Features/Special/RidingSomeCoattails.asset b/Assets/Features/Special/RidingSomeCoattails.asset new file mode 100644 index 0000000..9fa9687 --- /dev/null +++ b/Assets/Features/Special/RidingSomeCoattails.asset @@ -0,0 +1,19 @@ +%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: f132721a9c505654498a40770d09b4af, type: 3} + m_Name: RidingSomeCoattails + m_EditorClassIdentifier: + sectionPositions: [] + sectionData: [] + linkPositions: [] + linkData: [] + selectionPositions: [] diff --git a/Assets/Features/Special/RidingSomeCoattails.asset.meta b/Assets/Features/Special/RidingSomeCoattails.asset.meta new file mode 100644 index 0000000..b929750 --- /dev/null +++ b/Assets/Features/Special/RidingSomeCoattails.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 31969de8ead96d64b9c73162313380ca +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Features/Special/Specialer.meta b/Assets/Features/Special/Specialer.meta new file mode 100644 index 0000000..e83475f --- /dev/null +++ b/Assets/Features/Special/Specialer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 14850bcb5f265c141a04d4206f8b74f1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset b/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset new file mode 100644 index 0000000..ddfc313 --- /dev/null +++ b/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset @@ -0,0 +1,19 @@ +%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: f132721a9c505654498a40770d09b4af, type: 3} + m_Name: OnlyTheBestFeatureEver + m_EditorClassIdentifier: + sectionPositions: [] + sectionData: [] + linkPositions: [] + linkData: [] + selectionPositions: [] diff --git a/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset.meta b/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset.meta new file mode 100644 index 0000000..919cca4 --- /dev/null +++ b/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f8f77afd442ed674884132731ce9f8e8 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Labrys/FeatureEditor/TestFeature.asset b/Assets/Features/TestFeature.asset similarity index 100% rename from Assets/Labrys/FeatureEditor/TestFeature.asset rename to Assets/Features/TestFeature.asset diff --git a/Assets/Labrys/FeatureEditor/TestFeature.asset.meta b/Assets/Features/TestFeature.asset.meta similarity index 100% rename from Assets/Labrys/FeatureEditor/TestFeature.asset.meta rename to Assets/Features/TestFeature.asset.meta diff --git a/Assets/Labrys/FeatureEditor/FeatureLib.asset b/Assets/Features/TestLib.asset similarity index 51% rename from Assets/Labrys/FeatureEditor/FeatureLib.asset rename to Assets/Features/TestLib.asset index 3425d23..f1e4196 100644 --- a/Assets/Labrys/FeatureEditor/FeatureLib.asset +++ b/Assets/Features/TestLib.asset @@ -10,17 +10,22 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 56cac0c8c64b38c47bc5fc13147ebc83, type: 3} - m_Name: FeatureLib + m_Name: TestLib m_EditorClassIdentifier: - k__BackingField: Assets/Labrys/FeatureEditor - k__BackingField: 0 + k__BackingField: Assets/Features serializedNames: - AnotherFeature - - FeatureFolder/AnotherSpecialFeature - - FeatureFolder/SpecialFeature + - AThirdFeature + - Special/ActuallyPrettySpecial + - Special/ButNotThatSpecial + - Special/RidingSomeCoattails + - Special/Specialer/OnlyTheBestFeatureEver - TestFeature serializedFeatures: - {fileID: 11400000, guid: d93a59ab44bab0e4dbfcdde325c92019, type: 2} - - {fileID: 11400000, guid: 91df815d615dd4d41883592e5850eb45, type: 2} - - {fileID: 11400000, guid: 50e472b510a23de47a596b9e1e49581f, type: 2} + - {fileID: 11400000, guid: 8f89382a948fc644aa755003901f95b4, type: 2} + - {fileID: 11400000, guid: 6a523fcf115a9c04a92515fdc06e638f, type: 2} + - {fileID: 11400000, guid: 655f469db20febe4cbf90188ae201aaf, type: 2} + - {fileID: 11400000, guid: 31969de8ead96d64b9c73162313380ca, type: 2} + - {fileID: 11400000, guid: f8f77afd442ed674884132731ce9f8e8, type: 2} - {fileID: 11400000, guid: 3c9906764ccf06948a8aab32a03352b4, type: 2} diff --git a/Assets/Features/TestLib.asset.meta b/Assets/Features/TestLib.asset.meta new file mode 100644 index 0000000..0b5d3d3 --- /dev/null +++ b/Assets/Features/TestLib.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9ee43cb5049591848aa7430d58266fba +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Labrys/Editor/FeatureLibraryInspector.cs b/Assets/Labrys/Editor/FeatureLibraryInspector.cs index 35bb642..ffec4e1 100644 --- a/Assets/Labrys/Editor/FeatureLibraryInspector.cs +++ b/Assets/Labrys/Editor/FeatureLibraryInspector.cs @@ -1,7 +1,5 @@ -using Labrys.FeatureEditor; -using UnityEngine; +using UnityEngine; using UnityEditor; -using System.Collections.Generic; namespace Labrys.Editor { @@ -9,7 +7,6 @@ namespace Labrys.Editor public class FeatureLibraryInspector : UnityEditor.Editor { private FeatureLibrary library; - private bool autoRefresh; private Vector2 scrollPosition; private void OnEnable() @@ -22,42 +19,25 @@ public override void OnInspectorGUI() serializedObject.UpdateIfRequiredOrScript(); library.OnAfterDeserialize(); - GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (GUILayout.Button("Refresh")) { library.Refresh(); } - bool newAutoRefresh = GUILayout.Toggle(autoRefresh, "Auto"); - if (newAutoRefresh != autoRefresh) - { - autoRefresh = newAutoRefresh; - if (autoRefresh) - { - //TODO ??? - } - } - GUILayout.EndHorizontal(); - GUILayout.Space(25); GUILayout.Label("Contains:", EditorStyles.boldLabel); scrollPosition = GUILayout.BeginScrollView(scrollPosition); - foreach(KeyValuePair entry in library) + foreach(FeatureLibrary.Entry entry in library) { - if (GUILayout.Button(entry.Key)) + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.SelectableLabel($"{entry.FaID}: {entry.Name}", GUILayout.Height(15)); + if (GUILayout.Button($"-->")) { - ProjectWindowUtil.ShowCreatedAsset(entry.Value); + ProjectWindowUtil.ShowCreatedAsset(entry.Feature); } + EditorGUILayout.EndHorizontal(); } GUILayout.EndScrollView(); } - - private class AssetDatabaseListener : UnityEditor.AssetModificationProcessor - { - private static void OnWillCreateAsset(string assetName) - { - - } - } } } \ No newline at end of file diff --git a/Assets/Labrys/FeatureLibrary.cs b/Assets/Labrys/FeatureLibrary.cs index 9ef87d8..4706409 100644 --- a/Assets/Labrys/FeatureLibrary.cs +++ b/Assets/Labrys/FeatureLibrary.cs @@ -10,7 +10,7 @@ namespace Labrys { - public class FeatureLibrary : ScriptableObject, IEnumerable>, ISerializationCallbackReceiver + public class FeatureLibrary : ScriptableObject, IEnumerable, ISerializationCallbackReceiver, ICloneable { [field: SerializeField] public string TargetDirectory { get; private set; } @@ -20,11 +20,6 @@ public class FeatureLibrary : ScriptableObject, IEnumerable features.Length; -#if UNITY_EDITOR - [field: SerializeField] - public bool AutoRefresh { get; set; } //TODO figure out how to hook into asset creation process for auto refresh; or maybe auto refresh on playmode start -#endif - public FeatureAsset this[ushort faid] => Contains(faid) ? features[faid] : null; public FeatureAsset this[string name] @@ -35,7 +30,7 @@ public FeatureAsset this[string name] #if UNITY_EDITOR [MenuItem("Assets/Create/Labrys/Feature Library")] - private static void FromDirectory() + private static void Create() { string saveDir = AssetDatabase.GetAssetPath(Selection.activeInstanceID); if (!File.GetAttributes(saveDir).HasFlag(FileAttributes.Directory)) @@ -52,15 +47,7 @@ private static void FromDirectory() ProjectWindowUtil.CreateAsset(library, savePath); } -#endif - private FeatureLibrary() - { - nameToFAID = new Dictionary(); - features = new FeatureAsset[0]; - } - -#if UNITY_EDITOR public void Refresh() { string[] assetGUIDs = AssetDatabase.FindAssets($"t:{nameof(FeatureAsset)}", new string[] { TargetDirectory }); @@ -107,14 +94,14 @@ public ushort GetId(string name) throw new ArgumentException($"Unknown name: {name}."); } - public IEnumerator> GetEnumerator() + public IEnumerator GetEnumerator() { if (nameToFAID == null) yield break; foreach(KeyValuePair entry in nameToFAID) { - yield return new KeyValuePair(entry.Key, this[entry.Value]); + yield return new Entry(entry.Value, entry.Key, this[entry.Value]); } } @@ -123,6 +110,38 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } + public object Clone() + { + FeatureLibrary clone = CreateInstance(); + + clone.TargetDirectory = TargetDirectory; + + clone.features = new FeatureAsset[features.Length]; + Array.Copy(features, clone.features, features.Length); + + clone.nameToFAID = new Dictionary(); + foreach(KeyValuePair pair in nameToFAID) + { + clone.nameToFAID.Add(pair.Key, pair.Value); + } + + return clone; + } + + public struct Entry + { + public ushort FaID { get; } + public string Name { get; } + public FeatureAsset Feature { get; } + + public Entry(ushort faid, string name, FeatureAsset feature) + { + FaID = faid; + Name = name; + Feature = feature; + } + } + #region SERIALIZATION [SerializeField] private List serializedNames; @@ -147,8 +166,8 @@ public void OnBeforeSerialize() public void OnAfterDeserialize() { - if (serializedNames == null - || serializedFeatures == null + if (serializedNames == null + || serializedFeatures == null || serializedNames.Count != serializedFeatures.Count) return; From 764d9e2e41fa6de0b70d57c20e2a94406f6d3c9d Mon Sep 17 00:00:00 2001 From: Sam Streed Date: Fri, 20 Sep 2019 16:15:56 -0500 Subject: [PATCH 6/7] Fixed FeatureLibrary refresh, hopefully --- Assets/Features/ABrandNewHell.asset | 19 --- Assets/Features/ABrandNewHell.asset.meta | 8 -- Assets/Features/AThirdFeature.asset | 19 --- Assets/Features/AThirdFeature.asset.meta | 8 -- Assets/Features/AnotherFeature.asset | 19 --- Assets/Features/AnotherFeature.asset.meta | 8 -- Assets/Features/Special.meta | 8 -- .../Special/ActuallyPrettySpecial.asset | 19 --- .../Special/ActuallyPrettySpecial.asset.meta | 8 -- .../Features/Special/ButNotThatSpecial.asset | 19 --- .../Special/ButNotThatSpecial.asset.meta | 8 -- .../Special/RidingSomeCoattails.asset | 19 --- .../Special/RidingSomeCoattails.asset.meta | 8 -- Assets/Features/Special/Specialer.meta | 8 -- .../Specialer/OnlyTheBestFeatureEver.asset | 19 --- .../OnlyTheBestFeatureEver.asset.meta | 8 -- Assets/Features/TestFeature.asset | 132 ------------------ Assets/Features/TestFeature.asset.meta | 8 -- Assets/Features/TestLib.asset | 31 ---- Assets/Features/TestLib.asset.meta | 8 -- .../Labrys/Editor/FeatureLibraryInspector.cs | 21 ++- Assets/Labrys/FeatureLibrary.cs | 36 +++-- 22 files changed, 33 insertions(+), 408 deletions(-) delete mode 100644 Assets/Features/ABrandNewHell.asset delete mode 100644 Assets/Features/ABrandNewHell.asset.meta delete mode 100644 Assets/Features/AThirdFeature.asset delete mode 100644 Assets/Features/AThirdFeature.asset.meta delete mode 100644 Assets/Features/AnotherFeature.asset delete mode 100644 Assets/Features/AnotherFeature.asset.meta delete mode 100644 Assets/Features/Special.meta delete mode 100644 Assets/Features/Special/ActuallyPrettySpecial.asset delete mode 100644 Assets/Features/Special/ActuallyPrettySpecial.asset.meta delete mode 100644 Assets/Features/Special/ButNotThatSpecial.asset delete mode 100644 Assets/Features/Special/ButNotThatSpecial.asset.meta delete mode 100644 Assets/Features/Special/RidingSomeCoattails.asset delete mode 100644 Assets/Features/Special/RidingSomeCoattails.asset.meta delete mode 100644 Assets/Features/Special/Specialer.meta delete mode 100644 Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset delete mode 100644 Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset.meta delete mode 100644 Assets/Features/TestFeature.asset delete mode 100644 Assets/Features/TestFeature.asset.meta delete mode 100644 Assets/Features/TestLib.asset delete mode 100644 Assets/Features/TestLib.asset.meta diff --git a/Assets/Features/ABrandNewHell.asset b/Assets/Features/ABrandNewHell.asset deleted file mode 100644 index 23fe9ee..0000000 --- a/Assets/Features/ABrandNewHell.asset +++ /dev/null @@ -1,19 +0,0 @@ -%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: f132721a9c505654498a40770d09b4af, type: 3} - m_Name: ABrandNewHell - m_EditorClassIdentifier: - sectionPositions: [] - sectionData: [] - linkPositions: [] - linkData: [] - selectionPositions: [] diff --git a/Assets/Features/ABrandNewHell.asset.meta b/Assets/Features/ABrandNewHell.asset.meta deleted file mode 100644 index 57a3e4c..0000000 --- a/Assets/Features/ABrandNewHell.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: b681495fc9c35c7489630a9339b5ff25 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Features/AThirdFeature.asset b/Assets/Features/AThirdFeature.asset deleted file mode 100644 index 17c0000..0000000 --- a/Assets/Features/AThirdFeature.asset +++ /dev/null @@ -1,19 +0,0 @@ -%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: f132721a9c505654498a40770d09b4af, type: 3} - m_Name: AThirdFeature - m_EditorClassIdentifier: - sectionPositions: [] - sectionData: [] - linkPositions: [] - linkData: [] - selectionPositions: [] diff --git a/Assets/Features/AThirdFeature.asset.meta b/Assets/Features/AThirdFeature.asset.meta deleted file mode 100644 index 69242f4..0000000 --- a/Assets/Features/AThirdFeature.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 8f89382a948fc644aa755003901f95b4 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Features/AnotherFeature.asset b/Assets/Features/AnotherFeature.asset deleted file mode 100644 index f95f897..0000000 --- a/Assets/Features/AnotherFeature.asset +++ /dev/null @@ -1,19 +0,0 @@ -%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: f132721a9c505654498a40770d09b4af, type: 3} - m_Name: AnotherFeature - m_EditorClassIdentifier: - sectionPositions: [] - sectionData: [] - linkPositions: [] - linkData: [] - selectionPositions: [] diff --git a/Assets/Features/AnotherFeature.asset.meta b/Assets/Features/AnotherFeature.asset.meta deleted file mode 100644 index 06e28dd..0000000 --- a/Assets/Features/AnotherFeature.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: d93a59ab44bab0e4dbfcdde325c92019 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Features/Special.meta b/Assets/Features/Special.meta deleted file mode 100644 index 40d3a9b..0000000 --- a/Assets/Features/Special.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: e8c7f09b4b306944b96e46781987451d -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Features/Special/ActuallyPrettySpecial.asset b/Assets/Features/Special/ActuallyPrettySpecial.asset deleted file mode 100644 index 5f5d2b9..0000000 --- a/Assets/Features/Special/ActuallyPrettySpecial.asset +++ /dev/null @@ -1,19 +0,0 @@ -%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: f132721a9c505654498a40770d09b4af, type: 3} - m_Name: ActuallyPrettySpecial - m_EditorClassIdentifier: - sectionPositions: [] - sectionData: [] - linkPositions: [] - linkData: [] - selectionPositions: [] diff --git a/Assets/Features/Special/ActuallyPrettySpecial.asset.meta b/Assets/Features/Special/ActuallyPrettySpecial.asset.meta deleted file mode 100644 index f08d93b..0000000 --- a/Assets/Features/Special/ActuallyPrettySpecial.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 6a523fcf115a9c04a92515fdc06e638f -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Features/Special/ButNotThatSpecial.asset b/Assets/Features/Special/ButNotThatSpecial.asset deleted file mode 100644 index 8e6759c..0000000 --- a/Assets/Features/Special/ButNotThatSpecial.asset +++ /dev/null @@ -1,19 +0,0 @@ -%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: f132721a9c505654498a40770d09b4af, type: 3} - m_Name: ButNotThatSpecial - m_EditorClassIdentifier: - sectionPositions: [] - sectionData: [] - linkPositions: [] - linkData: [] - selectionPositions: [] diff --git a/Assets/Features/Special/ButNotThatSpecial.asset.meta b/Assets/Features/Special/ButNotThatSpecial.asset.meta deleted file mode 100644 index 29968f2..0000000 --- a/Assets/Features/Special/ButNotThatSpecial.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 655f469db20febe4cbf90188ae201aaf -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Features/Special/RidingSomeCoattails.asset b/Assets/Features/Special/RidingSomeCoattails.asset deleted file mode 100644 index 9fa9687..0000000 --- a/Assets/Features/Special/RidingSomeCoattails.asset +++ /dev/null @@ -1,19 +0,0 @@ -%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: f132721a9c505654498a40770d09b4af, type: 3} - m_Name: RidingSomeCoattails - m_EditorClassIdentifier: - sectionPositions: [] - sectionData: [] - linkPositions: [] - linkData: [] - selectionPositions: [] diff --git a/Assets/Features/Special/RidingSomeCoattails.asset.meta b/Assets/Features/Special/RidingSomeCoattails.asset.meta deleted file mode 100644 index b929750..0000000 --- a/Assets/Features/Special/RidingSomeCoattails.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 31969de8ead96d64b9c73162313380ca -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Features/Special/Specialer.meta b/Assets/Features/Special/Specialer.meta deleted file mode 100644 index e83475f..0000000 --- a/Assets/Features/Special/Specialer.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 14850bcb5f265c141a04d4206f8b74f1 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset b/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset deleted file mode 100644 index ddfc313..0000000 --- a/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset +++ /dev/null @@ -1,19 +0,0 @@ -%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: f132721a9c505654498a40770d09b4af, type: 3} - m_Name: OnlyTheBestFeatureEver - m_EditorClassIdentifier: - sectionPositions: [] - sectionData: [] - linkPositions: [] - linkData: [] - selectionPositions: [] diff --git a/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset.meta b/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset.meta deleted file mode 100644 index 919cca4..0000000 --- a/Assets/Features/Special/Specialer/OnlyTheBestFeatureEver.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f8f77afd442ed674884132731ce9f8e8 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Features/TestFeature.asset b/Assets/Features/TestFeature.asset deleted file mode 100644 index 8e5a132..0000000 --- a/Assets/Features/TestFeature.asset +++ /dev/null @@ -1,132 +0,0 @@ -%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: f132721a9c505654498a40770d09b4af, type: 3} - m_Name: TestFeature - m_EditorClassIdentifier: - sectionPositions: - - {x: -2, y: -2} - - {x: -2, y: 0} - - {x: -2, y: 2} - - {x: 0, y: 2} - - {x: 2, y: 2} - - {x: 2, y: 0} - - {x: 2, y: -2} - - {x: 0, y: -2} - sectionData: - - variant: Regular - fields: - - k__BackingField: hasChest - k__BackingField: false - - variant: Regular - fields: - - k__BackingField: hasChest - k__BackingField: false - - variant: Regular - fields: - - k__BackingField: hasChest - k__BackingField: false - - variant: Regular - fields: - - k__BackingField: hasChest - k__BackingField: false - - variant: Regular - fields: - - k__BackingField: hasChest - k__BackingField: false - - variant: Regular - fields: - - k__BackingField: hasChest - k__BackingField: false - - variant: ChestRoom - fields: - - k__BackingField: hasChest - k__BackingField: true - - variant: Regular - fields: - - k__BackingField: hasChest - k__BackingField: false - linkPositions: - - {x: -1, y: -2} - - {x: -2, y: -1} - - {x: -3, y: -2} - - {x: -2, y: -3} - - {x: -1, y: 0} - - {x: -2, y: 1} - - {x: -3, y: 0} - - {x: -1, y: 2} - - {x: -2, y: 3} - - {x: -3, y: 2} - - {x: 1, y: 2} - - {x: 0, y: 3} - - {x: 0, y: 1} - - {x: 3, y: 2} - - {x: 2, y: 3} - - {x: 2, y: 1} - - {x: 3, y: 0} - - {x: 1, y: 0} - - {x: 2, y: -1} - - {x: 3, y: -2} - - {x: 1, y: -2} - - {x: 2, y: -3} - - {x: 0, y: -1} - - {x: 0, y: -3} - linkData: - - open: 1 - external: 0 - - open: 1 - external: 0 - - open: 1 - external: 1 - - open: 1 - external: 1 - - open: 1 - external: 1 - - open: 1 - external: 0 - - open: 1 - external: 1 - - open: 1 - external: 0 - - open: 1 - external: 1 - - open: 1 - external: 1 - - open: 1 - external: 0 - - open: 1 - external: 1 - - open: 1 - external: 1 - - open: 1 - external: 1 - - open: 1 - external: 1 - - open: 1 - external: 0 - - open: 1 - external: 1 - - open: 1 - external: 1 - - open: 1 - external: 0 - - open: 1 - external: 1 - - open: 1 - external: 0 - - open: 1 - external: 1 - - open: 1 - external: 1 - - open: 1 - external: 1 - selectionPositions: - - {x: 2, y: -2} diff --git a/Assets/Features/TestFeature.asset.meta b/Assets/Features/TestFeature.asset.meta deleted file mode 100644 index 46a13d3..0000000 --- a/Assets/Features/TestFeature.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 3c9906764ccf06948a8aab32a03352b4 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Features/TestLib.asset b/Assets/Features/TestLib.asset deleted file mode 100644 index f1e4196..0000000 --- a/Assets/Features/TestLib.asset +++ /dev/null @@ -1,31 +0,0 @@ -%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: 56cac0c8c64b38c47bc5fc13147ebc83, type: 3} - m_Name: TestLib - m_EditorClassIdentifier: - k__BackingField: Assets/Features - serializedNames: - - AnotherFeature - - AThirdFeature - - Special/ActuallyPrettySpecial - - Special/ButNotThatSpecial - - Special/RidingSomeCoattails - - Special/Specialer/OnlyTheBestFeatureEver - - TestFeature - serializedFeatures: - - {fileID: 11400000, guid: d93a59ab44bab0e4dbfcdde325c92019, type: 2} - - {fileID: 11400000, guid: 8f89382a948fc644aa755003901f95b4, type: 2} - - {fileID: 11400000, guid: 6a523fcf115a9c04a92515fdc06e638f, type: 2} - - {fileID: 11400000, guid: 655f469db20febe4cbf90188ae201aaf, type: 2} - - {fileID: 11400000, guid: 31969de8ead96d64b9c73162313380ca, type: 2} - - {fileID: 11400000, guid: f8f77afd442ed674884132731ce9f8e8, type: 2} - - {fileID: 11400000, guid: 3c9906764ccf06948a8aab32a03352b4, type: 2} diff --git a/Assets/Features/TestLib.asset.meta b/Assets/Features/TestLib.asset.meta deleted file mode 100644 index 0b5d3d3..0000000 --- a/Assets/Features/TestLib.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 9ee43cb5049591848aa7430d58266fba -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Labrys/Editor/FeatureLibraryInspector.cs b/Assets/Labrys/Editor/FeatureLibraryInspector.cs index ffec4e1..2b3fe62 100644 --- a/Assets/Labrys/Editor/FeatureLibraryInspector.cs +++ b/Assets/Labrys/Editor/FeatureLibraryInspector.cs @@ -6,38 +6,35 @@ namespace Labrys.Editor [CustomEditor(typeof(FeatureLibrary))] public class FeatureLibraryInspector : UnityEditor.Editor { - private FeatureLibrary library; - private Vector2 scrollPosition; - - private void OnEnable() - { - library = (FeatureLibrary)target; - } - public override void OnInspectorGUI() { serializedObject.UpdateIfRequiredOrScript(); + FeatureLibrary library = (FeatureLibrary)serializedObject.targetObject; library.OnAfterDeserialize(); + EditorGUILayout.SelectableLabel(library.TargetDirectory); + if (GUILayout.Button("Refresh")) { + Undo.RegisterCompleteObjectUndo(library, "Feature Library Refresh"); library.Refresh(); + EditorUtility.SetDirty(library); + Debug.Log($"[Labrys:FL] Refreshed {library.name}: \n{library.ToString()}"); } GUILayout.Space(25); GUILayout.Label("Contains:", EditorStyles.boldLabel); - scrollPosition = GUILayout.BeginScrollView(scrollPosition); foreach(FeatureLibrary.Entry entry in library) { EditorGUILayout.BeginHorizontal(); - EditorGUILayout.SelectableLabel($"{entry.FaID}: {entry.Name}", GUILayout.Height(15)); - if (GUILayout.Button($"-->")) + Debug.Log($"{entry.FaID}: {entry.Name}"); + EditorGUILayout.SelectableLabel($"{entry.FaID}: {entry.Name}", GUILayout.Height(20)); + if (GUILayout.Button("-->")) { ProjectWindowUtil.ShowCreatedAsset(entry.Feature); } EditorGUILayout.EndHorizontal(); } - GUILayout.EndScrollView(); } } } \ No newline at end of file diff --git a/Assets/Labrys/FeatureLibrary.cs b/Assets/Labrys/FeatureLibrary.cs index 4706409..52a6d42 100644 --- a/Assets/Labrys/FeatureLibrary.cs +++ b/Assets/Labrys/FeatureLibrary.cs @@ -39,8 +39,6 @@ private static void Create() string loadPath = $"Assets{EditorUtility.OpenFolderPanel("Select target Feature folder", saveDir, "").Replace(Application.dataPath, "")}"; string savePath = $"{saveDir}/NewFeatureLibrary.asset"; - string[] assetGUIDs = AssetDatabase.FindAssets($"t:{nameof(FeatureAsset)}", new string[] { loadPath }); - FeatureLibrary library = CreateInstance(); library.TargetDirectory = loadPath; library.Refresh(); @@ -51,20 +49,22 @@ private static void Create() public void Refresh() { string[] assetGUIDs = AssetDatabase.FindAssets($"t:{nameof(FeatureAsset)}", new string[] { TargetDirectory }); - if (features != null && assetGUIDs.Length != features.Length) + nameToFAID = new Dictionary(); + features = new FeatureAsset[assetGUIDs.Length]; + + foreach (string guid in assetGUIDs) { - nameToFAID = new Dictionary(); - features = new FeatureAsset[assetGUIDs.Length]; - - foreach (string guid in assetGUIDs) - { - string path = AssetDatabase.GUIDToAssetPath(guid); - Add(path.Replace(TargetDirectory, "").Replace(".asset", "").TrimStart('/'), - AssetDatabase.LoadAssetAtPath(path)); - } + string path = AssetDatabase.GUIDToAssetPath(guid); + Add(path.Replace(TargetDirectory, "").Replace(".asset", "").TrimStart('/'), + AssetDatabase.LoadAssetAtPath(path)); } } #endif + private FeatureLibrary() + { + nameToFAID = new Dictionary(); + features = new FeatureAsset[0]; + } private bool Add(string name, FeatureAsset feature) { @@ -128,6 +128,18 @@ public object Clone() return clone; } + public override string ToString() + { + string str = ""; + + foreach(Entry e in this) + { + str += $"{{faid: {e.FaID}, name: {e.Name}, feature: {e.Feature.ToString()}}}\n"; + } + + return $"TargetDirectory: {TargetDirectory}, Contents: [\n{str}\n]"; + } + public struct Entry { public ushort FaID { get; } From cfa2dbf0676a7edc9f36c4a8f023098c0ea5e899 Mon Sep 17 00:00:00 2001 From: Sam Streed Date: Fri, 20 Sep 2019 19:24:25 -0500 Subject: [PATCH 7/7] Fixed w/o the hack --- Assets/Features.meta | 8 ----- .../Labrys/Editor/FeatureLibraryInspector.cs | 31 +++++++++++++------ Assets/Labrys/FeatureLibrary.cs | 2 -- Assets/Test.asset | 14 --------- Assets/Test.asset.meta | 8 ----- 5 files changed, 21 insertions(+), 42 deletions(-) delete mode 100644 Assets/Features.meta delete mode 100644 Assets/Test.asset delete mode 100644 Assets/Test.asset.meta diff --git a/Assets/Features.meta b/Assets/Features.meta deleted file mode 100644 index 2c6d03c..0000000 --- a/Assets/Features.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 86fa19d9723e7f54880785c8f542ea52 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Labrys/Editor/FeatureLibraryInspector.cs b/Assets/Labrys/Editor/FeatureLibraryInspector.cs index 2b3fe62..32135e3 100644 --- a/Assets/Labrys/Editor/FeatureLibraryInspector.cs +++ b/Assets/Labrys/Editor/FeatureLibraryInspector.cs @@ -1,16 +1,23 @@ using UnityEngine; using UnityEditor; +using UnityEditor.AnimatedValues; namespace Labrys.Editor { [CustomEditor(typeof(FeatureLibrary))] public class FeatureLibraryInspector : UnityEditor.Editor { + private AnimBool fadeGroupVal = new AnimBool(false); + + public void OnEnable() + { + fadeGroupVal.valueChanged.AddListener(Repaint); + } + public override void OnInspectorGUI() { serializedObject.UpdateIfRequiredOrScript(); FeatureLibrary library = (FeatureLibrary)serializedObject.targetObject; - library.OnAfterDeserialize(); EditorGUILayout.SelectableLabel(library.TargetDirectory); @@ -19,22 +26,26 @@ public override void OnInspectorGUI() Undo.RegisterCompleteObjectUndo(library, "Feature Library Refresh"); library.Refresh(); EditorUtility.SetDirty(library); - Debug.Log($"[Labrys:FL] Refreshed {library.name}: \n{library.ToString()}"); } GUILayout.Space(25); - GUILayout.Label("Contains:", EditorStyles.boldLabel); - foreach(FeatureLibrary.Entry entry in library) + if (GUILayout.Button(fadeGroupVal.value ? "Hide contents" : "Show contents")) + fadeGroupVal.target = !fadeGroupVal.value; + if (EditorGUILayout.BeginFadeGroup(fadeGroupVal.faded)) { - EditorGUILayout.BeginHorizontal(); - Debug.Log($"{entry.FaID}: {entry.Name}"); - EditorGUILayout.SelectableLabel($"{entry.FaID}: {entry.Name}", GUILayout.Height(20)); - if (GUILayout.Button("-->")) + foreach (FeatureLibrary.Entry entry in library) { - ProjectWindowUtil.ShowCreatedAsset(entry.Feature); + EditorGUILayout.BeginHorizontal(); + Debug.Log($"{entry.FaID}: {entry.Name}"); + EditorGUILayout.SelectableLabel($"{entry.FaID}: {entry.Name}", GUILayout.Height(20)); + if (GUILayout.Button("-->")) + { + ProjectWindowUtil.ShowCreatedAsset(entry.Feature); + } + EditorGUILayout.EndHorizontal(); } - EditorGUILayout.EndHorizontal(); } + EditorGUILayout.EndFadeGroup(); } } } \ No newline at end of file diff --git a/Assets/Labrys/FeatureLibrary.cs b/Assets/Labrys/FeatureLibrary.cs index 52a6d42..bf0b0f4 100644 --- a/Assets/Labrys/FeatureLibrary.cs +++ b/Assets/Labrys/FeatureLibrary.cs @@ -172,8 +172,6 @@ public void OnBeforeSerialize() serializedNames.Add(pair.Key); serializedFeatures.Add(features[pair.Value]); } - nameToFAID = null; - features = null; } public void OnAfterDeserialize() diff --git a/Assets/Test.asset b/Assets/Test.asset deleted file mode 100644 index 3eff857..0000000 --- a/Assets/Test.asset +++ /dev/null @@ -1,14 +0,0 @@ -%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: 2304350bd412e4faba5b8135efded78c, type: 3} - m_Name: Test - m_EditorClassIdentifier: diff --git a/Assets/Test.asset.meta b/Assets/Test.asset.meta deleted file mode 100644 index 51d7d23..0000000 --- a/Assets/Test.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 48d69f246df4a4ed2845ad8e6cff9387 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: