diff --git a/Assets/Editor/Art_Tools/ArtResourceConfigEditor.cs b/Assets/Editor/Art_Tools/ArtResourceConfigEditor.cs index 8bfd172..c0ca3af 100644 --- a/Assets/Editor/Art_Tools/ArtResourceConfigEditor.cs +++ b/Assets/Editor/Art_Tools/ArtResourceConfigEditor.cs @@ -65,6 +65,18 @@ namespace EditorArt_Tools window.Show(); } + [MenuItem("美术工具/路径管理/修复丢失的引用")] + public static void FixMissingReferences() + { + FixAllMissingReferences(); + } + + [MenuItem("美术工具/路径管理/清理SO丢失文件")] + public static void CleanupMissingItems() + { + CleanupAllMissingItems(); + } + private void OnEnable() { RefreshTableList(); @@ -1220,7 +1232,7 @@ namespace EditorArt_Tools // 清空原始列表 selectedTable.Items.Clear(); - // 将暂存区的数据复制到原始数据 + // 将暂存区的数据复制到原始数据,同时更新路径 foreach (var tempItem in tempItemsList) { var newItem = new ArtItemData @@ -1229,7 +1241,9 @@ namespace EditorArt_Tools Name = tempItem.Name, Desc = tempItem.Desc, Sprite = tempItem.Sprite, + SpritePath = tempItem.Sprite != null ? AssetDatabase.GetAssetPath(tempItem.Sprite) : "", SpineAsset = tempItem.SpineAsset, + SpineAssetPath = tempItem.SpineAsset != null ? AssetDatabase.GetAssetPath(tempItem.SpineAsset) : "", SpineAnimName = tempItem.SpineAnimName }; selectedTable.Items.Add(newItem); @@ -1642,5 +1656,326 @@ namespace EditorArt_Tools } #endregion + + #region 修复丢失引用和清理功能 + + /// + /// 修复所有配置表中丢失的引用 + /// 按照路径来找到引用(与"更新所有美术资源路径"相反) + /// + private static void FixAllMissingReferences() + { + if (!EditorUtility.DisplayDialog("修复丢失的引用", + "此操作将遍历所有配置表,根据路径信息修复丢失的引用。\n" + + "适用于跨项目拉取代码后引用丢失但路径正确的情况。\n\n" + + "确定要继续吗?", + "确定", "取消")) + { + return; + } + + try + { + EditorUtility.DisplayProgressBar("修复丢失的引用", "正在查找配置表...", 0f); + + // 查找所有ArtTableSO文件 + string[] guids = AssetDatabase.FindAssets("t:ArtTableSO", new[] { SO_ROOT_PATH }); + + if (guids.Length == 0) + { + EditorUtility.ClearProgressBar(); + EditorUtility.DisplayDialog("提示", "未找到任何配置表。", "确定"); + return; + } + + int totalFixed = 0; + int totalTables = 0; + List errorMessages = new List(); + List processedTables = new List(); + + for (int i = 0; i < guids.Length; i++) + { + string path = AssetDatabase.GUIDToAssetPath(guids[i]); + ArtTableSO table = AssetDatabase.LoadAssetAtPath(path); + + if (table == null) continue; + + EditorUtility.DisplayProgressBar("修复丢失的引用", + $"正在处理: {table.TableName} ({i + 1}/{guids.Length})", + (float)i / guids.Length); + + int fixedInTable = FixTableReferences(table, errorMessages); + + if (fixedInTable > 0) + { + totalFixed += fixedInTable; + totalTables++; + processedTables.Add($"{table.TableName}: {fixedInTable}个"); + + // 保存修改 + EditorUtility.SetDirty(table); + } + } + + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + EditorUtility.ClearProgressBar(); + + // 显示结果 + string message = $"修复完成!\n\n" + + $"处理的配置表: {guids.Length}个\n" + + $"修复引用的配置表: {totalTables}个\n" + + $"总共修复的引用: {totalFixed}个"; + + if (processedTables.Count > 0) + { + message += "\n\n修复详情:\n" + string.Join("\n", processedTables); + } + + if (errorMessages.Count > 0) + { + message += "\n\n⚠️ 以下问题需要注意:\n" + string.Join("\n", errorMessages); + } + + EditorUtility.DisplayDialog(totalFixed > 0 ? "修复成功" : "无需修复", message, "确定"); + + Debug.Log($"[修复丢失引用] {message}"); + } + catch (System.Exception ex) + { + EditorUtility.ClearProgressBar(); + EditorUtility.DisplayDialog("错误", $"修复过程中出现错误:\n{ex.Message}", "确定"); + Debug.LogError($"[修复丢失引用] 错误: {ex.Message}\n{ex.StackTrace}"); + } + } + + /// + /// 修复单个配置表的引用 + /// + private static int FixTableReferences(ArtTableSO table, List errorMessages) + { + int fixedCount = 0; + + foreach (var item in table.Items) + { + // 修复Sprite引用 + if (item.Sprite == null && !string.IsNullOrEmpty(item.SpritePath)) + { + Sprite sprite = AssetDatabase.LoadAssetAtPath(item.SpritePath); + if (sprite != null) + { + item.Sprite = sprite; + fixedCount++; + Debug.Log($"[修复引用] {table.TableName}/{item.Name}: 修复了Sprite引用 ({item.SpritePath})"); + } + else + { + string error = $"[{table.TableName}/{item.Name}] 找不到Sprite: {item.SpritePath}"; + errorMessages.Add(error); + Debug.LogWarning(error); + } + } + + // 修复SpineAsset引用 + if (item.SpineAsset == null && !string.IsNullOrEmpty(item.SpineAssetPath)) + { + SkeletonDataAsset spineAsset = AssetDatabase.LoadAssetAtPath(item.SpineAssetPath); + if (spineAsset != null) + { + item.SpineAsset = spineAsset; + fixedCount++; + Debug.Log($"[修复引用] {table.TableName}/{item.Name}: 修复了SpineAsset引用 ({item.SpineAssetPath})"); + } + else + { + string error = $"[{table.TableName}/{item.Name}] 找不到SpineAsset: {item.SpineAssetPath}"; + errorMessages.Add(error); + Debug.LogWarning(error); + } + } + + // 检查既没有引用又没有路径的情况 + if (item.Sprite == null && string.IsNullOrEmpty(item.SpritePath) && + item.SpineAsset == null && string.IsNullOrEmpty(item.SpineAssetPath)) + { + string error = $"[{table.TableName}/{item.Name}] 既没有引用也没有路径,需要手动配置"; + errorMessages.Add(error); + Debug.LogWarning(error); + } + } + + return fixedCount; + } + + /// + /// 清理所有配置表中引用丢失的Item + /// + private static void CleanupAllMissingItems() + { + if (!EditorUtility.DisplayDialog("清理丢失文件", + "此操作将删除所有配置表中引用丢失的资源项。\n" + + "同时会同步更新对应的JSON文件。\n\n" + + "⚠️ 此操作不可恢复!\n\n" + + "确定要继续吗?", + "确定", "取消")) + { + return; + } + + try + { + EditorUtility.DisplayProgressBar("清理丢失文件", "正在查找配置表...", 0f); + + // 查找所有ArtTableSO文件 + string[] guids = AssetDatabase.FindAssets("t:ArtTableSO", new[] { SO_ROOT_PATH }); + + if (guids.Length == 0) + { + EditorUtility.ClearProgressBar(); + EditorUtility.DisplayDialog("提示", "未找到任何配置表。", "确定"); + return; + } + + int totalRemoved = 0; + int totalTables = 0; + List cleanedTables = new List(); + + for (int i = 0; i < guids.Length; i++) + { + string path = AssetDatabase.GUIDToAssetPath(guids[i]); + ArtTableSO table = AssetDatabase.LoadAssetAtPath(path); + + if (table == null) continue; + + EditorUtility.DisplayProgressBar("清理丢失文件", + $"正在处理: {table.TableName} ({i + 1}/{guids.Length})", + (float)i / guids.Length); + + int removedInTable = CleanupTableMissingItems(table); + + if (removedInTable > 0) + { + totalRemoved += removedInTable; + totalTables++; + cleanedTables.Add($"{table.TableName}: 移除{removedInTable}个"); + + // 保存修改 + EditorUtility.SetDirty(table); + + // 同步到JSON + SyncTableToJson(table); + } + } + + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + EditorUtility.ClearProgressBar(); + + // 显示结果 + string message = $"清理完成!\n\n" + + $"处理的配置表: {guids.Length}个\n" + + $"清理的配置表: {totalTables}个\n" + + $"总共移除的资源项: {totalRemoved}个"; + + if (cleanedTables.Count > 0) + { + message += "\n\n清理详情:\n" + string.Join("\n", cleanedTables); + } + + EditorUtility.DisplayDialog(totalRemoved > 0 ? "清理成功" : "无需清理", message, "确定"); + + Debug.Log($"[清理丢失文件] {message}"); + } + catch (System.Exception ex) + { + EditorUtility.ClearProgressBar(); + EditorUtility.DisplayDialog("错误", $"清理过程中出现错误:\n{ex.Message}", "确定"); + Debug.LogError($"[清理丢失文件] 错误: {ex.Message}\n{ex.StackTrace}"); + } + } + + /// + /// 清理单个配置表中引用丢失的Item + /// + private static int CleanupTableMissingItems(ArtTableSO table) + { + List itemsToRemove = new List(); + + foreach (var item in table.Items) + { + bool hasMissingReference = false; + string missingInfo = ""; + + // 检查Sprite引用是否丢失 + if (!string.IsNullOrEmpty(item.SpritePath) && item.Sprite == null) + { + hasMissingReference = true; + missingInfo += $" Sprite({item.SpritePath})"; + } + + // 检查SpineAsset引用是否丢失 + if (!string.IsNullOrEmpty(item.SpineAssetPath) && item.SpineAsset == null) + { + hasMissingReference = true; + missingInfo += $" SpineAsset({item.SpineAssetPath})"; + } + + if (hasMissingReference) + { + itemsToRemove.Add(item); + Debug.Log($"[清理丢失文件] {table.TableName}/{item.Name}: 标记为删除 - 丢失:{missingInfo}"); + } + } + + // 移除标记的Item + foreach (var item in itemsToRemove) + { + table.Items.Remove(item); + } + + return itemsToRemove.Count; + } + + /// + /// 同步单个配置表到JSON(静态版本) + /// + private static void SyncTableToJson(ArtTableSO table) + { + string soPath = AssetDatabase.GetAssetPath(table); + string relativePath = soPath.Replace(SO_ROOT_PATH, "").Replace(".asset", ".json"); + string jsonPath = JSON_ROOT_PATH + relativePath; + + // 确保目录存在 + string directory = Path.GetDirectoryName(jsonPath); + if (!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + + // 创建JSON数据 + var jsonData = new ArtTableJsonData + { + TableId = table.TableId, + TableName = table.TableName, + Items = table.Items.Select(item => new ArtItemJsonData + { + Id = item.Id, + Name = item.Name, + Desc = item.Desc, + SpritePath = item.Sprite != null ? AssetDatabase.GetAssetPath(item.Sprite) : "", + SpineAssetPath = item.SpineAsset != null ? AssetDatabase.GetAssetPath(item.SpineAsset) : "", + SpineAnimName = item.SpineAnimName + }).ToList() + }; + + string json = JsonUtility.ToJson(jsonData, true); + File.WriteAllText(jsonPath, json); + + AssetDatabase.Refresh(); + + Debug.Log($"[同步JSON] {jsonPath}"); + } + + #endregion } } diff --git a/Assets/Editor/Art_Tools/BatchCreateSceneResources.cs b/Assets/Editor/Art_Tools/BatchCreateSceneResources.cs index 040e07b..037bbe1 100644 --- a/Assets/Editor/Art_Tools/BatchCreateSceneResources.cs +++ b/Assets/Editor/Art_Tools/BatchCreateSceneResources.cs @@ -1,288 +1,288 @@ -using UnityEngine; -using UnityEditor; -using System.IO; -using System.Collections.Generic; -using ArtResource; +// using UnityEngine; +// using UnityEditor; +// using System.IO; +// using System.Collections.Generic; +// using ArtResource; -namespace EditorArt_Tools -{ - /// - /// 批量创建场景资源配置表 - /// - public class BatchCreateSceneResources : EditorWindow - { - private const string SO_ROOT_PATH = "Assets/Art_SubModule/Art_SO/DecorateScene"; - private const string JSON_ROOT_PATH = "Assets/Art_SubModule/Art_Json/DecorateScene"; - private const string MANIFEST_PATH = "Assets/Art_SubModule/Art_SO/art_table_manifest.json"; +// namespace EditorArt_Tools +// { +// /// +// /// 批量创建场景资源配置表 +// /// +// public class BatchCreateSceneResources : EditorWindow +// { +// private const string SO_ROOT_PATH = "Assets/Art_SubModule/Art_SO/DecorateScene"; +// private const string JSON_ROOT_PATH = "Assets/Art_SubModule/Art_Json/DecorateScene"; +// private const string MANIFEST_PATH = "Assets/Art_SubModule/Art_SO/art_table_manifest.json"; - private int startIndex = 15; - private int endIndex = 50; - private string prefix = "Scene"; - private string suffix = "Resource"; +// private int startIndex = 15; +// private int endIndex = 50; +// private string prefix = "Scene"; +// private string suffix = "Resource"; - [MenuItem("美术工具/批量创建场景资源")] - public static void ShowWindow() - { - var window = GetWindow("批量创建场景资源"); - window.minSize = new Vector2(400, 300); - window.Show(); - } +// [MenuItem("美术工具/批量创建场景资源")] +// public static void ShowWindow() +// { +// var window = GetWindow("批量创建场景资源"); +// window.minSize = new Vector2(400, 300); +// window.Show(); +// } - private void OnGUI() - { - EditorGUILayout.LabelField("批量创建场景资源配置表", EditorStyles.boldLabel); - EditorGUILayout.Space(10); +// private void OnGUI() +// { +// EditorGUILayout.LabelField("批量创建场景资源配置表", EditorStyles.boldLabel); +// EditorGUILayout.Space(10); - EditorGUILayout.HelpBox( - "将在以下路径创建配置表:\n" + - $"SO: {SO_ROOT_PATH}\n" + - $"JSON: {JSON_ROOT_PATH}", - MessageType.Info); +// EditorGUILayout.HelpBox( +// "将在以下路径创建配置表:\n" + +// $"SO: {SO_ROOT_PATH}\n" + +// $"JSON: {JSON_ROOT_PATH}", +// MessageType.Info); - EditorGUILayout.Space(10); +// EditorGUILayout.Space(10); - prefix = EditorGUILayout.TextField("前缀:", prefix); - suffix = EditorGUILayout.TextField("后缀:", suffix); - startIndex = EditorGUILayout.IntField("起始序号:", startIndex); - endIndex = EditorGUILayout.IntField("结束序号:", endIndex); +// prefix = EditorGUILayout.TextField("前缀:", prefix); +// suffix = EditorGUILayout.TextField("后缀:", suffix); +// startIndex = EditorGUILayout.IntField("起始序号:", startIndex); +// endIndex = EditorGUILayout.IntField("结束序号:", endIndex); - EditorGUILayout.Space(10); +// EditorGUILayout.Space(10); - if (startIndex > endIndex) - { - EditorGUILayout.HelpBox("起始序号不能大于结束序号!", MessageType.Error); - return; - } +// if (startIndex > endIndex) +// { +// EditorGUILayout.HelpBox("起始序号不能大于结束序号!", MessageType.Error); +// return; +// } - int count = endIndex - startIndex + 1; - EditorGUILayout.HelpBox($"将创建 {count} 个配置表", MessageType.Info); +// int count = endIndex - startIndex + 1; +// EditorGUILayout.HelpBox($"将创建 {count} 个配置表", MessageType.Info); - EditorGUILayout.Space(10); +// EditorGUILayout.Space(10); - // 预览前几个文件名 - EditorGUILayout.LabelField("文件名预览:", EditorStyles.boldLabel); - for (int i = 0; i < Mathf.Min(3, count); i++) - { - int index = startIndex + i; - string fileName = $"{prefix}{index}{suffix}"; - EditorGUILayout.LabelField($" {i + 1}. {fileName}.asset / {fileName}.json"); - } - if (count > 3) - { - EditorGUILayout.LabelField($" ... (共 {count} 个)"); - } +// // 预览前几个文件名 +// EditorGUILayout.LabelField("文件名预览:", EditorStyles.boldLabel); +// for (int i = 0; i < Mathf.Min(3, count); i++) +// { +// int index = startIndex + i; +// string fileName = $"{prefix}{index}{suffix}"; +// EditorGUILayout.LabelField($" {i + 1}. {fileName}.asset / {fileName}.json"); +// } +// if (count > 3) +// { +// EditorGUILayout.LabelField($" ... (共 {count} 个)"); +// } - EditorGUILayout.Space(20); +// EditorGUILayout.Space(20); - GUI.backgroundColor = Color.green; - if (GUILayout.Button("开始创建", GUILayout.Height(40))) - { - CreateResources(); - } - GUI.backgroundColor = Color.white; - } +// GUI.backgroundColor = Color.green; +// if (GUILayout.Button("开始创建", GUILayout.Height(40))) +// { +// CreateResources(); +// } +// GUI.backgroundColor = Color.white; +// } - private void CreateResources() - { - if (startIndex > endIndex) - { - EditorUtility.DisplayDialog("错误", "起始序号不能大于结束序号!", "确定"); - return; - } +// private void CreateResources() +// { +// if (startIndex > endIndex) +// { +// EditorUtility.DisplayDialog("错误", "起始序号不能大于结束序号!", "确定"); +// return; +// } - // 确保目录存在 - if (!Directory.Exists(SO_ROOT_PATH)) - { - Directory.CreateDirectory(SO_ROOT_PATH); - } - if (!Directory.Exists(JSON_ROOT_PATH)) - { - Directory.CreateDirectory(JSON_ROOT_PATH); - } +// // 确保目录存在 +// if (!Directory.Exists(SO_ROOT_PATH)) +// { +// Directory.CreateDirectory(SO_ROOT_PATH); +// } +// if (!Directory.Exists(JSON_ROOT_PATH)) +// { +// Directory.CreateDirectory(JSON_ROOT_PATH); +// } - int successCount = 0; - int skipCount = 0; - List createdFiles = new List(); - int baseTableId = GetNextAvailableTableId(); +// int successCount = 0; +// int skipCount = 0; +// List createdFiles = new List(); +// int baseTableId = GetNextAvailableTableId(); - for (int i = startIndex; i <= endIndex; i++) - { - string fileName = $"{prefix}{i}{suffix}"; - string soPath = $"{SO_ROOT_PATH}/{fileName}.asset"; - string jsonPath = $"{JSON_ROOT_PATH}/{fileName}.json"; +// for (int i = startIndex; i <= endIndex; i++) +// { +// string fileName = $"{prefix}{i}{suffix}"; +// string soPath = $"{SO_ROOT_PATH}/{fileName}.asset"; +// string jsonPath = $"{JSON_ROOT_PATH}/{fileName}.json"; - // 检查文件是否已存在 - if (File.Exists(soPath) || File.Exists(jsonPath)) - { - skipCount++; - Debug.LogWarning($"文件已存在,跳过: {fileName}"); - continue; - } +// // 检查文件是否已存在 +// if (File.Exists(soPath) || File.Exists(jsonPath)) +// { +// skipCount++; +// Debug.LogWarning($"文件已存在,跳过: {fileName}"); +// continue; +// } - // 创建 ScriptableObject - var newTable = ScriptableObject.CreateInstance(); - newTable.TableName = fileName; - newTable.TableId = baseTableId + (i - startIndex); - newTable.Items = new List(); +// // 创建 ScriptableObject +// var newTable = ScriptableObject.CreateInstance(); +// newTable.TableName = fileName; +// newTable.TableId = baseTableId + (i - startIndex); +// newTable.Items = new List(); - // 保存 SO 文件 - AssetDatabase.CreateAsset(newTable, soPath); +// // 保存 SO 文件 +// AssetDatabase.CreateAsset(newTable, soPath); - // 创建 JSON 文件 - var jsonData = new ArtTableJsonData - { - TableId = newTable.TableId, - TableName = newTable.TableName, - Items = new List() - }; +// // 创建 JSON 文件 +// var jsonData = new ArtTableJsonData +// { +// TableId = newTable.TableId, +// TableName = newTable.TableName, +// Items = new List() +// }; - string json = JsonUtility.ToJson(jsonData, true); - File.WriteAllText(jsonPath, json); +// string json = JsonUtility.ToJson(jsonData, true); +// File.WriteAllText(jsonPath, json); - createdFiles.Add(fileName); - successCount++; +// createdFiles.Add(fileName); +// successCount++; - // 显示进度 - float progress = (float)(i - startIndex + 1) / (endIndex - startIndex + 1); - EditorUtility.DisplayProgressBar("创建资源", $"正在创建 {fileName}...", progress); - } +// // 显示进度 +// float progress = (float)(i - startIndex + 1) / (endIndex - startIndex + 1); +// EditorUtility.DisplayProgressBar("创建资源", $"正在创建 {fileName}...", progress); +// } - EditorUtility.ClearProgressBar(); +// EditorUtility.ClearProgressBar(); - // 刷新 AssetDatabase - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); +// // 刷新 AssetDatabase +// AssetDatabase.SaveAssets(); +// AssetDatabase.Refresh(); - // 更新 Manifest - UpdateManifest(); +// // 更新 Manifest +// UpdateManifest(); - // 显示结果 - string message = $"创建完成!\n成功创建: {successCount} 个\n跳过已存在: {skipCount} 个"; - if (createdFiles.Count > 0) - { - message += $"\n\n创建的文件:\n{string.Join("\n", createdFiles.ToArray())}"; - } +// // 显示结果 +// string message = $"创建完成!\n成功创建: {successCount} 个\n跳过已存在: {skipCount} 个"; +// if (createdFiles.Count > 0) +// { +// message += $"\n\n创建的文件:\n{string.Join("\n", createdFiles.ToArray())}"; +// } - EditorUtility.DisplayDialog("批量创建完成", message, "确定"); - Debug.Log($"[BatchCreateSceneResources] {message}"); - } +// EditorUtility.DisplayDialog("批量创建完成", message, "确定"); +// Debug.Log($"[BatchCreateSceneResources] {message}"); +// } - private int GetNextAvailableTableId() - { - // 查找所有现有的 ArtTableSO,获取最大的 TableId - string[] guids = AssetDatabase.FindAssets("t:ArtTableSO"); - int maxId = 0; +// private int GetNextAvailableTableId() +// { +// // 查找所有现有的 ArtTableSO,获取最大的 TableId +// string[] guids = AssetDatabase.FindAssets("t:ArtTableSO"); +// int maxId = 0; - foreach (string guid in guids) - { - string path = AssetDatabase.GUIDToAssetPath(guid); - var table = AssetDatabase.LoadAssetAtPath(path); - if (table != null && table.TableId > maxId) - { - maxId = table.TableId; - } - } +// foreach (string guid in guids) +// { +// string path = AssetDatabase.GUIDToAssetPath(guid); +// var table = AssetDatabase.LoadAssetAtPath(path); +// if (table != null && table.TableId > maxId) +// { +// maxId = table.TableId; +// } +// } - return maxId + 1; - } +// return maxId + 1; +// } - private void UpdateManifest() - { - try - { - // 查找所有ArtTableSO文件 - string[] guids = AssetDatabase.FindAssets("t:ArtTableSO", new[] { "Assets/Art_SubModule/Art_SO" }); - List tablePaths = new List(); +// private void UpdateManifest() +// { +// try +// { +// // 查找所有ArtTableSO文件 +// string[] guids = AssetDatabase.FindAssets("t:ArtTableSO", new[] { "Assets/Art_SubModule/Art_SO" }); +// List tablePaths = new List(); - foreach (string guid in guids) - { - string path = AssetDatabase.GUIDToAssetPath(guid); - if (!string.IsNullOrEmpty(path)) - { - tablePaths.Add(path); - } - } +// foreach (string guid in guids) +// { +// string path = AssetDatabase.GUIDToAssetPath(guid); +// if (!string.IsNullOrEmpty(path)) +// { +// tablePaths.Add(path); +// } +// } - // 排序路径 - tablePaths.Sort(); +// // 排序路径 +// tablePaths.Sort(); - // 创建或更新manifest - ArtTableManifest manifest; +// // 创建或更新manifest +// ArtTableManifest manifest; - // 如果文件存在,读取现有的预加载配置 - if (File.Exists(MANIFEST_PATH)) - { - string existingJson = File.ReadAllText(MANIFEST_PATH); - manifest = JsonUtility.FromJson(existingJson); +// // 如果文件存在,读取现有的预加载配置 +// if (File.Exists(MANIFEST_PATH)) +// { +// string existingJson = File.ReadAllText(MANIFEST_PATH); +// manifest = JsonUtility.FromJson(existingJson); - // 确保字段不为null - if (manifest == null) - { - manifest = new ArtTableManifest(); - } - if (manifest.preloadTableIds == null) - { - manifest.preloadTableIds = new int[0]; - } - } - else - { - // 创建新的manifest - manifest = new ArtTableManifest - { - preloadTableIds = new int[0] - }; - } +// // 确保字段不为null +// if (manifest == null) +// { +// manifest = new ArtTableManifest(); +// } +// if (manifest.preloadTableIds == null) +// { +// manifest.preloadTableIds = new int[0]; +// } +// } +// else +// { +// // 创建新的manifest +// manifest = new ArtTableManifest +// { +// preloadTableIds = new int[0] +// }; +// } - // 更新路径列表 - manifest.tablePaths = tablePaths.ToArray(); +// // 更新路径列表 +// manifest.tablePaths = tablePaths.ToArray(); - // 序列化为JSON - string json = JsonUtility.ToJson(manifest, true); +// // 序列化为JSON +// string json = JsonUtility.ToJson(manifest, true); - // 确保目录存在 - string directory = Path.GetDirectoryName(MANIFEST_PATH); - if (!Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } +// // 确保目录存在 +// string directory = Path.GetDirectoryName(MANIFEST_PATH); +// if (!Directory.Exists(directory)) +// { +// Directory.CreateDirectory(directory); +// } - // 写入文件 - File.WriteAllText(MANIFEST_PATH, json); - AssetDatabase.ImportAsset(MANIFEST_PATH); +// // 写入文件 +// File.WriteAllText(MANIFEST_PATH, json); +// AssetDatabase.ImportAsset(MANIFEST_PATH); - Debug.Log($"[BatchCreateSceneResources] Manifest文件已更新: {MANIFEST_PATH}, 共 {tablePaths.Count} 个表"); - } - catch (System.Exception ex) - { - Debug.LogError($"[BatchCreateSceneResources] 更新Manifest文件失败: {ex.Message}"); - } - } +// Debug.Log($"[BatchCreateSceneResources] Manifest文件已更新: {MANIFEST_PATH}, 共 {tablePaths.Count} 个表"); +// } +// catch (System.Exception ex) +// { +// Debug.LogError($"[BatchCreateSceneResources] 更新Manifest文件失败: {ex.Message}"); +// } +// } - [System.Serializable] - public class ArtTableManifest - { - public string[] tablePaths; - public int[] preloadTableIds; - } +// [System.Serializable] +// public class ArtTableManifest +// { +// public string[] tablePaths; +// public int[] preloadTableIds; +// } - [System.Serializable] - public class ArtTableJsonData - { - public int TableId; - public string TableName; - public List Items; - } +// [System.Serializable] +// public class ArtTableJsonData +// { +// public int TableId; +// public string TableName; +// public List Items; +// } - [System.Serializable] - public class ArtItemJsonData - { - public int Id; - public string Name; - public string Desc; - public string SpritePath; - public string SpineAssetPath; - public string SpineAnimName; - } - } -} +// [System.Serializable] +// public class ArtItemJsonData +// { +// public int Id; +// public string Name; +// public string Desc; +// public string SpritePath; +// public string SpineAssetPath; +// public string SpineAnimName; +// } +// } +// } diff --git a/Assets/Editor/Art_Tools/BatchImportSceneSprites.cs b/Assets/Editor/Art_Tools/BatchImportSceneSprites.cs index 67a1441..2c367e5 100644 --- a/Assets/Editor/Art_Tools/BatchImportSceneSprites.cs +++ b/Assets/Editor/Art_Tools/BatchImportSceneSprites.cs @@ -1,499 +1,499 @@ -using UnityEngine; -using UnityEditor; -using System.IO; -using System.Collections.Generic; -using System.Linq; -using ArtResource; +// using UnityEngine; +// using UnityEditor; +// using System.IO; +// using System.Collections.Generic; +// using System.Linq; +// using ArtResource; -namespace EditorArt_Tools -{ - /// - /// 批量导入场景Sprite资源到配置表 - /// - public class BatchImportSceneSprites : EditorWindow - { - private const string SO_ROOT_PATH = "Assets/Art_SubModule/Art_SO/DecorateScene"; - private const string JSON_ROOT_PATH = "Assets/Art_SubModule/Art_Json/DecorateScene"; - private const string SPRITE_ROOT_PATH = "Assets/Art_SubModule/Art_Resource/Art_UISprites/Decorate"; - private const string MANIFEST_PATH = "Assets/Art_SubModule/Art_SO/art_table_manifest.json"; +// namespace EditorArt_Tools +// { +// /// +// /// 批量导入场景Sprite资源到配置表 +// /// +// public class BatchImportSceneSprites : EditorWindow +// { +// private const string SO_ROOT_PATH = "Assets/Art_SubModule/Art_SO/DecorateScene"; +// private const string JSON_ROOT_PATH = "Assets/Art_SubModule/Art_Json/DecorateScene"; +// private const string SPRITE_ROOT_PATH = "Assets/Art_SubModule/Art_Resource/Art_UISprites/Decorate"; +// private const string MANIFEST_PATH = "Assets/Art_SubModule/Art_SO/art_table_manifest.json"; - private int startSceneIndex = 6; - private int endSceneIndex = 50; - private Vector2 scrollPosition; - private List importTasks = new List(); - private bool isProcessing = false; +// private int startSceneIndex = 6; +// private int endSceneIndex = 50; +// private Vector2 scrollPosition; +// private List importTasks = new List(); +// private bool isProcessing = false; - private class ImportTask - { - public string SceneName; - public string SoPath; - public string SpriteFolderPath; - public int SpriteCount; - public bool FolderExists; - public bool SoExists; - public ImportStatus Status; - } +// private class ImportTask +// { +// public string SceneName; +// public string SoPath; +// public string SpriteFolderPath; +// public int SpriteCount; +// public bool FolderExists; +// public bool SoExists; +// public ImportStatus Status; +// } - private enum ImportStatus - { - Pending, - Success, - Failed, - Skipped - } +// private enum ImportStatus +// { +// Pending, +// Success, +// Failed, +// Skipped +// } - [MenuItem("美术工具/批量导入场景Sprite")] - public static void ShowWindow() - { - var window = GetWindow("批量导入场景Sprite"); - window.minSize = new Vector2(800, 600); - window.Show(); - } +// [MenuItem("美术工具/批量导入场景Sprite")] +// public static void ShowWindow() +// { +// var window = GetWindow("批量导入场景Sprite"); +// window.minSize = new Vector2(800, 600); +// window.Show(); +// } - private void OnEnable() - { - ScanTasks(); - } +// private void OnEnable() +// { +// ScanTasks(); +// } - private void OnGUI() - { - EditorGUILayout.LabelField("批量导入场景Sprite资源", EditorStyles.boldLabel); - EditorGUILayout.Space(10); +// private void OnGUI() +// { +// EditorGUILayout.LabelField("批量导入场景Sprite资源", EditorStyles.boldLabel); +// EditorGUILayout.Space(10); - EditorGUILayout.HelpBox( - "此工具会自动扫描DecorateScene文件夹下的所有Scene配置表,\n" + - "并从对应的Sprite文件夹中批量导入所有sprite资源。", - MessageType.Info); +// EditorGUILayout.HelpBox( +// "此工具会自动扫描DecorateScene文件夹下的所有Scene配置表,\n" + +// "并从对应的Sprite文件夹中批量导入所有sprite资源。", +// MessageType.Info); - EditorGUILayout.Space(10); +// EditorGUILayout.Space(10); - // 设置范围 - EditorGUILayout.BeginHorizontal(); - EditorGUI.BeginChangeCheck(); - startSceneIndex = EditorGUILayout.IntField("起始场景序号:", startSceneIndex, GUILayout.Width(200)); - endSceneIndex = EditorGUILayout.IntField("结束场景序号:", endSceneIndex, GUILayout.Width(200)); - if (EditorGUI.EndChangeCheck()) - { - ScanTasks(); - } +// // 设置范围 +// EditorGUILayout.BeginHorizontal(); +// EditorGUI.BeginChangeCheck(); +// startSceneIndex = EditorGUILayout.IntField("起始场景序号:", startSceneIndex, GUILayout.Width(200)); +// endSceneIndex = EditorGUILayout.IntField("结束场景序号:", endSceneIndex, GUILayout.Width(200)); +// if (EditorGUI.EndChangeCheck()) +// { +// ScanTasks(); +// } - if (GUILayout.Button("刷新扫描", GUILayout.Width(100))) - { - ScanTasks(); - } - EditorGUILayout.EndHorizontal(); +// if (GUILayout.Button("刷新扫描", GUILayout.Width(100))) +// { +// ScanTasks(); +// } +// EditorGUILayout.EndHorizontal(); - EditorGUILayout.Space(10); +// EditorGUILayout.Space(10); - // 统计信息 - int validTasks = importTasks.Count(t => t.FolderExists && t.SoExists && t.SpriteCount > 0); - int totalSprites = importTasks.Where(t => t.FolderExists && t.SoExists).Sum(t => t.SpriteCount); +// // 统计信息 +// int validTasks = importTasks.Count(t => t.FolderExists && t.SoExists && t.SpriteCount > 0); +// int totalSprites = importTasks.Where(t => t.FolderExists && t.SoExists).Sum(t => t.SpriteCount); - EditorGUILayout.BeginHorizontal("box"); - EditorGUILayout.LabelField($"找到配置表: {importTasks.Count(t => t.SoExists)} 个"); - EditorGUILayout.LabelField($"可导入任务: {validTasks} 个"); - EditorGUILayout.LabelField($"总Sprite数: {totalSprites} 个"); - EditorGUILayout.EndHorizontal(); - - EditorGUILayout.Space(10); - - // 任务列表 - EditorGUILayout.LabelField("导入任务列表:", EditorStyles.boldLabel); - scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); - - foreach (var task in importTasks) - { - DrawTaskItem(task); - } - - EditorGUILayout.EndScrollView(); - - EditorGUILayout.Space(10); - - // 操作按钮 - GUI.enabled = !isProcessing && validTasks > 0; - GUI.backgroundColor = Color.green; - if (GUILayout.Button("开始批量导入", GUILayout.Height(40))) - { - StartBatchImport(); - } - GUI.backgroundColor = Color.white; - GUI.enabled = true; - - if (isProcessing) - { - EditorGUILayout.HelpBox("正在处理中,请稍候...", MessageType.Warning); - } - } - - private void DrawTaskItem(ImportTask task) - { - Color originalBg = GUI.backgroundColor; - - // 根据状态设置背景色 - switch (task.Status) - { - case ImportStatus.Success: - GUI.backgroundColor = new Color(0.5f, 1f, 0.5f, 0.3f); - break; - case ImportStatus.Failed: - GUI.backgroundColor = new Color(1f, 0.5f, 0.5f, 0.3f); - break; - case ImportStatus.Skipped: - GUI.backgroundColor = new Color(1f, 1f, 0.5f, 0.3f); - break; - } - - EditorGUILayout.BeginVertical("box"); - GUI.backgroundColor = originalBg; - - EditorGUILayout.BeginHorizontal(); - - // 状态图标 - string statusIcon = task.Status switch - { - ImportStatus.Success => "✔", - ImportStatus.Failed => "✘", - ImportStatus.Skipped => "⊘", - _ => "○" - }; - EditorGUILayout.LabelField(statusIcon, GUILayout.Width(20)); - - // 场景名称 - EditorGUILayout.LabelField(task.SceneName, EditorStyles.boldLabel, GUILayout.Width(150)); - - // SO状态 - if (task.SoExists) - { - GUI.color = Color.green; - EditorGUILayout.LabelField("SO✔", GUILayout.Width(40)); - } - else - { - GUI.color = Color.red; - EditorGUILayout.LabelField("SO✘", GUILayout.Width(40)); - } - GUI.color = Color.white; - - // 文件夹状态 - if (task.FolderExists) - { - GUI.color = Color.green; - EditorGUILayout.LabelField($"文件夹✔ ({task.SpriteCount} sprites)", GUILayout.Width(150)); - } - else - { - GUI.color = Color.red; - EditorGUILayout.LabelField("文件夹✘", GUILayout.Width(150)); - } - GUI.color = Color.white; - - GUILayout.FlexibleSpace(); - - // 状态文本 - if (task.Status != ImportStatus.Pending) - { - EditorGUILayout.LabelField(task.Status.ToString(), GUILayout.Width(80)); - } - - EditorGUILayout.EndHorizontal(); - - // 路径信息 - EditorGUI.indentLevel++; - EditorGUILayout.LabelField($"SO: {task.SoPath}", EditorStyles.miniLabel); - EditorGUILayout.LabelField($"Sprite: {task.SpriteFolderPath}", EditorStyles.miniLabel); - EditorGUI.indentLevel--; - - EditorGUILayout.EndVertical(); - } - - private void ScanTasks() - { - importTasks.Clear(); - - for (int i = startSceneIndex; i <= endSceneIndex; i++) - { - string sceneName = $"Scene{i}Resource"; - string soPath = $"{SO_ROOT_PATH}/{sceneName}.asset"; - string spriteFolderPath = $"{SPRITE_ROOT_PATH}/Scene{i}"; - - var task = new ImportTask - { - SceneName = sceneName, - SoPath = soPath, - SpriteFolderPath = spriteFolderPath, - SoExists = File.Exists(soPath), - FolderExists = Directory.Exists(spriteFolderPath), - Status = ImportStatus.Pending - }; - - // 统计Sprite数量 - if (task.FolderExists) - { - string[] guids = AssetDatabase.FindAssets("t:Sprite", new[] { spriteFolderPath }); - task.SpriteCount = guids.Length; - } - - importTasks.Add(task); - } - - Repaint(); - } - - private void StartBatchImport() - { - isProcessing = true; - - int successCount = 0; - int failedCount = 0; - int skippedCount = 0; - int totalSpritesImported = 0; - - try - { - for (int i = 0; i < importTasks.Count; i++) - { - var task = importTasks[i]; - - // 跳过无效任务 - if (!task.SoExists || !task.FolderExists || task.SpriteCount == 0) - { - task.Status = ImportStatus.Skipped; - skippedCount++; - continue; - } - - // 显示进度 - float progress = (float)i / importTasks.Count; - EditorUtility.DisplayProgressBar("批量导入", $"正在处理 {task.SceneName}...", progress); - - // 加载SO - var table = AssetDatabase.LoadAssetAtPath(task.SoPath); - if (table == null) - { - Debug.LogError($"无法加载配置表: {task.SoPath}"); - task.Status = ImportStatus.Failed; - failedCount++; - continue; - } - - // 获取所有Sprite - string[] guids = AssetDatabase.FindAssets("t:Sprite", new[] { task.SpriteFolderPath }); - if (guids.Length == 0) - { - task.Status = ImportStatus.Skipped; - skippedCount++; - continue; - } - - // 获取当前最大ID - int startId = table.Items.Count > 0 ? table.Items.Max(item => item.Id) + 1 : 1; - - // 导入Sprite - int importedCount = 0; - foreach (string guid in guids) - { - string assetPath = AssetDatabase.GUIDToAssetPath(guid); - Sprite sprite = AssetDatabase.LoadAssetAtPath(assetPath); - - if (sprite != null) - { - // 检查是否已存在同名资源 - if (table.Items.Any(item => item.Name == sprite.name)) - { - Debug.LogWarning($"[{task.SceneName}] 跳过重复资源: {sprite.name}"); - continue; - } - - var newItem = new ArtItemData - { - Id = startId + importedCount, - Name = sprite.name, - Desc = "", - Sprite = sprite - }; - - table.Items.Add(newItem); - importedCount++; - } - } - - if (importedCount > 0) - { - // 保存SO - EditorUtility.SetDirty(table); - AssetDatabase.SaveAssets(); - - // 同步JSON - SyncToJson(table); - - task.Status = ImportStatus.Success; - successCount++; - totalSpritesImported += importedCount; - - Debug.Log($"[{task.SceneName}] 成功导入 {importedCount} 个sprite资源"); - } - else - { - task.Status = ImportStatus.Skipped; - skippedCount++; - } - - Repaint(); - } - - // 更新Manifest - UpdateManifest(); - } - finally - { - EditorUtility.ClearProgressBar(); - isProcessing = false; - } - - // 显示结果 - string message = $"批量导入完成!\n\n" + - $"✔ 成功: {successCount} 个配置表\n" + - $"✘ 失败: {failedCount} 个\n" + - $"⊘ 跳过: {skippedCount} 个\n" + - $"📦 总共导入: {totalSpritesImported} 个sprite"; - - EditorUtility.DisplayDialog("批量导入完成", message, "确定"); - Debug.Log($"[BatchImportSceneSprites] {message}"); - - Repaint(); - } - - private void SyncToJson(ArtTableSO table) - { - string soPath = AssetDatabase.GetAssetPath(table); - string relativePath = soPath.Replace(SO_ROOT_PATH, "").Replace(".asset", ".json"); - string jsonPath = JSON_ROOT_PATH + relativePath; - - // 确保目录存在 - string directory = Path.GetDirectoryName(jsonPath); - if (!Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } - - // 创建JSON数据 - var jsonData = new ArtTableJsonData - { - TableId = table.TableId, - TableName = table.TableName, - Items = table.Items.Select(item => new ArtItemJsonData - { - Id = item.Id, - Name = item.Name, - Desc = item.Desc, - SpritePath = item.Sprite != null ? AssetDatabase.GetAssetPath(item.Sprite) : "", - SpineAssetPath = item.SpineAsset != null ? AssetDatabase.GetAssetPath(item.SpineAsset) : "", - SpineAnimName = item.SpineAnimName - }).ToList() - }; - - string json = JsonUtility.ToJson(jsonData, true); - File.WriteAllText(jsonPath, json); - - AssetDatabase.ImportAsset(jsonPath); - } - - private void UpdateManifest() - { - try - { - // 查找所有ArtTableSO文件 - string[] guids = AssetDatabase.FindAssets("t:ArtTableSO", new[] { "Assets/Art_SubModule/Art_SO" }); - List tablePaths = new List(); - - foreach (string guid in guids) - { - string path = AssetDatabase.GUIDToAssetPath(guid); - if (!string.IsNullOrEmpty(path)) - { - tablePaths.Add(path); - } - } - - // 排序路径 - tablePaths.Sort(); - - // 创建或更新manifest - ArtTableManifest manifest; - - // 如果文件存在,读取现有的预加载配置 - if (File.Exists(MANIFEST_PATH)) - { - string existingJson = File.ReadAllText(MANIFEST_PATH); - manifest = JsonUtility.FromJson(existingJson); - - if (manifest == null) - { - manifest = new ArtTableManifest(); - } - if (manifest.preloadTableIds == null) - { - manifest.preloadTableIds = new int[0]; - } - } - else - { - manifest = new ArtTableManifest - { - preloadTableIds = new int[0] - }; - } - - // 更新路径列表 - manifest.tablePaths = tablePaths.ToArray(); - - // 序列化为JSON - string json = JsonUtility.ToJson(manifest, true); - - // 确保目录存在 - string directory = Path.GetDirectoryName(MANIFEST_PATH); - if (!Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } - - // 写入文件 - File.WriteAllText(MANIFEST_PATH, json); - AssetDatabase.ImportAsset(MANIFEST_PATH); - - Debug.Log($"[BatchImportSceneSprites] Manifest文件已更新: {MANIFEST_PATH}"); - } - catch (System.Exception ex) - { - Debug.LogError($"[BatchImportSceneSprites] 更新Manifest文件失败: {ex.Message}"); - } - } - - [System.Serializable] - public class ArtTableManifest - { - public string[] tablePaths; - public int[] preloadTableIds; - } - - [System.Serializable] - public class ArtTableJsonData - { - public int TableId; - public string TableName; - public List Items; - } - - [System.Serializable] - public class ArtItemJsonData - { - public int Id; - public string Name; - public string Desc; - public string SpritePath; - public string SpineAssetPath; - public string SpineAnimName; - } - } -} +// EditorGUILayout.BeginHorizontal("box"); +// EditorGUILayout.LabelField($"找到配置表: {importTasks.Count(t => t.SoExists)} 个"); +// EditorGUILayout.LabelField($"可导入任务: {validTasks} 个"); +// EditorGUILayout.LabelField($"总Sprite数: {totalSprites} 个"); +// EditorGUILayout.EndHorizontal(); + +// EditorGUILayout.Space(10); + +// // 任务列表 +// EditorGUILayout.LabelField("导入任务列表:", EditorStyles.boldLabel); +// scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); + +// foreach (var task in importTasks) +// { +// DrawTaskItem(task); +// } + +// EditorGUILayout.EndScrollView(); + +// EditorGUILayout.Space(10); + +// // 操作按钮 +// GUI.enabled = !isProcessing && validTasks > 0; +// GUI.backgroundColor = Color.green; +// if (GUILayout.Button("开始批量导入", GUILayout.Height(40))) +// { +// StartBatchImport(); +// } +// GUI.backgroundColor = Color.white; +// GUI.enabled = true; + +// if (isProcessing) +// { +// EditorGUILayout.HelpBox("正在处理中,请稍候...", MessageType.Warning); +// } +// } + +// private void DrawTaskItem(ImportTask task) +// { +// Color originalBg = GUI.backgroundColor; + +// // 根据状态设置背景色 +// switch (task.Status) +// { +// case ImportStatus.Success: +// GUI.backgroundColor = new Color(0.5f, 1f, 0.5f, 0.3f); +// break; +// case ImportStatus.Failed: +// GUI.backgroundColor = new Color(1f, 0.5f, 0.5f, 0.3f); +// break; +// case ImportStatus.Skipped: +// GUI.backgroundColor = new Color(1f, 1f, 0.5f, 0.3f); +// break; +// } + +// EditorGUILayout.BeginVertical("box"); +// GUI.backgroundColor = originalBg; + +// EditorGUILayout.BeginHorizontal(); + +// // 状态图标 +// string statusIcon = task.Status switch +// { +// ImportStatus.Success => "✔", +// ImportStatus.Failed => "✘", +// ImportStatus.Skipped => "⊘", +// _ => "○" +// }; +// EditorGUILayout.LabelField(statusIcon, GUILayout.Width(20)); + +// // 场景名称 +// EditorGUILayout.LabelField(task.SceneName, EditorStyles.boldLabel, GUILayout.Width(150)); + +// // SO状态 +// if (task.SoExists) +// { +// GUI.color = Color.green; +// EditorGUILayout.LabelField("SO✔", GUILayout.Width(40)); +// } +// else +// { +// GUI.color = Color.red; +// EditorGUILayout.LabelField("SO✘", GUILayout.Width(40)); +// } +// GUI.color = Color.white; + +// // 文件夹状态 +// if (task.FolderExists) +// { +// GUI.color = Color.green; +// EditorGUILayout.LabelField($"文件夹✔ ({task.SpriteCount} sprites)", GUILayout.Width(150)); +// } +// else +// { +// GUI.color = Color.red; +// EditorGUILayout.LabelField("文件夹✘", GUILayout.Width(150)); +// } +// GUI.color = Color.white; + +// GUILayout.FlexibleSpace(); + +// // 状态文本 +// if (task.Status != ImportStatus.Pending) +// { +// EditorGUILayout.LabelField(task.Status.ToString(), GUILayout.Width(80)); +// } + +// EditorGUILayout.EndHorizontal(); + +// // 路径信息 +// EditorGUI.indentLevel++; +// EditorGUILayout.LabelField($"SO: {task.SoPath}", EditorStyles.miniLabel); +// EditorGUILayout.LabelField($"Sprite: {task.SpriteFolderPath}", EditorStyles.miniLabel); +// EditorGUI.indentLevel--; + +// EditorGUILayout.EndVertical(); +// } + +// private void ScanTasks() +// { +// importTasks.Clear(); + +// for (int i = startSceneIndex; i <= endSceneIndex; i++) +// { +// string sceneName = $"Scene{i}Resource"; +// string soPath = $"{SO_ROOT_PATH}/{sceneName}.asset"; +// string spriteFolderPath = $"{SPRITE_ROOT_PATH}/Scene{i}"; + +// var task = new ImportTask +// { +// SceneName = sceneName, +// SoPath = soPath, +// SpriteFolderPath = spriteFolderPath, +// SoExists = File.Exists(soPath), +// FolderExists = Directory.Exists(spriteFolderPath), +// Status = ImportStatus.Pending +// }; + +// // 统计Sprite数量 +// if (task.FolderExists) +// { +// string[] guids = AssetDatabase.FindAssets("t:Sprite", new[] { spriteFolderPath }); +// task.SpriteCount = guids.Length; +// } + +// importTasks.Add(task); +// } + +// Repaint(); +// } + +// private void StartBatchImport() +// { +// isProcessing = true; + +// int successCount = 0; +// int failedCount = 0; +// int skippedCount = 0; +// int totalSpritesImported = 0; + +// try +// { +// for (int i = 0; i < importTasks.Count; i++) +// { +// var task = importTasks[i]; + +// // 跳过无效任务 +// if (!task.SoExists || !task.FolderExists || task.SpriteCount == 0) +// { +// task.Status = ImportStatus.Skipped; +// skippedCount++; +// continue; +// } + +// // 显示进度 +// float progress = (float)i / importTasks.Count; +// EditorUtility.DisplayProgressBar("批量导入", $"正在处理 {task.SceneName}...", progress); + +// // 加载SO +// var table = AssetDatabase.LoadAssetAtPath(task.SoPath); +// if (table == null) +// { +// Debug.LogError($"无法加载配置表: {task.SoPath}"); +// task.Status = ImportStatus.Failed; +// failedCount++; +// continue; +// } + +// // 获取所有Sprite +// string[] guids = AssetDatabase.FindAssets("t:Sprite", new[] { task.SpriteFolderPath }); +// if (guids.Length == 0) +// { +// task.Status = ImportStatus.Skipped; +// skippedCount++; +// continue; +// } + +// // 获取当前最大ID +// int startId = table.Items.Count > 0 ? table.Items.Max(item => item.Id) + 1 : 1; + +// // 导入Sprite +// int importedCount = 0; +// foreach (string guid in guids) +// { +// string assetPath = AssetDatabase.GUIDToAssetPath(guid); +// Sprite sprite = AssetDatabase.LoadAssetAtPath(assetPath); + +// if (sprite != null) +// { +// // 检查是否已存在同名资源 +// if (table.Items.Any(item => item.Name == sprite.name)) +// { +// Debug.LogWarning($"[{task.SceneName}] 跳过重复资源: {sprite.name}"); +// continue; +// } + +// var newItem = new ArtItemData +// { +// Id = startId + importedCount, +// Name = sprite.name, +// Desc = "", +// Sprite = sprite +// }; + +// table.Items.Add(newItem); +// importedCount++; +// } +// } + +// if (importedCount > 0) +// { +// // 保存SO +// EditorUtility.SetDirty(table); +// AssetDatabase.SaveAssets(); + +// // 同步JSON +// SyncToJson(table); + +// task.Status = ImportStatus.Success; +// successCount++; +// totalSpritesImported += importedCount; + +// Debug.Log($"[{task.SceneName}] 成功导入 {importedCount} 个sprite资源"); +// } +// else +// { +// task.Status = ImportStatus.Skipped; +// skippedCount++; +// } + +// Repaint(); +// } + +// // 更新Manifest +// UpdateManifest(); +// } +// finally +// { +// EditorUtility.ClearProgressBar(); +// isProcessing = false; +// } + +// // 显示结果 +// string message = $"批量导入完成!\n\n" + +// $"✔ 成功: {successCount} 个配置表\n" + +// $"✘ 失败: {failedCount} 个\n" + +// $"⊘ 跳过: {skippedCount} 个\n" + +// $"📦 总共导入: {totalSpritesImported} 个sprite"; + +// EditorUtility.DisplayDialog("批量导入完成", message, "确定"); +// Debug.Log($"[BatchImportSceneSprites] {message}"); + +// Repaint(); +// } + +// private void SyncToJson(ArtTableSO table) +// { +// string soPath = AssetDatabase.GetAssetPath(table); +// string relativePath = soPath.Replace(SO_ROOT_PATH, "").Replace(".asset", ".json"); +// string jsonPath = JSON_ROOT_PATH + relativePath; + +// // 确保目录存在 +// string directory = Path.GetDirectoryName(jsonPath); +// if (!Directory.Exists(directory)) +// { +// Directory.CreateDirectory(directory); +// } + +// // 创建JSON数据 +// var jsonData = new ArtTableJsonData +// { +// TableId = table.TableId, +// TableName = table.TableName, +// Items = table.Items.Select(item => new ArtItemJsonData +// { +// Id = item.Id, +// Name = item.Name, +// Desc = item.Desc, +// SpritePath = item.Sprite != null ? AssetDatabase.GetAssetPath(item.Sprite) : "", +// SpineAssetPath = item.SpineAsset != null ? AssetDatabase.GetAssetPath(item.SpineAsset) : "", +// SpineAnimName = item.SpineAnimName +// }).ToList() +// }; + +// string json = JsonUtility.ToJson(jsonData, true); +// File.WriteAllText(jsonPath, json); + +// AssetDatabase.ImportAsset(jsonPath); +// } + +// private void UpdateManifest() +// { +// try +// { +// // 查找所有ArtTableSO文件 +// string[] guids = AssetDatabase.FindAssets("t:ArtTableSO", new[] { "Assets/Art_SubModule/Art_SO" }); +// List tablePaths = new List(); + +// foreach (string guid in guids) +// { +// string path = AssetDatabase.GUIDToAssetPath(guid); +// if (!string.IsNullOrEmpty(path)) +// { +// tablePaths.Add(path); +// } +// } + +// // 排序路径 +// tablePaths.Sort(); + +// // 创建或更新manifest +// ArtTableManifest manifest; + +// // 如果文件存在,读取现有的预加载配置 +// if (File.Exists(MANIFEST_PATH)) +// { +// string existingJson = File.ReadAllText(MANIFEST_PATH); +// manifest = JsonUtility.FromJson(existingJson); + +// if (manifest == null) +// { +// manifest = new ArtTableManifest(); +// } +// if (manifest.preloadTableIds == null) +// { +// manifest.preloadTableIds = new int[0]; +// } +// } +// else +// { +// manifest = new ArtTableManifest +// { +// preloadTableIds = new int[0] +// }; +// } + +// // 更新路径列表 +// manifest.tablePaths = tablePaths.ToArray(); + +// // 序列化为JSON +// string json = JsonUtility.ToJson(manifest, true); + +// // 确保目录存在 +// string directory = Path.GetDirectoryName(MANIFEST_PATH); +// if (!Directory.Exists(directory)) +// { +// Directory.CreateDirectory(directory); +// } + +// // 写入文件 +// File.WriteAllText(MANIFEST_PATH, json); +// AssetDatabase.ImportAsset(MANIFEST_PATH); + +// Debug.Log($"[BatchImportSceneSprites] Manifest文件已更新: {MANIFEST_PATH}"); +// } +// catch (System.Exception ex) +// { +// Debug.LogError($"[BatchImportSceneSprites] 更新Manifest文件失败: {ex.Message}"); +// } +// } + +// [System.Serializable] +// public class ArtTableManifest +// { +// public string[] tablePaths; +// public int[] preloadTableIds; +// } + +// [System.Serializable] +// public class ArtTableJsonData +// { +// public int TableId; +// public string TableName; +// public List Items; +// } + +// [System.Serializable] +// public class ArtItemJsonData +// { +// public int Id; +// public string Name; +// public string Desc; +// public string SpritePath; +// public string SpineAssetPath; +// public string SpineAnimName; +// } +// } +// } diff --git a/Git工具/Unity Git管理工具.exe b/Git工具/Unity Git管理工具.exe index 8d832b6..7970604 100644 Binary files a/Git工具/Unity Git管理工具.exe and b/Git工具/Unity Git管理工具.exe differ