void OnObjectListItemPreDraw(ScrollableObjectList list, string path) { if (list == targetList) { GUI.SetNextControlName("Target," + path); } else { var check = checks.ContainsKey(path) && checks[path]; checks[path] = EditorGUILayout.ToggleLeft("", check, GUILayout.Width(15)); GUI.SetNextControlName("Result," + path); } if (path == focusedObjectPath) { list.SetBackgroundColor(new Color(0.8f, 1f, 0.7f)); } else if (focusedRefs != null && focusedRefs.Contains(path)) { list.SetBackgroundColor(new Color(1f, 0.8f, 0.5f)); } else if (focusedDeps != null && focusedDeps.Contains(path)) { list.SetBackgroundColor(new Color(0.5f, 0.8f, 1f)); } }
void OnPostDrawResultItem(ScrollableObjectList list, string path) { if (AssetMenu.IsMouseDownInLastRect()) { var o = AssetDatabase.LoadAssetAtPath(path, typeof(UnityObject)); AssetMenu.PopupObjectHelperMenu(o); } }
void OnEnable() { titleContent.text = "References"; objectList = new ScrollableObjectList(); objectList.OnPostDraw = OnPostDrawResultItem; beforeTarget = null; if (engine != null) { engine.Cancel(); } var root = Path.GetFullPath(Application.dataPath + "/.."); engine = new ReferenceSearchEngine(root); ReferenceSearchEngine.Tracer = s => Debug.Log(s); AssetDependencyDatabase.Trace = s => Debug.Log(s); AssetDependencyDatabase.StartFullScanWorker(); }
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 OnObjectListItemPostDraw(ScrollableObjectList list, string path) { if (targetList.Count == 1) { EditorGUILayout.LabelField("", GUILayout.Width(1)); } else { var paths = GetOrNull(references, path); var count = paths == null ? 0 : paths.Count(targetList.Contains); EditorGUILayout.LabelField(count.ToString(), GUILayout.Width(15)); } if (!isShowDirectory) { return; } var i = path.IndexOf("Resources/"); if (i > -1) { path = path.Substring(i + "Resources/".Length); } EditorGUILayout.TextField(Path.GetDirectoryName(path)); }
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); } } }