示例#1
0
        public static void OnModelInitializationHandler(UnityModelAndLifetime modelAndLifetime)
        {
            var modelValue         = modelAndLifetime.Model;
            var connectionLifetime = modelAndLifetime.Lifetime;

            modelValue.ShowGameObjectOnScene.Advise(connectionLifetime, findUsagesResult =>
            {
                if (findUsagesResult != null)
                {
                    MainThreadDispatcher.Instance.Queue(() =>
                    {
                        ExpandMinimizedUnityWindow();

                        EditorUtility.FocusProjectWindow();

                        if (findUsagesResult.IsPrefab)
                        {
                            ShowUtil.ShowFileUsage(findUsagesResult.FilePath);
                        }
                        else
                        {
                            ShowUtil.ShowUsageOnScene(findUsagesResult.FilePath, findUsagesResult.FileName, findUsagesResult.PathElements, findUsagesResult.RootIndices);
                        }
                    });
                }
            });

            modelValue.FindUsageResults.Advise(connectionLifetime, result =>
            {
                if (result != null)
                {
                    MainThreadDispatcher.Instance.Queue(() =>
                    {
                        GUI.BringWindowToFront(EditorWindow.GetWindow <SceneView>().GetInstanceID());
                        GUI.BringWindowToFront(EditorWindow.GetWindow(typeof(SceneView).Assembly.GetType("UnityEditor.SceneHierarchyWindow")).GetInstanceID());
                        GUI.BringWindowToFront(EditorWindow.GetWindow(typeof(SceneView).Assembly.GetType("UnityEditor.ProjectBrowser")).GetInstanceID());

                        var window = FindUsagesWindow.GetWindow(result.Target);
                        window.SetDataToEditor(result.Elements);
                    });
                }
            });

            modelValue.ShowFileInUnity.Advise(connectionLifetime, result =>
            {
                if (result != null)
                {
                    MainThreadDispatcher.Instance.Queue(() =>
                    {
                        EditorUtility.FocusProjectWindow();
                        ShowUtil.ShowFileUsage(result);
                    });
                }
            });
        }
        public static void OnModelInitializationHandler(UnityModelAndLifetime modelAndLifetime)
        {
            var modelValue         = modelAndLifetime.Model;
            var connectionLifetime = modelAndLifetime.Lifetime;

            modelValue.ShowUsagesInUnity.Advise(connectionLifetime, findUsagesResult =>
            {
                if (findUsagesResult != null)
                {
                    MainThreadDispatcher.Instance.Queue(() =>
                    {
                        ExpandMinimizedUnityWindow();

                        EditorUtility.FocusProjectWindow();
                        switch (findUsagesResult)
                        {
                        case AnimatorFindUsagesResult animatorUsage:
                            ShowUtil.ShowAnimatorUsage(animatorUsage.PathElements, animatorUsage.FilePath);
                            return;

                        case HierarchyFindUsagesResult _ when findUsagesResult.Extension.Equals(".prefab", StringComparison.OrdinalIgnoreCase):
                            ShowUtil.ShowFileUsage(findUsagesResult.FilePath);
                            break;

                        case HierarchyFindUsagesResult hierarchyFindUsagesResult:
                            ShowUtil.ShowUsageOnScene(findUsagesResult.FilePath, findUsagesResult.FileName, hierarchyFindUsagesResult.PathElements, hierarchyFindUsagesResult.RootIndices);
                            break;

                        case AnimationFindUsagesResult animationEventUsage:
                            ShowUtil.ShowAnimationEventUsage(animationEventUsage.FilePath);
                            break;

                        default:
                            ShowUtil.ShowFileUsage(findUsagesResult.FilePath);
                            break;
                        }
                    });
                }
            });

            modelValue.SendFindUsagesSessionResult.Advise(connectionLifetime, result =>
            {
                if (result != null)
                {
                    MainThreadDispatcher.Instance.Queue(() =>
                    {
                        GUI.BringWindowToFront(EditorWindow.GetWindow <SceneView>().GetInstanceID());
                        GUI.BringWindowToFront(EditorWindow.GetWindow(typeof(SceneView).Assembly.GetType("UnityEditor.SceneHierarchyWindow")).GetInstanceID());
                        GUI.BringWindowToFront(EditorWindow.GetWindow(typeof(SceneView).Assembly.GetType("UnityEditor.ProjectBrowser")).GetInstanceID());

                        var window = FindUsagesWindow.GetWindow(result.Target);
                        window.SetDataToEditor(result.Elements);
                    });
                }
            });

            modelValue.ShowFileInUnity.Advise(connectionLifetime, result =>
            {
                if (result != null)
                {
                    MainThreadDispatcher.Instance.Queue(() =>
                    {
                        ExpandMinimizedUnityWindow();
                        EditorUtility.FocusProjectWindow();
                        ShowUtil.ShowFileUsage(result);
                    });
                }
            });
        }