From fe7cd1f456b180020a553fc489b26efa105f7dd7 Mon Sep 17 00:00:00 2001 From: Vorobey Date: Wed, 22 Nov 2023 21:01:09 +0300 Subject: [PATCH 1/4] Setup project --- Packages/UGF.Assets/package.json.meta | 7 +++++++ Packages/packages-lock.json | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 Packages/UGF.Assets/package.json.meta diff --git a/Packages/UGF.Assets/package.json.meta b/Packages/UGF.Assets/package.json.meta new file mode 100644 index 0000000..b8d7269 --- /dev/null +++ b/Packages/UGF.Assets/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 49e299ff97a3f6b429e9402d3b28da6f +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index a1be05b..b5c4b16 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,7 +1,7 @@ { "dependencies": { - "com.ugf.package.name": { - "version": "file:Package", + "com.ugf.assets": { + "version": "file:UGF.Assets", "depth": 0, "source": "embedded", "dependencies": {} From 6d8bc6f79030c939a2939e591964ee5931c8b242 Mon Sep 17 00:00:00 2001 From: Vorobey Date: Wed, 22 Nov 2023 21:22:05 +0300 Subject: [PATCH 2/4] Change dependencies --- Packages/UGF.Assets/package.json | 5 ++++- Packages/packages-lock.json | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Packages/UGF.Assets/package.json b/Packages/UGF.Assets/package.json index a2fcdaf..1b9b6b3 100644 --- a/Packages/UGF.Assets/package.json +++ b/Packages/UGF.Assets/package.json @@ -18,5 +18,8 @@ "publishConfig": { "registry": "https://api.upmhub.org/registries/unity-game-framework" }, - "dependencies": {} + "dependencies": { + "com.ugf.customsettings": "3.4.1", + "com.ugf.editortools": "3.0.0-preview" + } } \ No newline at end of file diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index b5c4b16..c5e7644 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -4,7 +4,27 @@ "version": "file:UGF.Assets", "depth": 0, "source": "embedded", - "dependencies": {} + "dependencies": { + "com.ugf.customsettings": "3.4.1", + "com.ugf.editortools": "3.0.0-preview" + } + }, + "com.ugf.customsettings": { + "version": "3.4.1", + "depth": 1, + "source": "registry", + "dependencies": { + "com.ugf.editortools": "1.7.0", + "com.unity.modules.jsonserialize": "1.0.0" + }, + "url": "https://api.upmhub.org/registries/unity-game-framework" + }, + "com.ugf.editortools": { + "version": "3.0.0-preview", + "depth": 1, + "source": "registry", + "dependencies": {}, + "url": "https://api.upmhub.org/registries/unity-game-framework" }, "com.unity.ext.nunit": { "version": "2.0.5", From ddd44faedbe39608e253e95f955f9e1700ac5ffb Mon Sep 17 00:00:00 2001 From: Vorobey Date: Wed, 22 Nov 2023 21:22:21 +0300 Subject: [PATCH 3/4] Add AssetFolderAsset --- Packages/UGF.Assets/Editor.meta | 8 ++ .../UGF.Assets/Editor/AssetEditorSettings.cs | 27 +++++ .../Editor/AssetEditorSettings.cs.meta | 2 + .../Editor/AssetEditorSettingsData.cs | 17 +++ .../Editor/AssetEditorSettingsData.cs.meta | 2 + .../Editor/AssetEditorSettingsDataEditor.cs | 97 ++++++++++++++++ .../AssetEditorSettingsDataEditor.cs.meta | 2 + .../UGF.Assets/Editor/AssetFolderAsset.cs | 69 +++++++++++ .../Editor/AssetFolderAsset.cs.meta | 2 + .../AssetFolderAssetBuildPreprocessor.cs | 21 ++++ .../AssetFolderAssetBuildPreprocessor.cs.meta | 2 + .../Editor/AssetFolderAssetEditor.cs | 47 ++++++++ .../Editor/AssetFolderAssetEditor.cs.meta | 3 + .../Editor/AssetFolderAssetPostprocessor.cs | 58 ++++++++++ .../AssetFolderAssetPostprocessor.cs.meta | 2 + .../UGF.Assets/Editor/AssetFolderAsset`1.cs | 13 +++ .../Editor/AssetFolderAsset`1.cs.meta | 2 + .../UGF.Assets/Editor/AssetFolderAsset`2.cs | 18 +++ .../Editor/AssetFolderAsset`2.cs.meta | 3 + .../Editor/AssetFolderEditorGUIUtility.cs | 41 +++++++ .../AssetFolderEditorGUIUtility.cs.meta | 2 + .../Editor/AssetFolderEditorUtility.cs | 107 ++++++++++++++++++ .../Editor/AssetFolderEditorUtility.cs.meta | 2 + .../Editor/UGF.Assets.Editor.asmdef | 21 ++++ .../Editor/UGF.Assets.Editor.asmdef.meta | 7 ++ UGF.Assets.Editor.csproj.DotSettings | 2 + 26 files changed, 577 insertions(+) create mode 100644 Packages/UGF.Assets/Editor.meta create mode 100644 Packages/UGF.Assets/Editor/AssetEditorSettings.cs create mode 100644 Packages/UGF.Assets/Editor/AssetEditorSettings.cs.meta create mode 100644 Packages/UGF.Assets/Editor/AssetEditorSettingsData.cs create mode 100644 Packages/UGF.Assets/Editor/AssetEditorSettingsData.cs.meta create mode 100644 Packages/UGF.Assets/Editor/AssetEditorSettingsDataEditor.cs create mode 100644 Packages/UGF.Assets/Editor/AssetEditorSettingsDataEditor.cs.meta create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAsset.cs create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAsset.cs.meta create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAssetBuildPreprocessor.cs create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAssetBuildPreprocessor.cs.meta create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAssetEditor.cs create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAssetEditor.cs.meta create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAssetPostprocessor.cs create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAssetPostprocessor.cs.meta create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAsset`1.cs create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAsset`1.cs.meta create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAsset`2.cs create mode 100644 Packages/UGF.Assets/Editor/AssetFolderAsset`2.cs.meta create mode 100644 Packages/UGF.Assets/Editor/AssetFolderEditorGUIUtility.cs create mode 100644 Packages/UGF.Assets/Editor/AssetFolderEditorGUIUtility.cs.meta create mode 100644 Packages/UGF.Assets/Editor/AssetFolderEditorUtility.cs create mode 100644 Packages/UGF.Assets/Editor/AssetFolderEditorUtility.cs.meta create mode 100644 Packages/UGF.Assets/Editor/UGF.Assets.Editor.asmdef create mode 100644 Packages/UGF.Assets/Editor/UGF.Assets.Editor.asmdef.meta create mode 100644 UGF.Assets.Editor.csproj.DotSettings diff --git a/Packages/UGF.Assets/Editor.meta b/Packages/UGF.Assets/Editor.meta new file mode 100644 index 0000000..1ee5b5f --- /dev/null +++ b/Packages/UGF.Assets/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1e3d52ea91737bd4990c4e5177270b6f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/UGF.Assets/Editor/AssetEditorSettings.cs b/Packages/UGF.Assets/Editor/AssetEditorSettings.cs new file mode 100644 index 0000000..b628995 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetEditorSettings.cs @@ -0,0 +1,27 @@ +using UGF.CustomSettings.Editor; +using UnityEditor; + +namespace UGF.Assets.Editor +{ + public static class AssetEditorSettings + { + public static CustomSettingsEditorPackage Settings { get; } = new CustomSettingsEditorPackage + ( + "UGF.Assets", + nameof(AssetEditorSettings) + ); + + public static bool UpdateFoldersAll() + { + AssetEditorSettingsData data = Settings.GetData(); + + return AssetFolderEditorUtility.TryUpdate(data.Folders); + } + + [SettingsProvider] + private static SettingsProvider GetProvider() + { + return new CustomSettingsProvider("Project/Unity Game Framework/Assets", Settings, SettingsScope.Project); + } + } +} diff --git a/Packages/UGF.Assets/Editor/AssetEditorSettings.cs.meta b/Packages/UGF.Assets/Editor/AssetEditorSettings.cs.meta new file mode 100644 index 0000000..f5f4b04 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetEditorSettings.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 4432345da81b74045a52484c01baa7f0 \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/AssetEditorSettingsData.cs b/Packages/UGF.Assets/Editor/AssetEditorSettingsData.cs new file mode 100644 index 0000000..8faa492 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetEditorSettingsData.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using UGF.CustomSettings.Runtime; +using UnityEngine; + +namespace UGF.Assets.Editor +{ + public class AssetEditorSettingsData : CustomSettingsData + { + [SerializeField] private bool m_foldersUpdateOnPostprocess = true; + [SerializeField] private bool m_foldersUpdateOnBuild = true; + [SerializeField] private List m_folders = new List(); + + public bool FoldersUpdateOnPostprocess { get { return m_foldersUpdateOnPostprocess; } set { m_foldersUpdateOnPostprocess = value; } } + public bool FoldersUpdateOnBuild { get { return m_foldersUpdateOnBuild; } set { m_foldersUpdateOnBuild = value; } } + public List Folders { get { return m_folders; } } + } +} diff --git a/Packages/UGF.Assets/Editor/AssetEditorSettingsData.cs.meta b/Packages/UGF.Assets/Editor/AssetEditorSettingsData.cs.meta new file mode 100644 index 0000000..4a69fe4 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetEditorSettingsData.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: d94c12c52baab4c498c95d314cea614c \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/AssetEditorSettingsDataEditor.cs b/Packages/UGF.Assets/Editor/AssetEditorSettingsDataEditor.cs new file mode 100644 index 0000000..46fcd16 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetEditorSettingsDataEditor.cs @@ -0,0 +1,97 @@ +using UGF.EditorTools.Editor.IMGUI; +using UGF.EditorTools.Editor.IMGUI.Scopes; +using UnityEditor; +using UnityEngine; + +namespace UGF.Assets.Editor +{ + [CustomEditor(typeof(AssetEditorSettingsData), true)] + internal class AssetEditorSettingsDataEditor : UnityEditor.Editor + { + private SerializedProperty m_propertyFoldersUpdateOnPostprocess; + private SerializedProperty m_propertyFoldersUpdateOnBuild; + private ReorderableListDrawer m_listFolders; + private ReorderableListSelectionDrawerByElement m_listFoldersSelection; + + private void OnEnable() + { + m_propertyFoldersUpdateOnPostprocess = serializedObject.FindProperty("m_foldersUpdateOnPostprocess"); + m_propertyFoldersUpdateOnBuild = serializedObject.FindProperty("m_foldersUpdateOnBuild"); + + m_listFolders = new ReorderableListDrawer(serializedObject.FindProperty("m_folders")); + + m_listFoldersSelection = new ReorderableListSelectionDrawerByElement(m_listFolders) + { + Drawer = { DisplayTitlebar = true } + }; + + m_listFolders.Enable(); + m_listFoldersSelection.Enable(); + } + + private void OnDisable() + { + m_listFolders.Disable(); + m_listFoldersSelection.Disable(); + } + + public override void OnInspectorGUI() + { + using (new SerializedObjectUpdateScope(serializedObject)) + { + EditorGUILayout.PropertyField(m_propertyFoldersUpdateOnPostprocess); + EditorGUILayout.PropertyField(m_propertyFoldersUpdateOnBuild); + + m_listFolders.DrawGUILayout(); + } + + using (new EditorGUILayout.HorizontalScope()) + { + GUILayout.FlexibleSpace(); + + using (new EditorGUI.DisabledScope(m_listFolders.List.selectedIndices.Count == 0)) + { + if (GUILayout.Button("Update")) + { + OnUpdate(); + } + } + + using (new EditorGUI.DisabledScope(m_listFolders.SerializedProperty.arraySize == 0)) + { + if (GUILayout.Button("Update All")) + { + OnUpdateAll(); + } + } + + EditorGUILayout.Space(); + } + + EditorGUILayout.Space(); + + m_listFoldersSelection.DrawGUILayout(); + } + + private void OnUpdate() + { + foreach (int index in m_listFolders.List.selectedIndices) + { + SerializedProperty propertyElement = m_listFolders.SerializedProperty.GetArrayElementAtIndex(index); + + if (propertyElement.objectReferenceValue is AssetFolderAsset assetFolder && !AssetFolderEditorUtility.TryUpdate(assetFolder)) + { + Debug.LogWarning($"Asset folder is invalid: '{assetFolder}'.", assetFolder); + } + } + } + + private void OnUpdateAll() + { + if (!AssetEditorSettings.UpdateFoldersAll()) + { + Debug.LogWarning("Asset folder collection has an invalid entry."); + } + } + } +} diff --git a/Packages/UGF.Assets/Editor/AssetEditorSettingsDataEditor.cs.meta b/Packages/UGF.Assets/Editor/AssetEditorSettingsDataEditor.cs.meta new file mode 100644 index 0000000..45b0393 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetEditorSettingsDataEditor.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 74496aa361e80ea4c90b7fa462bcae57 \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/AssetFolderAsset.cs b/Packages/UGF.Assets/Editor/AssetFolderAsset.cs new file mode 100644 index 0000000..a0ada48 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAsset.cs @@ -0,0 +1,69 @@ +using System; +using UGF.EditorTools.Runtime.IMGUI.Attributes; +using UnityEditor; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace UGF.Assets.Editor +{ + public abstract class AssetFolderAsset : ScriptableObject + { + [ObjectPicker("t:folder")] + [SerializeField] private Object m_folder; + + public Object Folder { get { return m_folder; } set { m_folder = value; } } + + public bool IsValid() + { + if (m_folder != null) + { + string path = AssetDatabase.GetAssetPath(m_folder); + + return AssetDatabase.IsValidFolder(path) && OnIsValid(); + } + + return false; + } + + public Type GetAssetType() + { + if (!IsValid()) throw new InvalidOperationException("Asset folder is invalid."); + + return OnGetAssetType(); + } + + public void Update() + { + if (!IsValid()) throw new InvalidOperationException("Asset folder is invalid."); + + OnUpdate(); + } + + public string GetFolderPath() + { + if (!IsValid()) throw new InvalidOperationException("Asset folder is invalid."); + + return AssetDatabase.GetAssetPath(m_folder); + } + + public string[] FindAssetsAsGuids() + { + string path = GetFolderPath(); + Type type = GetAssetType(); + + return AssetFolderEditorUtility.FindAssetsAsGuids(path, type); + } + + protected virtual bool OnIsValid() + { + return true; + } + + protected virtual Type OnGetAssetType() + { + return typeof(Object); + } + + protected abstract void OnUpdate(); + } +} diff --git a/Packages/UGF.Assets/Editor/AssetFolderAsset.cs.meta b/Packages/UGF.Assets/Editor/AssetFolderAsset.cs.meta new file mode 100644 index 0000000..2d1252a --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAsset.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 38d2b752ebef9224b8474165cc13ff7e \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/AssetFolderAssetBuildPreprocessor.cs b/Packages/UGF.Assets/Editor/AssetFolderAssetBuildPreprocessor.cs new file mode 100644 index 0000000..6397f9f --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAssetBuildPreprocessor.cs @@ -0,0 +1,21 @@ +using UGF.CustomSettings.Editor; +using UnityEditor.Build; +using UnityEditor.Build.Reporting; + +namespace UGF.Assets.Editor +{ + internal class AssetFolderAssetBuildPreprocessor : IPreprocessBuildWithReport + { + public int callbackOrder { get; } + + public void OnPreprocessBuild(BuildReport report) + { + CustomSettingsEditorPackage settings = AssetEditorSettings.Settings; + + if (settings.Exists() && settings.GetData().FoldersUpdateOnBuild) + { + AssetEditorSettings.UpdateFoldersAll(); + } + } + } +} diff --git a/Packages/UGF.Assets/Editor/AssetFolderAssetBuildPreprocessor.cs.meta b/Packages/UGF.Assets/Editor/AssetFolderAssetBuildPreprocessor.cs.meta new file mode 100644 index 0000000..962f177 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAssetBuildPreprocessor.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 7e39ed6f880ed854f9a4edc1b07867ad \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/AssetFolderAssetEditor.cs b/Packages/UGF.Assets/Editor/AssetFolderAssetEditor.cs new file mode 100644 index 0000000..9b3d5f3 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAssetEditor.cs @@ -0,0 +1,47 @@ +using UGF.EditorTools.Editor.IMGUI; +using UGF.EditorTools.Editor.IMGUI.Scopes; +using UnityEditor; + +namespace UGF.Assets.Editor +{ + [CustomEditor(typeof(AssetFolderAsset<,>), true)] + internal class AssetFolderAssetEditor : UnityEditor.Editor + { + private SerializedProperty m_propertyFolder; + private SerializedProperty m_propertyCollection; + private EditorObjectReferenceDrawer m_drawerCollection; + + private void OnEnable() + { + m_propertyFolder = serializedObject.FindProperty("m_folder"); + m_propertyCollection = serializedObject.FindProperty("m_collection"); + + m_drawerCollection = new EditorObjectReferenceDrawer(m_propertyCollection) + { + Drawer = { DisplayTitlebar = true } + }; + + m_drawerCollection.Enable(); + } + + private void OnDisable() + { + m_drawerCollection.Disable(); + } + + public override void OnInspectorGUI() + { + using (new SerializedObjectUpdateScope(serializedObject)) + { + EditorIMGUIUtility.DrawScriptProperty(serializedObject); + + EditorGUILayout.PropertyField(m_propertyFolder); + EditorGUILayout.PropertyField(m_propertyCollection); + } + + AssetFolderEditorGUIUtility.DrawControlsGUILayout(serializedObject); + + m_drawerCollection.DrawGUILayout(); + } + } +} diff --git a/Packages/UGF.Assets/Editor/AssetFolderAssetEditor.cs.meta b/Packages/UGF.Assets/Editor/AssetFolderAssetEditor.cs.meta new file mode 100644 index 0000000..823c7aa --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAssetEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: de72233ee75047da863c631cf567adea +timeCreated: 1700676887 \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/AssetFolderAssetPostprocessor.cs b/Packages/UGF.Assets/Editor/AssetFolderAssetPostprocessor.cs new file mode 100644 index 0000000..f8ef533 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAssetPostprocessor.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using UGF.CustomSettings.Editor; +using UnityEditor; +using UnityEngine; + +namespace UGF.Assets.Editor +{ + internal class AssetFolderAssetPostprocessor : AssetPostprocessor + { + private static readonly HashSet m_paths = new HashSet(); + + private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) + { + CustomSettingsEditorPackage settings = AssetEditorSettings.Settings; + + if (settings.Exists()) + { + AssetFolderEditorUtility.TryGetAssetFolderPaths(m_paths, importedAssets); + AssetFolderEditorUtility.TryGetAssetFolderPaths(m_paths, deletedAssets); + AssetFolderEditorUtility.TryGetAssetFolderPaths(m_paths, movedAssets); + AssetFolderEditorUtility.TryGetAssetFolderPaths(m_paths, movedFromAssetPaths); + + if (m_paths.Count > 0) + { + List assetFolders = settings.GetData().Folders; + + try + { + for (int i = 0; i < assetFolders.Count; i++) + { + AssetFolderAsset assetFolder = assetFolders[i]; + + if (assetFolder.IsValid()) + { + string assetFolderPath = AssetDatabase.GetAssetPath(assetFolder.Folder); + + if (m_paths.Contains(assetFolderPath)) + { + assetFolder.Update(); + } + } + else + { + Debug.LogWarning($"Asset folder is invalid: '{assetFolder}'.", assetFolder); + } + } + } + finally + { + m_paths.Clear(); + } + + AssetDatabase.SaveAssets(); + } + } + } + } +} diff --git a/Packages/UGF.Assets/Editor/AssetFolderAssetPostprocessor.cs.meta b/Packages/UGF.Assets/Editor/AssetFolderAssetPostprocessor.cs.meta new file mode 100644 index 0000000..b865cdd --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAssetPostprocessor.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e79081153c72a204c906c285e4f78aa0 \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/AssetFolderAsset`1.cs b/Packages/UGF.Assets/Editor/AssetFolderAsset`1.cs new file mode 100644 index 0000000..9f513d9 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAsset`1.cs @@ -0,0 +1,13 @@ +using System; +using Object = UnityEngine.Object; + +namespace UGF.Assets.Editor +{ + public abstract class AssetFolderAsset : AssetFolderAsset where TAsset : Object + { + protected override Type OnGetAssetType() + { + return typeof(TAsset); + } + } +} diff --git a/Packages/UGF.Assets/Editor/AssetFolderAsset`1.cs.meta b/Packages/UGF.Assets/Editor/AssetFolderAsset`1.cs.meta new file mode 100644 index 0000000..74ec76d --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAsset`1.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 87e9687b3ac26894c95b601a20826c94 \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/AssetFolderAsset`2.cs b/Packages/UGF.Assets/Editor/AssetFolderAsset`2.cs new file mode 100644 index 0000000..e7c99f7 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAsset`2.cs @@ -0,0 +1,18 @@ +using UnityEngine; + +namespace UGF.Assets.Editor +{ + public abstract class AssetFolderAsset : AssetFolderAsset + where TCollectionAsset : Object + where TAsset : Object + { + [SerializeField] private TCollectionAsset m_collection; + + public TCollectionAsset Collection { get { return m_collection; } set { m_collection = value; } } + + protected override bool OnIsValid() + { + return m_collection != null; + } + } +} diff --git a/Packages/UGF.Assets/Editor/AssetFolderAsset`2.cs.meta b/Packages/UGF.Assets/Editor/AssetFolderAsset`2.cs.meta new file mode 100644 index 0000000..cd57b08 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderAsset`2.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 30d5816c1aa6457d8bc4f9e90917bc1d +timeCreated: 1700677128 \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/AssetFolderEditorGUIUtility.cs b/Packages/UGF.Assets/Editor/AssetFolderEditorGUIUtility.cs new file mode 100644 index 0000000..71dcd60 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderEditorGUIUtility.cs @@ -0,0 +1,41 @@ +using System; +using UnityEditor; +using UnityEngine; + +namespace UGF.Assets.Editor +{ + public static class AssetFolderEditorGUIUtility + { + public static void DrawControlsGUILayout(SerializedObject serializedObject) + { + if (serializedObject == null) throw new ArgumentNullException(nameof(serializedObject)); + + if (serializedObject.targetObject is not AssetFolderAsset assetFolder) + { + throw new ArgumentException($"Serialized object target must be type of '{nameof(AssetFolderAsset)}'."); + } + + EditorGUILayout.Space(); + + using (new EditorGUILayout.HorizontalScope()) + { + GUILayout.FlexibleSpace(); + + using (new EditorGUI.DisabledScope(!assetFolder.IsValid())) + { + if (GUILayout.Button("Update")) + { + assetFolder.Update(); + } + } + } + + EditorGUILayout.Space(); + + if (!assetFolder.IsValid()) + { + EditorGUILayout.HelpBox("Asset folder is invalid, please check that all fields specified correctly.", MessageType.Warning); + } + } + } +} diff --git a/Packages/UGF.Assets/Editor/AssetFolderEditorGUIUtility.cs.meta b/Packages/UGF.Assets/Editor/AssetFolderEditorGUIUtility.cs.meta new file mode 100644 index 0000000..d89b470 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderEditorGUIUtility.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f9f3bf0e0f369c942bb78668d72cec6c \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/AssetFolderEditorUtility.cs b/Packages/UGF.Assets/Editor/AssetFolderEditorUtility.cs new file mode 100644 index 0000000..c52483f --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderEditorUtility.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.IO; +using UnityEditor; +using Object = UnityEngine.Object; + +namespace UGF.Assets.Editor +{ + public static class AssetFolderEditorUtility + { + private static readonly string[] m_searchInFolders = new string[1]; + + public static bool TryUpdate(IReadOnlyList assetFolders) + { + if (assetFolders == null) throw new ArgumentNullException(nameof(assetFolders)); + + bool all = true; + + for (int i = 0; i < assetFolders.Count; i++) + { + AssetFolderAsset assetFolder = assetFolders[i]; + + if (!TryUpdate(assetFolder)) + { + all = false; + } + } + + return all; + } + + public static bool TryUpdate(AssetFolderAsset assetFolder) + { + if (assetFolder == null) throw new ArgumentNullException(nameof(assetFolder)); + + if (assetFolder.IsValid()) + { + assetFolder.Update(); + return true; + } + + return false; + } + + public static string[] FindAssetsAsGuids(string folderPath) where T : Object + { + return FindAssetsAsGuids(folderPath, typeof(T)); + } + + public static string[] FindAssetsAsGuids(string folderPath, Type assetType) + { + if (string.IsNullOrEmpty(folderPath)) throw new ArgumentException("Value cannot be null or empty.", nameof(folderPath)); + if (assetType == null) throw new ArgumentNullException(nameof(assetType)); + + m_searchInFolders[0] = folderPath; + + string[] guids = AssetDatabase.FindAssets($"t:{assetType.Name}", m_searchInFolders); + + m_searchInFolders[0] = null; + + return guids; + } + + public static void TryGetAssetFolderPaths(ICollection paths, IReadOnlyList assetPaths) + { + if (paths == null) throw new ArgumentNullException(nameof(paths)); + if (assetPaths == null) throw new ArgumentNullException(nameof(assetPaths)); + + for (int i = 0; i < assetPaths.Count; i++) + { + string assetPath = assetPaths[i]; + + if (TryGetAssetFolderPath(assetPath, out string path)) + { + paths.Add(path); + } + } + } + + public static bool TryGetAssetFolderPath(Object asset, out string path) + { + if (asset == null) throw new ArgumentNullException(nameof(asset)); + + path = default; + + string assetPath = AssetDatabase.GetAssetPath(asset); + + return !string.IsNullOrEmpty(assetPath) && TryGetAssetFolderPath(assetPath, out path); + } + + public static bool TryGetAssetFolderPath(string assetPath, out string path) + { + if (string.IsNullOrEmpty(assetPath)) throw new ArgumentException("Value cannot be null or empty.", nameof(assetPath)); + + string name = Path.GetDirectoryName(assetPath); + + if (!string.IsNullOrEmpty(name)) + { + path = name.Replace('\\', '/'); + return true; + } + + path = default; + return false; + } + } +} diff --git a/Packages/UGF.Assets/Editor/AssetFolderEditorUtility.cs.meta b/Packages/UGF.Assets/Editor/AssetFolderEditorUtility.cs.meta new file mode 100644 index 0000000..9297457 --- /dev/null +++ b/Packages/UGF.Assets/Editor/AssetFolderEditorUtility.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e58aa66456782104896018ca791f252c \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/UGF.Assets.Editor.asmdef b/Packages/UGF.Assets/Editor/UGF.Assets.Editor.asmdef new file mode 100644 index 0000000..49637ea --- /dev/null +++ b/Packages/UGF.Assets/Editor/UGF.Assets.Editor.asmdef @@ -0,0 +1,21 @@ +{ + "name": "UGF.Assets.Editor", + "rootNamespace": "UGF.Assets.Editor", + "references": [ + "GUID:abdd615e45137c74ca2ce9c636c78c15", + "GUID:088d00b6871540e44bce58af1a3f0f17", + "GUID:ff62901452104d14cae29322ac133c05", + "GUID:4806a292f99efd44aba38aea20847e17" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Packages/UGF.Assets/Editor/UGF.Assets.Editor.asmdef.meta b/Packages/UGF.Assets/Editor/UGF.Assets.Editor.asmdef.meta new file mode 100644 index 0000000..9fe1403 --- /dev/null +++ b/Packages/UGF.Assets/Editor/UGF.Assets.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c54ebf9bf71849f4b97d2be9494ec7ad +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UGF.Assets.Editor.csproj.DotSettings b/UGF.Assets.Editor.csproj.DotSettings new file mode 100644 index 0000000..eff1c1e --- /dev/null +++ b/UGF.Assets.Editor.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file From e942bfa24fba70cbe11b94c6a9ce6e4108901afd Mon Sep 17 00:00:00 2001 From: Vorobey Date: Wed, 22 Nov 2023 21:22:28 +0300 Subject: [PATCH 4/4] Add tests --- Assets/Scenes/Empty.unity | 14 ++-- Assets/UGF.Assets.Editor.Tests.meta | 8 ++ .../UGF.Assets.Editor.Tests/AssetsFolder.meta | 8 ++ .../AssetsFolder/New Material.mat | 84 +++++++++++++++++++ .../AssetsFolder/New Material.mat.meta | 8 ++ .../AssetsFolder/New Material1.mat | 84 +++++++++++++++++++ .../AssetsFolder/New Material1.mat.meta | 8 ++ .../New Test Asset Collection Asset.asset | 17 ++++ ...New Test Asset Collection Asset.asset.meta | 8 ++ ...w Test Asset Collection Folder Asset.asset | 16 ++++ ...t Asset Collection Folder Asset.asset.meta | 8 ++ .../TestAssetCollectionAsset.cs | 13 +++ .../TestAssetCollectionAsset.cs.meta | 3 + .../TestAssetCollectionFolderAsset.cs | 28 +++++++ .../TestAssetCollectionFolderAsset.cs.meta | 3 + .../UGF.Assets.Editor.Tests.asmdef | 20 +++++ .../UGF.Assets.Editor.Tests.asmdef.meta | 7 ++ .../UGF.Assets/AssetEditorSettings.asset | 18 ++++ 18 files changed, 348 insertions(+), 7 deletions(-) create mode 100644 Assets/UGF.Assets.Editor.Tests.meta create mode 100644 Assets/UGF.Assets.Editor.Tests/AssetsFolder.meta create mode 100644 Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material.mat create mode 100644 Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material.mat.meta create mode 100644 Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material1.mat create mode 100644 Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material1.mat.meta create mode 100644 Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Asset.asset create mode 100644 Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Asset.asset.meta create mode 100644 Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Folder Asset.asset create mode 100644 Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Folder Asset.asset.meta create mode 100644 Assets/UGF.Assets.Editor.Tests/TestAssetCollectionAsset.cs create mode 100644 Assets/UGF.Assets.Editor.Tests/TestAssetCollectionAsset.cs.meta create mode 100644 Assets/UGF.Assets.Editor.Tests/TestAssetCollectionFolderAsset.cs create mode 100644 Assets/UGF.Assets.Editor.Tests/TestAssetCollectionFolderAsset.cs.meta create mode 100644 Assets/UGF.Assets.Editor.Tests/UGF.Assets.Editor.Tests.asmdef create mode 100644 Assets/UGF.Assets.Editor.Tests/UGF.Assets.Editor.Tests.asmdef.meta create mode 100644 ProjectSettings/Packages/UGF.Assets/AssetEditorSettings.asset diff --git a/Assets/Scenes/Empty.unity b/Assets/Scenes/Empty.unity index 5656a15..36da7c1 100644 --- a/Assets/Scenes/Empty.unity +++ b/Assets/Scenes/Empty.unity @@ -13,7 +13,7 @@ OcclusionCullingSettings: --- !u!104 &2 RenderSettings: m_ObjectHideFlags: 0 - serializedVersion: 9 + serializedVersion: 10 m_Fog: 0 m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} m_FogMode: 3 @@ -44,7 +44,6 @@ RenderSettings: LightmapSettings: m_ObjectHideFlags: 0 serializedVersion: 12 - m_GIWorkflowMode: 1 m_GISettings: serializedVersion: 2 m_BounceScale: 1 @@ -67,9 +66,6 @@ LightmapSettings: m_LightmapParameters: {fileID: 0} m_LightmapsBakeMode: 1 m_TextureCompression: 1 - m_FinalGather: 0 - m_FinalGatherFiltering: 1 - m_FinalGatherRayCount: 256 m_ReflectionCompression: 2 m_MixedBakeMode: 2 m_BakeBackend: 1 @@ -104,7 +100,7 @@ NavMeshSettings: serializedVersion: 2 m_ObjectHideFlags: 0 m_BuildSettings: - serializedVersion: 2 + serializedVersion: 3 agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 @@ -117,9 +113,13 @@ NavMeshSettings: cellSize: 0.16666667 manualTileSize: 0 tileSize: 256 - accuratePlacement: 0 + buildHeightMesh: 0 maxJobWorkers: 0 preserveTilesOutsideBounds: 0 debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1660057539 &9223372036854775807 +SceneRoots: + m_ObjectHideFlags: 0 + m_Roots: [] diff --git a/Assets/UGF.Assets.Editor.Tests.meta b/Assets/UGF.Assets.Editor.Tests.meta new file mode 100644 index 0000000..439078f --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 82c12e7369d5a454e850d7ec78897af6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UGF.Assets.Editor.Tests/AssetsFolder.meta b/Assets/UGF.Assets.Editor.Tests/AssetsFolder.meta new file mode 100644 index 0000000..af71eb0 --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/AssetsFolder.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6cb67ff0fbaa3f343b51685750b3f3ae +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material.mat b/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material.mat new file mode 100644 index 0000000..bc8d1e2 --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material.mat @@ -0,0 +1,84 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: New Material + m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + m_BuildTextureStacks: [] + m_AllowLocking: 1 diff --git a/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material.mat.meta b/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material.mat.meta new file mode 100644 index 0000000..92ad2ea --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: de2dddea353d57d478142c289d022485 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material1.mat b/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material1.mat new file mode 100644 index 0000000..6cb3ff2 --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material1.mat @@ -0,0 +1,84 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: New Material1 + m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + m_BuildTextureStacks: [] + m_AllowLocking: 1 diff --git a/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material1.mat.meta b/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material1.mat.meta new file mode 100644 index 0000000..d7f4a80 --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/AssetsFolder/New Material1.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2950179d4affa2a49b32a9a6c3291dbd +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Asset.asset b/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Asset.asset new file mode 100644 index 0000000..8fc7a14 --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Asset.asset @@ -0,0 +1,17 @@ +%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: f9dbe9e99ada43cd90a433361a6d42ef, type: 3} + m_Name: New Test Asset Collection Asset + m_EditorClassIdentifier: + m_assets: + - {fileID: 2100000, guid: de2dddea353d57d478142c289d022485, type: 2} + - {fileID: 2100000, guid: 2950179d4affa2a49b32a9a6c3291dbd, type: 2} diff --git a/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Asset.asset.meta b/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Asset.asset.meta new file mode 100644 index 0000000..ba6e4c6 --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Asset.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 58ce2f8a162320c4ca5b1563e5b8e99e +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Folder Asset.asset b/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Folder Asset.asset new file mode 100644 index 0000000..d52076b --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Folder Asset.asset @@ -0,0 +1,16 @@ +%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: 125ef81c41b649e6ae55035691e8c16b, type: 3} + m_Name: New Test Asset Collection Folder Asset + m_EditorClassIdentifier: + m_folder: {fileID: 102900000, guid: 6cb67ff0fbaa3f343b51685750b3f3ae, type: 3} + m_collection: {fileID: 11400000, guid: 58ce2f8a162320c4ca5b1563e5b8e99e, type: 2} diff --git a/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Folder Asset.asset.meta b/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Folder Asset.asset.meta new file mode 100644 index 0000000..d8f4f47 --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/New Test Asset Collection Folder Asset.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0f3cf6189ec53e344951132c16f22b09 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionAsset.cs b/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionAsset.cs new file mode 100644 index 0000000..2ae6500 --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionAsset.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace UGF.Assets.Editor.Tests +{ + [CreateAssetMenu(menuName = "Tests/TestAssetCollectionAsset")] + public class TestAssetCollectionAsset : ScriptableObject + { + [SerializeField] private List m_assets = new List(); + + public List Assets { get { return m_assets; } } + } +} diff --git a/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionAsset.cs.meta b/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionAsset.cs.meta new file mode 100644 index 0000000..e86dcd4 --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionAsset.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f9dbe9e99ada43cd90a433361a6d42ef +timeCreated: 1700676565 \ No newline at end of file diff --git a/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionFolderAsset.cs b/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionFolderAsset.cs new file mode 100644 index 0000000..8d93b50 --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionFolderAsset.cs @@ -0,0 +1,28 @@ +using UnityEditor; +using UnityEngine; + +namespace UGF.Assets.Editor.Tests +{ + [CreateAssetMenu(menuName = "Tests/TestAssetCollectionFolderAsset")] + public class TestAssetCollectionFolderAsset : AssetFolderAsset + { + protected override void OnUpdate() + { + Collection.Assets.Clear(); + + string[] guids = FindAssetsAsGuids(); + + for (int i = 0; i < guids.Length; i++) + { + string guid = guids[i]; + string path = AssetDatabase.GUIDToAssetPath(guid); + + var asset = AssetDatabase.LoadAssetAtPath(path); + + Collection.Assets.Add(asset); + } + + EditorUtility.SetDirty(Collection); + } + } +} diff --git a/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionFolderAsset.cs.meta b/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionFolderAsset.cs.meta new file mode 100644 index 0000000..049affc --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/TestAssetCollectionFolderAsset.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 125ef81c41b649e6ae55035691e8c16b +timeCreated: 1700676619 \ No newline at end of file diff --git a/Assets/UGF.Assets.Editor.Tests/UGF.Assets.Editor.Tests.asmdef b/Assets/UGF.Assets.Editor.Tests/UGF.Assets.Editor.Tests.asmdef new file mode 100644 index 0000000..fbbc4dd --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/UGF.Assets.Editor.Tests.asmdef @@ -0,0 +1,20 @@ +{ + "name": "UGF.Assets.Editor.Tests", + "rootNamespace": "", + "references": [ + "GUID:c54ebf9bf71849f4b97d2be9494ec7ad" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "nunit.framework.dll" + ], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/UGF.Assets.Editor.Tests/UGF.Assets.Editor.Tests.asmdef.meta b/Assets/UGF.Assets.Editor.Tests/UGF.Assets.Editor.Tests.asmdef.meta new file mode 100644 index 0000000..edd111f --- /dev/null +++ b/Assets/UGF.Assets.Editor.Tests/UGF.Assets.Editor.Tests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 23f5b7c2a2234ec4b902d4feb8b9d4f3 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/Packages/UGF.Assets/AssetEditorSettings.asset b/ProjectSettings/Packages/UGF.Assets/AssetEditorSettings.asset new file mode 100644 index 0000000..a9c5ea1 --- /dev/null +++ b/ProjectSettings/Packages/UGF.Assets/AssetEditorSettings.asset @@ -0,0 +1,18 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &1 +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: d94c12c52baab4c498c95d314cea614c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_foldersUpdateOnPostprocess: 1 + m_foldersUpdateOnBuild: 1 + m_folders: + - {fileID: 11400000, guid: 0f3cf6189ec53e344951132c16f22b09, type: 2}