/// <summary> /// 构建资源关系图 /// </summary> public static void BuildAssetDependenctGraph() { var asset = BuildUtils.BuildAndSave(); var dic = new Dictionary <string, string[]>(); if (asset != null) { Debug.Log("This way can fast analysis resources relationship."); using (new ExecuteTimer("Compute cache file dependencies")) { var resourceDependenct = asset.data.GetDic(); var res = resourceDependenct.GetEnumerator(); while (res.MoveNext()) { dic.Add(res.Current.Key, res.Current.Value.dependencies); } } } else { Debug.Log("This way need some time analysis resources relationship."); string rpath = "Assets/Resources/"; using (new ExecuteTimer("Compute which file that need analysis")) { //var searchPattern = AssetFileType.GetSearchPattern(); //var filePaths = searchPattern.SelectMany(i => Directory.GetFiles(rpath, i, SearchOption.AllDirectories)).Distinct().ToArray(); //prefabfiles = filePaths; prefabfiles = AssetsDependenctGenerateEditor.GetAllFile(); } using (new ExecuteTimer("Compute Resource dependencies.")) { for (int i = 0; i < prefabfiles.Length; i++) { var assetPath = prefabfiles[i] = BuildUtils.GetUnityPath(prefabfiles[i]); var assetsDependencies = BuildUtils.GetDependencies(assetPath); assetsDependencies = BuildUtils.ExceptScriptAndDll(assetsDependencies); dic.Add(assetPath, assetsDependencies); } } } using (new ExecuteTimer("Compute Resouce Relationship" + dic.Count)) { //根据当前的资源引用关系数据,刷新构建图形数据结构 resourceGraph = new AssetDependenctGraph(dic); state = AssetDependenctTreeBuildState.NodeGraph; } }
/// <summary> /// 画依赖的GUI /// </summary> private void DrawDependencyGUI() { if (resourceGraph.result.Count > 0) { EditorGUILayout.BeginHorizontal(); currentSelection = EditorGUILayout.ObjectField(currentSelection, typeof(Object), false); EditorGUILayout.EndHorizontal(); if (currentSelection) { var currentSelectionPath = AssetDatabase.GetAssetPath(currentSelection); currentSelectionPath = BuildUtils.GetUnityPath(currentSelectionPath); if (currentSelectionPath.Contains("Resources")) { AssetDependenctGraph.Node graph; if (resourceGraph.result.TryGetValue(currentSelectionPath, out graph)) { EditorGUILayout.BeginHorizontal(); var maxHeight = newGraph != null ? newGraph.maxHeight : 5000; scrollValue = GUI.BeginScrollView(new Rect(0, 20, position.width, position.height), scrollValue, new Rect(0, 0, position.width, maxHeight), true, true); BeginWindows(); if (graph.Parents != null) { if (newGraph == null || newGraph.tree != graph) { newGraph = new AssetNodeGraph(resourceGraph.result, graph); } newGraph.Draw(); } EndWindows(); GUI.EndScrollView(); EditorGUILayout.EndHorizontal(); } } } } }
public void Update() { for (int fast = 0; fast < 10; fast++) { if (isPermission && files != null) { if (index < files.Length) { var assetPath = BuildUtils.GetUnityPath(files[index]); var denpendenctList = new DependenctList(); denpendenctList.dependencies = BuildUtils.ExceptScriptAndDll(BuildUtils.GetDependencies(assetPath)); denpendenctList.isdirty = false; data.data.Add(assetPath, denpendenctList); EditorUtility.DisplayProgressBar("正在生成资源依赖图", "进度:" + (index / (float)files.Length) * 100 + "%", ++index / (float)files.Length); } else { Debug.Log(data.data.Count + "HashCode:::" + data.data.GetHashCode()); isPermission = false; EditorUtility.ClearProgressBar(); BuildUtils.RemoveAsset(EditorGenerate); BuildUtils.SaveAsset(data, EditorGenerate); EditorPrefs.SetBool(ResourceDirty, true); data = null; } } } }
/// <summary> /// 获取当前所有的资源引用数据 /// </summary> /// <returns></returns> static AssetsDependenctData GetAssetDependenctData() { var allFile = GetAllFile(); AssetsDependenctData data = ScriptableObject.CreateInstance <AssetsDependenctData>(); data.data = new AssetsDependenct(); for (int i = 0; i < allFile.Length; i++) { var assetPath = BuildUtils.GetUnityPath(allFile[i]); var list = new DependenctList(); list.dependencies = BuildUtils.ExceptScriptAndDll(BuildUtils.GetDependencies(assetPath)); list.isdirty = false; data.data.Add(assetPath, list); } return(data); }