ソースを参照

Folder structure and meta generation

Syed zainul abedin 2 週間 前
コミット
6e486a1c96

+ 8 - 0
Assets/AssetBank.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 84b275332bca5401587e034555a92938
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/AssetBank/.DS_Store


+ 16 - 0
Assets/AssetBank/AssetDatabase.asmdef

@@ -0,0 +1,16 @@
+{
+    "name": "assetdef",
+    "rootNamespace": "",
+    "references": [
+        "GUID:ae9b6d935e0774f0a9e43c085bf3c9c0"
+    ],
+    "includePlatforms": [],
+    "excludePlatforms": [],
+    "allowUnsafeCode": false,
+    "overrideReferences": false,
+    "precompiledReferences": [],
+    "autoReferenced": true,
+    "defineConstraints": [],
+    "versionDefines": [],
+    "noEngineReferences": false
+}

+ 7 - 0
Assets/AssetBank/AssetDatabase.asmdef.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 7efc6eefc450d472994cfb6bf1ddd048
+AssemblyDefinitionImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Assets/AssetBank/Editor.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 1ff08bf9edb4945ae855a9de36362a83
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Assets/AssetBank/Editor/AssetBankConfig.cs

@@ -0,0 +1,9 @@
+using UnityEditor;
+
+namespace AssetBank.Editor
+{
+    public class AssetBankConfig
+    {
+        
+    }
+}

+ 3 - 0
Assets/AssetBank/Editor/AssetBankConfig.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 7f64670905be4967af246569fa25591d
+timeCreated: 1752831907

+ 256 - 0
Assets/AssetBank/Editor/AssetBankScanner.cs

