public void ParseList() { var parser = new PrefabParser(); foreach (var go in _prefabs) { if (go != null) { var path = AssetDatabase.GetAssetPath(go); parser.Load(path); var monos = parser.GetMonoBehaviourNodes(); foreach (var item in monos) { var asset = AssetUtils.GetAssetFromId(item.ScriptFileID, item.ScriptGUID); if (asset == null) { continue; } _db.AddOrUpdate(new ScriptIDDatabase.ScriptID() { Name = AssetUtils.GetScriptName(asset), FileID = item.ScriptFileID, GUID = item.ScriptGUID }); } } } }
public void AnalyzePrefabs() { MissingList.Clear(); FixList.Clear(); NofixList.Clear(); var parser = new PrefabParser(); foreach (var go in _prefabs) { if (go != null) { var path = AssetDatabase.GetAssetPath(go); parser.Load(path); var monos = parser.GetMonoBehaviourNodes(); foreach (var item in monos) { var asset = AssetUtils.GetAssetFromId(item.ScriptFileID, item.ScriptGUID); if (asset == null) // missing { if (MissingList.Find(n => { return(n.FileID == item.ScriptFileID && n.GUID == item.ScriptGUID); }) == null) { MissingList.Add(new ScriptID() { FileID = item.ScriptFileID, GUID = item.ScriptGUID }); } } } } } // 从参考数据库查询missing id的名字 foreach (var item in MissingList) { var r = _refDb.Search(item.FileID, item.GUID); if (r != null) { item.Name = r.Name; } } // 通过名字在项目中寻找其正确id foreach (var item in MissingList) { string fileID = null; string guid = null; Object _ = null; if (AssetUtils.TrySearchClass(item.Name, ref fileID, ref guid, ref _)) { FixList.Add(new ScriptID() { Name = item.Name, FileID = fileID, GUID = guid }); } else { NofixList.Add(item); } } // log var sb = new StringBuilder(100); sb.AppendLine("分析结果如下:"); sb.AppendLine("--------"); sb.AppendLine($"丢失{MissingList.Count}:"); foreach (var item in MissingList) { sb.AppendLine($"类名:{item.Name},fileID:{item.FileID},guid:{item.GUID}"); } sb.AppendLine("--------"); sb.AppendLine($"可修复{FixList.Count}:"); foreach (var item in FixList) { sb.AppendLine($"类名:{item.Name},fileID:{item.FileID},guid:{item.GUID}"); } sb.AppendLine("--------"); sb.AppendLine($"不可修复{NofixList.Count}:"); foreach (var item in NofixList) { sb.AppendLine($"类名:{item.Name},fileID:{item.FileID},guid:{item.GUID}"); } sb.AppendLine("--------"); Debug.Log(sb.ToString()); }