private void DrawDepInfo(List <DepencyInfo> infoList) { for (int i = 0; i < infoList.Count; i++) { DepencyInfo dep = infoList[i]; Object depObj = AssetDatabase.LoadMainAssetAtPath(dep.path); if (depObj == null) { continue; } GUILayout.BeginHorizontal(); { GUILayout.Label(depObj.name); GUILayout.Label(dep.path); if (GUILayout.Button("选择", GUILayout.Width(70))) { EditorGUIUtility.PingObject(depObj); } if (GUILayout.Button("查看依赖", GUILayout.Width(70))) { showInfoStack.Push(dep); } } GUILayout.EndHorizontal(); } }
void Analyse() { if (File.Exists(savePath)) { infoDic = LitJson.JsonMapper.ToObject <Dictionary <string, DepencyInfo> >(File.ReadAllText(savePath)); DepHandler(); } else { infoDic = new Dictionary <string, DepencyInfo>(); string[] path = AssetDatabase.GetAllAssetPaths(); for (int i = 0; i < path.Length; i++) { infoDic[path[i]] = new DepencyInfo() { path = path[i] }; EditorUtility.DisplayProgressBar("采集Asset信息", path[i], (float)i / (float)path.Length); } int count = infoDic.Count; int n = 0; foreach (var info in infoDic.Values) { string[] deps = AssetDatabase.GetDependencies(info.path); for (int i = 0; i < deps.Length; i++) { DepencyInfo depInfo; if (infoDic.TryGetValue(deps[i], out depInfo)) { depInfo.depList.Add(info.path); info.refList.Add(depInfo.path); } else { Debug.Log("no dep info " + deps[i]); } } n++; EditorUtility.DisplayProgressBar("收集依赖信息", info.path, (float)n / (float)count); } EditorUtility.ClearProgressBar(); if (autoCache) { string json = LitJson.JsonMapper.ToJson(infoDic); File.WriteAllText(savePath, json); } DepHandler(); } }