예제 #1
0
        public static void OnModelInitializationHandler(UnityModelAndLifetime modelAndLifetime)
        {
            ourLogger.Verbose("AdviseUnitTestLaunch");
            var modelValue         = modelAndLifetime.Model;
            var connectionLifetime = modelAndLifetime.Lifetime;

            modelValue.GetCompilationResult.Set(_ => !EditorUtility.scriptCompilationFailed);

#if !UNITY_5_6 // before 5.6 this file is not included at all
            CompiledAssembliesTracker.Init(modelAndLifetime);
#endif

            modelValue.UnitTestLaunch.Advise(connectionLifetime, launch =>
            {
                new TestEventsSender(launch);
            });

            modelValue.RunUnitTestLaunch.Set(rdVoid =>
            {
                if (!modelValue.UnitTestLaunch.HasValue())
                {
                    return(false);
                }
                var testLauncher = new UnityEditorTestLauncher(modelValue.UnitTestLaunch.Value, connectionLifetime);
                return(testLauncher.TryLaunchUnitTests());
            });
        }
예제 #2
0
        private static void OnModelInitializationHandler(UnityModelAndLifetime modelAndLifetime)
        {
            ourLogger.Verbose("AdviseUnitTestLaunch");
            var modelValue         = modelAndLifetime.Model;
            var connectionLifetime = modelAndLifetime.Lifetime;

            modelValue.GetCompilationResult.Set(_ => !EditorUtility.scriptCompilationFailed);

            modelValue.UnitTestLaunch.Advise(connectionLifetime, launch =>
            {
                var collector = TestEventsCollector.Instance;
                ourLogger.Verbose("TestEventsCollectorInstance: " + collector.GetInstanceID() + " DelayedEvents.Count:" + collector.DelayedEvents.Count);
                new TestEventsSender(collector, launch);
            });

            modelValue.RunUnitTestLaunch.Advise(connectionLifetime, () =>
            {
                if (!modelValue.UnitTestLaunch.HasValue())
                {
                    return;
                }

                var testLauncher = new UnityEditorTestLauncher(modelValue.UnitTestLaunch.Value);
                testLauncher.TryLaunchUnitTests();
            });
        }
예제 #3
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);
                    });
                }
            });
        }
예제 #4
0
        public static void AdviseUnitTestLaunch(UnityModelAndLifetime modelAndLifetime)
        {
            var modelValue         = modelAndLifetime.Model;
            var connectionLifetime = modelAndLifetime.Lifetime;

            modelValue.UnitTestLaunch.Change.Advise(connectionLifetime, launch =>
            {
                var unityEditorTestLauncher = new UnityEditorTestLauncher(launch);
                unityEditorTestLauncher.TryLaunchUnitTests();
            });
        }
예제 #5
0
 private static void GetUnsavedChangesInScenes(UnityModelAndLifetime modelAndLifetime)
 {
     modelAndLifetime.Model.HasUnsavedScenes.Set(rdVoid =>
     {
         var count = SceneManager.sceneCount;
         for (var i = 0; i < count; i++)
         {
             if (SceneManager.GetSceneAt(i).isDirty)
             {
                 return(true);
             }
         }
         return(false);
     });
 }
        public static void Init(UnityModelAndLifetime modelAndLifetime)
        {
            ourModel = modelAndLifetime.Model;

            void OnCompilationFinished(string assemblyPath, CompilerMessage[] messages)
            {
                if (!ourCompiledAssemblyPaths.Contains(assemblyPath))
                {
                    UpdateAssemblies();
                }
            }

            modelAndLifetime.Lifetime.Bracket(
                () => CompilationPipeline.assemblyCompilationFinished += OnCompilationFinished,
                () => CompilationPipeline.assemblyCompilationFinished -= OnCompilationFinished);

            UpdateAssemblies();
        }
예제 #7
0
        public static void OnModelInitializationHandler(UnityModelAndLifetime modelAndLifetime)
        {
            ourLogger.Verbose("AdviseUnitTestLaunch");
            var modelValue         = modelAndLifetime.Model;
            var connectionLifetime = modelAndLifetime.Lifetime;

            modelValue.GetCompilationResult.Set(_ => !EditorUtility.scriptCompilationFailed);

            modelValue.UnitTestLaunch.Advise(connectionLifetime, launch =>
            {
                new TestEventsSender(launch);
            });

            modelValue.RunUnitTestLaunch.Advise(connectionLifetime, () =>
            {
                if (!modelValue.UnitTestLaunch.HasValue())
                {
                    return;
                }
                var testLauncher = new UnityEditorTestLauncher(modelValue.UnitTestLaunch.Value);
                testLauncher.TryLaunchUnitTests();
            });
        }
예제 #8
0
        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);
                    });
                }
            });
        }