/// <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> /// 修复所有的关联关系 /// </summary> public void FixedDirty() { foreach (var i in data.GetDic()) { if (i.Value.isdirty) { if (File.Exists(i.Key)) { i.Value.dependencies = BuildUtils.ExceptScriptAndDll(BuildUtils.GetDependencies(i.Key)); i.Value.isdirty = false; } else { Debug.Log(i.Key + " is delete!"); } } } EditorUtility.SetDirty(this); }
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); }