public static void PopupObjectHelperMenu(UnityObject o) { var path = AssetDatabase.GetAssetPath(o); var guid = AssetDatabase.AssetPathToGUID(path); var iid = o.GetInstanceID(); if (getLocalIdentifierInFile == null) { var method = typeof(Unsupported).GetMethod( "GetLocalIdentifierInFile", BindingFlags.Static | BindingFlags.Public); if (method != null) { getLocalIdentifierInFile = (Func <int, int>)Delegate.CreateDelegate(typeof(Func <int, int>), method); } if (getLocalIdentifierInFile == null) { getLocalIdentifierInFile = _ => 0; } } var localId = getLocalIdentifierInFile(iid); var info = new FileInfo(path); var name = Path.GetFileName(path); var itemPath = ToMenuItemPath(path); var menu = new GenericMenu(); menu.AddItem(new GUIContent(name + " " + info.Length.ToString("N0") + " B " + info.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")), false, null); menu.AddSeparator(""); var deps = AssetDatabase.GetDependencies(path, false); System.Array.Sort(deps); var limit = 30; foreach (var depPath in deps) { var target = AssetDatabase.LoadAssetAtPath(depPath, typeof(UnityObject)); menu.AddItem(new GUIContent("Dependencies/" + ToMenuItemPath(depPath)), false, t => PopupObjectHelperMenu(t as UnityObject), target); if (--limit < 0) { break; } } menu.AddItem(new GUIContent("Dependencies/..."), false, DependencyListWindow.Open, o); var refs = AssetDependencyDatabase.GetReferences(path); refs.Sort(); limit = 30; foreach (var refPath in refs) { var target = AssetDatabase.LoadAssetAtPath(refPath, typeof(UnityObject)); if (target == null) { continue; } menu.AddItem(new GUIContent("References/" + ToMenuItemPath(refPath)), false, t => PopupObjectHelperMenu(t as UnityObject), target); if (--limit < 0) { break; } } menu.AddItem(new GUIContent("References/..."), false, ReferenceGrepWindow.Open, o); menu.AddSeparator(""); menu.AddItem(new GUIContent("Copy " + itemPath), false, CopyToClipboard, path); menu.AddItem(new GUIContent("Copy GUID " + guid), false, CopyToClipboard, guid); menu.AddItem(new GUIContent("Copy InstanceID " + iid), false, CopyToClipboard, iid); if (localId != 0) { menu.AddItem(new GUIContent("Copy LocalID " + localId), false, CopyToClipboard, localId); } menu.AddItem(new GUIContent("Open In Finder"), false, OpenInFinder, path); menu.AddItem(new GUIContent("Open In Editor"), false, OpenInEditor, path); menu.AddItem(new GUIContent("Find References In Scene"), false, FindReferencesInScean, o); if (Event.current == null) { EditorGUIUtility.PingObject(o); Selection.activeObject = o; actionQueue.Enqueue(() => { menu.ShowAsContext(); }); } else { menu.ShowAsContext(); } }
void EnqueueProcess(string path, bool isRecursive, ResultCallback callback, HashSet <string> results = null) { results = results ?? new HashSet <string>(); var guid = AssetDependencyDatabase.PathToGUID(path); var crumbs = Path.GetDirectoryName(path).Split(new[] { '/', '\\' }); var sb = new StringBuilder(); var dirs = new List <string>(); for (var n = crumbs.Length; n > 0; --n) { sb.Length = 0; for (var j = 0; j < n; ++j) { if (j > 0) { sb.Append('/'); } sb.Append(crumbs[j]); } dirs.Add(sb.ToString()); } dirs.Add("ProjectSettings"); ReferenceSearchEngineProcess process = null; for (var i = 0; i < dirs.Count; ++i) { var dir = dirs[i]; var ignore = i > 0 ? dirs[i - 1] + "/" : null; if (dir == "ProjectSettings") { ignore = null; } var merged = false; foreach (var q in processQueue) { if (q.SearchDirectory == dir && q.IgnoreDirectory == ignore) { q.TargetPaths.Add(path); q.TargetGUIDs.Add(guid); merged = true; process = q; break; } } if (!merged) { process = new ReferenceSearchEngineProcess() { Argument = string.Format("--json {0} ", commonIgnorePatterns), SearchDirectory = Prefix + dir, IgnoreDirectory = ignore == null ? null : Prefix + ignore, TargetPaths = new List <string>() { path }, TargetGUIDs = new List <string>() { guid }, Callback = callback, IsRecursive = isRecursive, Results = results, Reporter = this, }; processQueue.Add(process); } } var refPaths = AssetDependencyDatabase.GetReferences(path); if (refPaths == null) { return; } foreach (var refPath in refPaths) { lock (results) { if (results.Contains(refPath)) { continue; } results.Add(refPath); } FoundReference(process, refPath, path); } }