Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        void OnGUI()
        {
            OnKeyEvent();
            var e = Event.current;

            EditorGUIUtility.labelWidth = 100f;

            if (Target == null && !string.IsNullOrEmpty(guid) && guid.Length == 32)
            {
                var assetPath = AssetDatabase.GUIDToAssetPath(guid);
                if (!string.IsNullOrEmpty(assetPath))
                {
                    Target     = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityObject));
                    targetPath = assetPath;
                }
            }
            Target = EditorGUILayout.ObjectField(Target, typeof(UnityObject), false);
            if (Target != null && AssetMenu.IsMouseDownInLastRect())
            {
                AssetMenu.PopupObjectHelperMenu(Target);
            }
            if (Target == null)
            {
                targetPath = null;
            }
            else
            {
                targetPath = AssetDatabase.GetAssetPath(Target);
                guid       = AssetDatabase.AssetPathToGUID(targetPath);
            }
            var newGUID = EditorGUILayout.TextField("GUID", guid ?? "");

            if (newGUID != guid)
            {
                guid       = newGUID;
                Target     = null;
                targetPath = null;
            }
            EditorGUILayout.TextField("Path", targetPath ?? "");

            if (Target != null && Target != beforeTarget)
            {
                beforeTarget = Target;
                objectList.Clear();
                engine.Start(targetPath, isRecursive, AddObjectList);
            }

            EditorGUILayout.BeginHorizontal();
            if (!engine.IsInitialized)
            {
                EditorGUILayout.LabelField("initialize ...");
            }
            else
            {
                EditorGUILayout.LabelField(string.Format("references: {0} {1}", objectList.Count, engine.IsSearching ? "..." : ""));
            }
            if (AssetDependencyDatabase.IsFullScanRunning())
            {
                EditorGUILayout.LabelField(string.Format("scan: {0}", AssetDependencyDatabase.GetScanQueueCount()));
            }
            else
            {
                EditorGUILayout.LabelField("");
            }
            EditorGUILayout.EndHorizontal();

            objectList.Draw();

            AssetMenu.DequeueContextAction();
        }
Beispiel #3
0
        void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.EndHorizontal();

            SplitterGUILayoutBridge.BeginVerticalSplit(splitter);
            EditorGUILayout.BeginVertical();
            targetScroll = GUILayout.BeginScrollView(targetScroll);

            // var focused = EditorGUILayout.TextField("focus", GUI.GetNameOfFocusedControl());
            var focused = GUI.GetNameOfFocusedControl();

            if (string.IsNullOrEmpty(focused))
            {
                focusedRefs = null;
                focusedDeps = null;
            }
            else
            {
                var chunks = focused.Split(',');
                if (chunks.Length == 2)
                {
                    focusedObjectPath = chunks[1];
                    if (chunks[0] == "Result")
                    {
                        focusedRefs = GetOrNull(references, focusedObjectPath);
                        focusedDeps = GetOrNull(dependencies, focusedObjectPath);
                    }
                    else if (chunks[0] == "Target")
                    {
                        focusedDeps = GetOrNull(dependencies, focusedObjectPath);
                    }
                }
            }

            Targets = Targets ?? new List <UnityObject>();
            if (Targets.Count == 0)
            {
                Targets.Add(null);
            }
            targetList.Clear();
            targetList.AddRange(Targets.Select(AssetDatabase.GetAssetPath));
            var backgroundColor = GUI.backgroundColor;

            targetList.Draw();

            if (isAutoSelect)
            {
                if (Selection.objects != null && Selection.objects.Length > 0 && !Selection.objects.SequenceEqual(Targets))
                {
                    var o = Selection.objects[0];
                    if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(o)))
                    {
                        Targets = Selection.objects.ToList();
                    }
                }
            }

            if (Targets[0] == null)
            {
                guid = null;
            }
            EditorGUILayout.TextField("GUIDs", guid ?? "");

            if (Targets[0] != null && (prevTargets == null || !Targets.SequenceEqual(prevTargets)))
            {
                prevTargets = Targets;
                ListDependencies(Targets);
            }

            GUILayout.EndScrollView();
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
            EditorGUILayout.LabelField(string.Format("dependencies: {0}", objectList.Count));

            objectList.Draw();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("SelectAll"))
            {
                SelectAll();
            }
            if (GUILayout.Button("DeselectAll"))
            {
                DeselectAll();
            }
            if (GUILayout.Button("History"))
            {
                ShowHistory();
            }
            if (GUILayout.Button("DuplicateDeps"))
            {
                Duplicate();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
            SplitterGUILayoutBridge.EndVerticalSplit();

            var ev = Event.current;

            if (ev.type == EventType.KeyDown)
            {
                OnKeyDown(ev.keyCode);
            }
        }