@@ -0,0 +1,256 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using LLM.Editor.Helper;
+using UnityEditor;
+using UnityEditorInternal;
+using UnityEngine;
+
+
+namespace AssetBank.Editor
+{
+    public class AssetBankScanner : EditorWindow
+    {
+        private List<string> folderToIgnore = new List<string>()
+        {
+            "AssetBank",
+            "Library"
+        };
+
+        private List<string> fileExtensionToIgnore = new List<string>()
+        {
+            ".meta",
+            ".dylib",
+            ".bytes"
+        };
+
+        private List<string> typesToIgnore = new List<string>()
+        {
+            typeof(DefaultAsset).ToString()
+        };
+        
+        private int currentTab = 0;
+        private string[] tabs = new[] { "General" , "Settings"};
+        
+        private readonly string folderstoignore = "AssetBankScanner_FolderToIgnore";
+        private readonly string extensiontoignore = "AssetBankScanner_FileExtensionToIgnore";
+        private readonly string typesToignore = "AssetBankScanner_TypesToIgnore";
+        private readonly string CACHE_FOLDER = "AssetBank";
+        private string cachePath;
+
+        private List<ReorderableList> prefLists = new();
+        
+        [MenuItem("Window/Asset Database Scanner")]
+        public static void ShowWindow()
+        {
+            var window = GetWindow<AssetBankScanner>();
+            window.titleContent = new GUIContent("Asset Database Scanner");
+            window.Show();
+        }
+
+        private void OnEnable()
+        {
+            cachePath = Path.Join("Library", CACHE_FOLDER);
+            LoadSettings();
+            SetupLists();
+        }
+
+        private void SetupLists()
+        {
+            prefLists.Add(CreateReorderableList("Folders to ignore", folderToIgnore));
+            prefLists.Add(CreateReorderableList("Files to ignore", fileExtensionToIgnore));
+            prefLists.Add(CreateReorderableList("Types to ignore", typesToIgnore));
+        }
+
+        private void LoadSettings()
+        {
+            if (!EditorPrefs.HasKey(folderstoignore))
+            {
+                EditorPrefs.SetString(folderstoignore, String.Join(";",folderToIgnore));
+            }
+
+            if (!EditorPrefs.HasKey(extensiontoignore))
+            {
+                EditorPrefs.SetString(extensiontoignore, String.Join(";", fileExtensionToIgnore));
+            }
+
+            if (!EditorPrefs.HasKey(typesToignore))
+            {
+                EditorPrefs.SetString(typesToignore, String.Join(";",typesToIgnore));
+            }
+
+            folderToIgnore = EditorPrefs.GetString(folderstoignore, "").Split(';')
+                .Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
+            fileExtensionToIgnore = EditorPrefs.GetString(extensiontoignore, "").Split(';')
+                .Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
+            typesToIgnore = EditorPrefs.GetString(typesToignore, "").Split(';').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
+        }
+
+        private void OnGUI()
+        {
+            EditorGUILayout.LabelField("Asset Bank Scanner", EditorStyles.boldLabel);
+            GUILayout.Space(10);
+            
+            currentTab = GUILayout.Toolbar(currentTab, tabs);
+            GUILayout.Space(10);
+            switch (currentTab)
+            {
+                case 0: DrawScanner(); break;
+                case 1: DrawSettings(); break;
+            }
+        }
+
+        private void DrawSettings()
+        {
+            GUILayout.Label("Settings", EditorStyles.boldLabel);
+            foreach (var prefList in prefLists)
+            {
+                prefList.DoLayoutList();
+                EditorGUILayout.Space();
+            }
+
+            if (GUILayout.Button("Clear cache", EditorStyles.miniButton))
+            {
+                Directory.Delete(cachePath, true);
+            }
+            return;
+            # region "Clear options"
+            if (GUILayout.Button("Clear preferences", EditorStyles.miniButton))
+            {
+                prefLists.Clear();
+                EditorPrefs.DeleteKey(folderstoignore);
+                EditorPrefs.DeleteKey(extensiontoignore);
+                EditorPrefs.DeleteKey(typesToignore);
+            }
+            #endregion
+        }
+
+        private ReorderableList CreateReorderableList(string title, List<string> targetList)
+        {
+            var list = new ReorderableList(targetList, typeof(string), true, true, true, true)
+                {
+                    drawHeaderCallback = rect =>
+                    {
+                        EditorGUI.LabelField(rect, title);
+                    },
+                    drawElementCallback = (rect, index, isActive, isFocused) =>
+                    {
+                        targetList[index] = EditorGUI.TextField(
+                            new Rect(rect.x, rect.y + 2, rect.width, EditorGUIUtility.singleLineHeight),
+                            targetList[index]
+                        );
+                    },
+                    onAddCallback = l =>
+                    {
+                        targetList.Add("");
+                    },
+                    onRemoveCallback = l =>
+                    {
+                        targetList.RemoveAt(l.index);
+                    }
+                };
+
+            return list;
+        }
+
+
+        private void DrawScanner()
+        {
+            if (GUILayout.Button("Scan project", GUILayout.Height(25)))
+            {
+                ScanProject();
+            }
+        }
+
+        private void ScanProject()
+        {
+            CreateMeta();
+            SerializeProjectSettings();
+        }
+
+        private void SerializeProjectSettings()
+        {
+            
+        }
+
+        private void CreateMeta()
+        {
+            float index = 0;
+            var assetPaths = AssetDatabase.GetAllAssetPaths();
+            int assetCount = assetPaths.Length;
+
+            foreach (var assetPath in assetPaths)
+            {
+                var dataPath = Path.Join(cachePath, assetPath) + ".json";
+                var metaPath = Path.Join(cachePath, assetPath) + ".meta" + ".json";
+
+                var guid = AssetDatabase.AssetPathToGUID(assetPath);
+                
+                var progress = index / assetCount;
+                index++;
+                if (string.IsNullOrEmpty(guid))
+                {
+                    Debug.LogWarning("Asset is invalid: " + assetPath);
+                    continue;
+                }
+                var extension = Path.GetExtension(assetPath);
+
+                if (fileExtensionToIgnore.Contains(extension))
+                {
+                    Debug.LogWarning("Asset file is not supported: " + assetPath);
+                    continue;
+                }
+                FileInfo info = new FileInfo(metaPath);
+                if (info.Directory != null)
+                {
+                    if (folderToIgnore.Contains(info.Directory.FullName))
+                    {
+                        Debug.Log("Ignoring directory: " + assetPath);
+                        continue;
+                    }
+                    info.Directory.Create();
+                }
+                
+                AssetMetaData assetMetaData = new AssetMetaData
+                {
+                    path = assetPath,
+                    guid = guid
+                };
+
+                if (EditorUtility.DisplayCancelableProgressBar("Updating", "Updating meta for file" + assetPath,
+                        progress))
+                {
+                    return;
+                }
+                Thread.Sleep(1);
+                var metaData = assetMetaData.ToJson();
+                File.WriteAllText(metaPath, metaData);
+                SerializeFile(assetPath, dataPath);
+            }
+            EditorUtility.ClearProgressBar();
+        }
+
+        private void SerializeFile(string path, string dataPath)
+        {
+            Type type = AssetDatabase.GetMainAssetTypeAtPath(path);
+            
+            // Looking at supporting types only
+            if (type != typeof(GameObject) && type != typeof(Texture) && type != typeof(Material) &&
+                type != typeof(Shader) && type != typeof(Font) && type != typeof(PlayerSettings) &&
+                type != typeof(Animation) && type != typeof(Material) &&
+                type != typeof(PrefabAssetType) && type != typeof(TextAsset) && type != typeof(AudioClip) &&
+                type != typeof(SceneAsset) && type != typeof(MonoScript) &&
+                type != typeof(ScriptableObject))
+            {
+                return;
+            }
+            AssetData assetData = new AssetData();
+
+            // TODO: Serialization for asset types
+            var jsonifiedAsset = assetData.ToJson();
+            File.WriteAllText(dataPath, jsonifiedAsset);
+        }
+    }
+}

+ 11 - 0
Assets/AssetBank/Editor/AssetBankScanner.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5e9f928f678334417b5ae6776de028c6
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 17 - 0
Assets/AssetBank/Editor/AssetMetaData.cs

@@ -0,0 +1,17 @@
+using System.Reflection;
+
+namespace AssetBank.Editor
+{
+    public class AssetMetaData
+    {
+        public string path;
+        public string guid;
+    }
+
+    public class AssetData
+    {
+        public string type;
+        public PropertyInfo[] properties;
+        public string[] dependencies;
+    }
+}

+ 3 - 0
Assets/AssetBank/Editor/AssetMetaData.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 0ce6485c9794419ebd69009eede17c28
+timeCreated: 1752822068

+ 8 - 0
Assets/AssetBank/Editor/UnityAssetSerializer.cs

@@ -0,0 +1,8 @@
+namespace AssetBank.Editor
+{
+    public interface UnityAssetSerializer<T> where T : UnityEngine.Object
+    {
+        T Serialize();
+        T Deserialize();
+    }
+}

+ 3 - 0
Assets/AssetBank/Editor/UnityAssetSerializer.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 60350600c9fb4016a0969e0357411623
+timeCreated: 1752840889