void OnEnable() { titleContent.text = "Dependencies"; targetList = new ScrollableObjectList(false); targetList.OnPreDraw = OnObjectListItemPreDraw; objectList = new ScrollableObjectList(); objectList.OnPreDraw = OnObjectListItemPreDraw; objectList.OnPostDraw = OnObjectListItemPostDraw; objectList.OnAssetDrop = OnObjectListAssetDrop; Targets = null; prevTargets = null; isAutoSelect = EditorPrefs.GetBool("AssetDependencyTool.DependencyListWindow.isAutoSelect", isAutoSelect); isRecursive = EditorPrefs.GetBool("AssetDependencyTool.DependencyListWindow.isRecursive", isRecursive); isShowDirectory = EditorPrefs.GetBool("AssetDependencyTool.DependencyListWindow.isShowDirectory", isShowDirectory); sortType = (SortType)EditorPrefs.GetInt("AssetDependencyTool.DependencyListWindow.sortType", (int)sortType); history = HistoryJson.Read(); splitter = new SplitterState( new float[] { 20f, 80f }, new int[] { 30, 100 }, null ); targetScroll = Vector2.zero; }
void ListDependencies(List <UnityObject> targets) { objectList = objectList ?? new ScrollableObjectList(); objectList.Clear(); checks.Clear(); if (targets.Count == 1) { var target = targets.First(); var targetPath = AssetDatabase.GetAssetPath(target.GetInstanceID()); // instanceID = target.GetInstanceID(); // fileID = GetFileID(target); if (string.IsNullOrEmpty(targetPath)) { return; } history.Remove(target); history.Add(target); if (history.Count > 50) { history.RemoveAt(0); } HistoryJson.Write(history); } guid = string.Join(",", Targets.Select(t => AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(t.GetInstanceID()))).ToArray()); var targetPaths = new List <string>(); var deps = new List <string>(); foreach (var o in targets) { var path = AssetDatabase.GetAssetPath(o); if (string.IsNullOrEmpty(path)) { continue; } targetPaths.Add(path); var assets = AssetDatabase.GetDependencies(path, isRecursive); deps.AddRange(assets.Select(AssetDatabase.AssetPathToGUID)); } deps = deps.Distinct() .Select(AssetDatabase.GUIDToAssetPath) .Where(path => !targetPaths.Contains(path)).ToList(); if (sortType == SortType.Extension) { deps = deps.OrderBy(x => Path.GetExtension(x)).ThenBy(x => Path.GetFileName(x)).ToList(); } else if (sortType == SortType.FileName) { deps = deps.OrderBy(x => Path.GetFileName(x)).ThenBy(x => Path.GetExtension(x)).ToList(); } else if (sortType == SortType.FilePath) { deps = deps.OrderBy(x => x).ToList(); } foreach (var dep in deps) { var ext = Path.GetExtension(dep); objectList.Add(dep); checks[dep] = ext != ".cs" && ext != ".shader"; } var all = targetPaths.Concat(deps).ToArray(); references.Clear(); dependencies.Clear(); foreach (var path in all) { dependencies.Add(path, AssetDatabase.GetDependencies(path, true).ToList()); references.Add(path, new List <string>()); } foreach (var pair in dependencies) { foreach (var path in pair.Value) { references[path].Add(pair.Key); } } }