Kaynağa Gözat

Sujith :) ->
1. Added tools to export custom information

Sujith:) 1 hafta önce
ebeveyn
işleme
dc7f605f59

+ 1 - 1
Assets/AssetBank/AssetDatabase.asmdef

@@ -1,7 +1,7 @@
 {
     "name": "AssetBank",
     "rootNamespace": "",
-    "references": [],
+    "references": ["GUID:e7c9410007423435ea89724962e62f27"],
     "includePlatforms": [],
     "excludePlatforms": [],
     "allowUnsafeCode": false,

+ 3 - 3
Assets/AssetBank/Editor/Settings/ProjectExporterSettings.cs

@@ -43,15 +43,15 @@ namespace AssetBank.Settings
         private const string k_SettingsPath = "Assets/AssetBank/Assets/ProjectExporterSettings.asset";
 
         [SerializeField]
-        private List<string> m_FoldersToIgnore = new List<string>();
+        private List<string> m_FoldersToIgnore = new();
         public List<string> FoldersToIgnore => m_FoldersToIgnore;
 
         [SerializeField]
-        private List<string> m_FileExtensionsToIgnore = new List<string>();
+        private List<string> m_FileExtensionsToIgnore = new();
         public List<string> FileExtensionsToIgnore => m_FileExtensionsToIgnore;
 
         [SerializeField]
-        private List<IgnoredUnityType> m_UnityTypesToIgnore = new List<IgnoredUnityType>();
+        private List<IgnoredUnityType> m_UnityTypesToIgnore = new();
         public List<IgnoredUnityType> UnityTypesToIgnore => m_UnityTypesToIgnore;
 
 

+ 3 - 0
Assets/AssetBank/Editor/Tools.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 5d4d5741bcc445889748b472f51b70d0
+timeCreated: 1753176210

+ 163 - 0
Assets/AssetBank/Editor/Tools/GuidMapperExporter.cs

@@ -0,0 +1,163 @@
+using System;
+using System.IO;
+using System.Linq;
+using UnityEditor;
+using UnityEngine;
+using AssetBank.Settings;
+using System.Collections.Generic;
+using IntelligentProjectAnalyzer.Helper;
+
+namespace AssetBank.Editor.Tools
+{
+    public static class GuidMapperExporter
+    {
+        private enum ExportFor
+        {
+            Script,
+            Scene,
+            Prefab,
+            ScriptableObject,
+            All
+        }
+        
+        [Serializable]
+        public class GuidMapper
+        {
+            public string Guid { get; set; }
+            public string Path { get; set; }
+        }
+
+        [MenuItem("Tools/GUID Exporter/Export Script GUIDs")]
+        public static void ExportScriptGuids()
+        {
+            Export(ExportFor.Script);
+        }
+        
+        [MenuItem("Tools/GUID Exporter/Export Scene GUIDs")]
+        public static void ExportSceneGuids()
+        {
+            Export(ExportFor.Scene);
+        }
+        
+        [MenuItem("Tools/GUID Exporter/Export Prefab GUIDs")]
+        public static void ExportPrefabGuids()
+        {
+            Export(ExportFor.Prefab);
+        }
+        
+        [MenuItem("Tools/GUID Exporter/Export ScriptableObject GUIDs")]
+        public static void ExportScriptableObjectGuids()
+        {
+            Export(ExportFor.ScriptableObject);
+        }
+        
+        private static void Export(ExportFor exportFor)
+        {
+            var (searchPattern, extension) = GetSearchPattern(exportFor);
+            var searchResults = AssetDatabase.FindAssets(searchPattern, new[] { "Assets" });
+            
+            var settings = ProjectExporterSettings.GetOrCreateSettings();
+            var folderToIgnore = settings.FoldersToIgnore;
+            var mapperList = new List<GuidMapper>();
+            
+            foreach (var guid in searchResults)
+            {
+                var path = AssetDatabase.GUIDToAssetPath(guid);
+                if (extension != "*" && !path.EndsWith(extension)) continue;
+                
+                var directoryName = Path.GetDirectoryName(path);
+                if (folderToIgnore.Any(folder => directoryName != null && directoryName.StartsWith(folder, StringComparison.OrdinalIgnoreCase))) continue;
+                
+                var guidMapper = new GuidMapper
+                {
+                    Guid = guid,
+                    Path = path
+                };
+                mapperList.Add(guidMapper);
+            }
+            
+            var savePath = EditorUtility.SaveFilePanel("Save GUID Mapper", Application.dataPath, $"{exportFor} - guidMapper", "json");
+            if (!string.IsNullOrEmpty(savePath))
+            {
+                JsonFileSystem.Write(mapperList, savePath);
+            }
+            
+            Debug.Log($"Successfully exported {mapperList.Count} {exportFor} GUIDs");
+        }
+        
+        private static (string searchPattern, string extension) GetSearchPattern(ExportFor exportFor)
+        {
+            return exportFor switch
+            {
+                ExportFor.Script => ("t:MonoScript", "cs"),
+                ExportFor.Scene => ("t:SceneAsset", "unity"),
+                ExportFor.Prefab => ("t:Prefab", "prefab"),
+                ExportFor.ScriptableObject => ("t:ScriptableObject", "asset"),
+                ExportFor.All => ("", "*"),
+                _ => throw new ArgumentOutOfRangeException(nameof(exportFor), exportFor, null)
+            };
+        }
+        
+        [MenuItem("Tools/GUID Exporter/Export All GUIDs")]
+        public static void ExportAllGuids()
+        {
+            BulkExport();
+        }
+
+        private static void BulkExport()
+        {
+            var typeToGuidMapper = new Dictionary<Type, List<GuidMapper>>();
+            
+            var settings = ProjectExporterSettings.GetOrCreateSettings();
+            var folderToIgnore = settings.FoldersToIgnore;
+            var assets = AssetDatabase.FindAssets("", new[] { "Assets" });
+            foreach (var guid in assets)
+            {
+                var path = AssetDatabase.GUIDToAssetPath(guid);
+                
+                if (folderToIgnore.Any(folder => path.StartsWith(folder, StringComparison.OrdinalIgnoreCase))) continue;
+                
+                var extension = Path.GetExtension(path);
+                var type = AssetDatabase.GetMainAssetTypeAtPath(path);
+                if (type == null || extension == null) continue;
+
+                if (type.IsSubclassOf(typeof(ScriptableObject)) && extension == ".asset")
+                {
+                    type = typeof(ScriptableObject);
+                }
+
+                if (type == typeof(DefaultAsset) && File.GetAttributes(path).HasFlag(FileAttributes.Directory))
+                {
+                    continue;
+                }
+
+                var guidMapper = new GuidMapper
+                {
+                    Guid = guid,
+                    Path = path
+                };
+                
+                if (!typeToGuidMapper.ContainsKey(type))
+                {
+                    typeToGuidMapper[type] = new List<GuidMapper>();
+                }
+                
+                typeToGuidMapper[type].Add(guidMapper);
+            }
+            
+            var savePath = EditorUtility.SaveFilePanel("Save GUID Mappers", Application.dataPath, "guidMappers", "json");
+            if (!string.IsNullOrEmpty(savePath))
+            {
+                foreach (var (type, guidMappers) in typeToGuidMapper)
+                {
+                    var friendlyName = type.Name.Split('.').Last();
+                    var fileName = $"{friendlyName} - guidMapper";
+                    var filePath = Path.Combine(Path.GetDirectoryName(savePath) ?? Application.dataPath, fileName);
+                    JsonFileSystem.Write(guidMappers, filePath);
+                }
+            }
+            
+            Debug.Log($"Exported {typeToGuidMapper.Count} GUID Mappers");
+        }
+    }
+}

+ 3 - 0
Assets/AssetBank/Editor/Tools/GuidMapperExporter.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 8fa68775ab73403cbec6a8aaf54c8718
+timeCreated: 1753176244

+ 52 - 0
Assets/AssetBank/Editor/Tools/ScriptExporter.cs

@@ -0,0 +1,52 @@
+using System;
+using System.IO;
+using System.Linq;
+using UnityEditor;
+using UnityEngine;
+using AssetBank.Settings;
+using System.Collections.Generic;
+
+namespace AssetBank.Editor.Tools
+{
+    public static class ScriptExporter
+    {
+        [MenuItem("Tools/Script Exporter/Export Scripts")]
+        public static void ExportScripts()
+        {
+            var settings = ProjectExporterSettings.GetOrCreateSettings();
+            var foldersToIgnore = settings.FoldersToIgnore;
+            var scriptGuids = AssetDatabase.FindAssets("t:Script", new[] { "Assets" });
+            
+            var filteredScriptPaths = new List<string>();
+            foreach (var guid in scriptGuids)
+            {
+                var path = AssetDatabase.GUIDToAssetPath(guid);
+                
+                var directoryName = Path.GetDirectoryName(path);
+                if (foldersToIgnore.Any(folder => directoryName != null && directoryName.StartsWith(folder, StringComparison.OrdinalIgnoreCase))) continue;
+                
+                filteredScriptPaths.Add(path);
+            }
+            
+            var savePath = EditorUtility.SaveFolderPanel("Choose destination to copy scripts into", Application.dataPath, "");
+            if (string.IsNullOrEmpty(savePath)) return;
+
+            foreach (var scriptPath in filteredScriptPaths)
+            {
+                CopyFile(scriptPath, savePath);
+            }
+        }
+
+        private static void CopyFile(string sourcePath, string targetDir)
+        {
+            var relativePath = Path.GetRelativePath(Application.dataPath, sourcePath);
+            var targetPath = Path.Combine(targetDir, relativePath);
+            var dirName = Path.GetDirectoryName(targetPath);
+            if (!Directory.Exists(dirName))
+            {
+                if (dirName != null) Directory.CreateDirectory(dirName);
+            }
+            File.Copy(sourcePath, targetPath, true);
+        }
+    }
+}

+ 3 - 0
Assets/AssetBank/Editor/Tools/ScriptExporter.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: a469c0258f9c460395d7a2a2764c5dd7
+timeCreated: 1753177006