コード例 #1
0
        public IEnumerator TestGetViewsAndRects_ForSerializedPropertyInInspector()
        {
            var testObject = new GameObject("TestGetViewsAndRects_ForSerializedPropertiesInInspector");

            Selection.activeObject = testObject;
            try
            {
                EditorWindow.GetWindow <InspectorWindow>();
                yield return(null);

                var unmaskedViews = new[] {
                    UnmaskedView.CreateInstanceForEditorWindow <InspectorWindow>(
                        new[] {
                        new GUIControlSelector()
                        {
                            selectorMode = GUIControlSelector.Mode.Property, targetType = typeof(Transform), propertyPath = "m_LocalPosition"
                        }
                    }
                        )
                };
                var viewsAndRects = UnmaskedView.GetViewsAndRects(unmaskedViews).m_MaskData;
                Assert.AreEqual(1, viewsAndRects.Count, "Did not find one view for the Inspector");
                var rects = viewsAndRects.Values.First().rects;
                Assert.AreEqual(1, rects.Count, "Did not find exactly one control for the SerializedProperty m_LocalPosition for a Transform");
            }
            finally
            {
                GameObject.DestroyImmediate(testObject);
            }
        }
コード例 #2
0
        public IEnumerator TestGetViewsAndRects_ForSerializedPropertyInInspector_WhenSamePathExistsOnMultipleComponents()
        {
            var testObject = new GameObject("TestGetViewsAndRects_ForSerializedPropertiesInInspector", typeof(Light), typeof(SpriteRenderer));

            Selection.activeObject = testObject;
            try
            {
                Assert.IsNotNull(new SerializedObject(testObject.GetComponent <Light>()).FindProperty("m_Color"));
                Assert.IsNotNull(new SerializedObject(testObject.GetComponent <SpriteRenderer>()).FindProperty("m_Color"));

                EditorWindow.GetWindow <InspectorWindow>();
                yield return(null);

                var unmaskedViews = new[] {
                    UnmaskedView.CreateInstanceForEditorWindow <InspectorWindow>(
                        new[] {
                        new GUIControlSelector()
                        {
                            selectorMode = GUIControlSelector.Mode.Property, targetType = typeof(SpriteRenderer), propertyPath = "m_Color"
                        }
                    }
                        )
                };
                var viewsAndRects = UnmaskedView.GetViewsAndRects(unmaskedViews).m_MaskData;
                Assert.AreEqual(1, viewsAndRects.Count, "Did not find one view for the Inspector");
                var rects = viewsAndRects.Values.First().rects;
                Assert.AreEqual(1, rects.Count, "Did not find exactly one control for the SerializedProperty m_Color for a SpriteRenderer");
            }
            finally
            {
                GameObject.DestroyImmediate(testObject);
            }
        }
コード例 #3
0
        public void ApplyHighlighting_ToTutorialWindow_WhenAllTasksAreComplete()
        {
            firstPage.m_Paragraphs[0].maskingSettings.SetUnmaskedViews(new[] { UnmaskedView.CreateInstanceForGUIView <Toolbar>() });
            firstPage.m_Paragraphs[0].maskingSettings.enabled = true;
            firstPage.RaiseTutorialPageMaskingSettingsChangedEvent();

            firstPageCriterion.Complete(true);

            m_Window.RepaintImmediately();

            List <GUIView> views = new List <GUIView>();

            GUIViewDebuggerHelper.GetViews(views);

            // only the tutorial window should be highlighted
            var rects = new List <Rect>();

            foreach (var view in views)
            {
                if (view == m_Window.m_Parent)
                {
                    Assert.IsTrue(MaskingManager.IsHighlighted(new GUIViewProxy(view), rects));
                }
                else
                {
                    Assert.IsFalse(MaskingManager.IsHighlighted(new GUIViewProxy(view), rects));
                }
            }
        }
コード例 #4
0
        public void ApplyHighlighting_ToAllUnmaskedWindowsAndViews_WhenMaskingSettingsOnlySpecifyEntireWindowsAndViews()
        {
            firstPage.m_Paragraphs[0].maskingSettings.SetUnmaskedViews(
                new[]
            {
                UnmaskedView.CreateInstanceForGUIView <Toolbar>(),
                UnmaskedView.CreateInstanceForGUIView <AppStatusBar>()
            }
                );
            firstPage.m_Paragraphs[0].maskingSettings.enabled = true;
            firstPage.RaiseTutorialPageMaskingSettingsChangedEvent();

            m_Window.RepaintImmediately();

            List <GUIView> views = new List <GUIView>();

            GUIViewDebuggerHelper.GetViews(views);

            // both the toolbar and status bar should be highlighted
            var rects = new List <Rect>();

            foreach (var view in views)
            {
                if (view == Toolbar.get || view is AppStatusBar)
                {
                    Assert.IsTrue(MaskingManager.IsHighlighted(new GUIViewProxy(view), rects));
                }
                else
                {
                    Assert.IsFalse(MaskingManager.IsHighlighted(new GUIViewProxy(view), rects));
                }
            }
        }
コード例 #5
0
        public void ApplyMasking_WhenPageIsActivated()
        {
            firstPage.m_Paragraphs[0].maskingSettings.SetUnmaskedViews(new[] { UnmaskedView.CreateInstanceForGUIView <Toolbar>() });
            firstPage.m_Paragraphs[0].maskingSettings.enabled = true;
            firstPage.RaiseTutorialPageMaskingSettingsChangedEvent();
            //m_Window.RepaintImmediately(); TODO disabled, was causing problems after adding localisation support

            List <GUIView> views = new List <GUIView>();

            GUIViewDebuggerHelper.GetViews(views);

            // the tutorial window and the specified unmasked view should both be unmasked
            var rects = new List <Rect>();

            foreach (var view in views)
            {
                if (view == m_Window.m_Parent || view == Toolbar.get || view is TooltipView)
                {
                    Assert.IsFalse(MaskingManager.IsMasked(new GUIViewProxy(view), rects));
                }
                else
                {
                    Assert.IsTrue(MaskingManager.IsMasked(new GUIViewProxy(view), rects));
                }
            }
        }
コード例 #6
0
        public void ApplyHighlighting_ToUnmaskedViews_WhenPageOnlyContainsNarrativeParagraphs()
        {
            firstPage.m_Paragraphs[0].m_Type = ParagraphType.Narrative;
            firstPage.m_Paragraphs[0].maskingSettings.SetUnmaskedViews(new[] { UnmaskedView.CreateInstanceForGUIView <Toolbar>() });
            firstPage.m_Paragraphs[0].maskingSettings.enabled = true;
            firstPage.RaiseTutorialPageMaskingSettingsChangedEvent();

            List <GUIView> views = new List <GUIView>();

            GUIViewDebuggerHelper.GetViews(views);

            // only the specified unmasked view should be highlighted
            var rects = new List <Rect>();

            foreach (var view in views)
            {
                if (view == Toolbar.get)
                {
                    Assert.IsTrue(MaskingManager.IsHighlighted(new GUIViewProxy(view), rects));
                }
                else
                {
                    Assert.IsFalse(MaskingManager.IsHighlighted(new GUIViewProxy(view), rects));
                }
            }
        }
コード例 #7
0
        public void TestGetViewsAndRects_ForNamedControlsInToolbar()
        {
            var unmaskedViews = new[]
            {
                UnmaskedView.CreateInstanceForGUIView <Toolbar>(
                    new[]
                {
                    new GUIControlSelector()
                    {
                        selectorMode = GUIControlSelector.Mode.NamedControl, controlName = "ToolbarPersistentToolsPan"
                    },
                    new GUIControlSelector()
                    {
                        selectorMode = GUIControlSelector.Mode.NamedControl, controlName = "ToolbarPersistentToolsTranslate"
                    },
                    new GUIControlSelector()
                    {
                        selectorMode = GUIControlSelector.Mode.NamedControl, controlName = "ToolbarPersistentToolsRotate"
                    },
                    new GUIControlSelector()
                    {
                        selectorMode = GUIControlSelector.Mode.NamedControl, controlName = "ToolbarPersistentToolsScale"
                    },
                    new GUIControlSelector()
                    {
                        selectorMode = GUIControlSelector.Mode.NamedControl, controlName = "ToolbarPersistentToolsRect"
                    },
                    new GUIControlSelector()
                    {
                        selectorMode = GUIControlSelector.Mode.NamedControl, controlName = "ToolbarToolPivotPositionButton"
                    },
                    new GUIControlSelector()
                    {
                        selectorMode = GUIControlSelector.Mode.NamedControl, controlName = "ToolbarToolPivotOrientationButton"
                    },
                    new GUIControlSelector()
                    {
                        selectorMode = GUIControlSelector.Mode.NamedControl, controlName = "ToolbarPlayModePlayButton"
                    },
                    new GUIControlSelector()
                    {
                        selectorMode = GUIControlSelector.Mode.NamedControl, controlName = "ToolbarPlayModePauseButton"
                    },
                    new GUIControlSelector()
                    {
                        selectorMode = GUIControlSelector.Mode.NamedControl, controlName = "ToolbarPlayModeStepButton"
                    },
                }
                    )
            };

            var viewsAndRects = UnmaskedView.GetViewsAndRects(unmaskedViews).m_MaskData;

            Assert.AreEqual(1, viewsAndRects.Count, "Did not find one view for the Toolbar");
            var rects = viewsAndRects.Values.First().rects;

            Assert.AreEqual(10, rects.Count, "Did not find all of the expected named controls in the Toolbar");
        }
コード例 #8
0
        public IEnumerator ApplyMasking_ToAllViewsExceptTutorialWindowAndTooltips_WhenRevisitingCompletedPage()
        {
            firstPage.m_Paragraphs[0].maskingSettings.SetUnmaskedViews(new[] { UnmaskedView.CreateInstanceForGUIView <Toolbar>() });
            firstPage.m_Paragraphs[0].maskingSettings.enabled = true;
            firstPage.RaiseTutorialPageMaskingSettingsChangedEvent();

            firstPageCriterion.Complete(true);

            m_Window.RepaintImmediately();

            List <GUIView> views = new List <GUIView>();

            GUIViewDebuggerHelper.GetViews(views);

            // masking of final instruction still applied when it is complete
            var rects = new List <Rect>();

            foreach (var view in views)
            {
                if (view == m_Window.m_Parent || view == Toolbar.get || view is TooltipView)
                {
                    Assert.IsFalse(MaskingManager.IsMasked(new GUIViewProxy(view), rects));
                }
                else
                {
                    Assert.IsTrue(MaskingManager.IsMasked(new GUIViewProxy(view), rects));
                }
            }

            using (var automatedWindow = new AutomatedWindow <TutorialWindow>(m_Window))
            {
                m_Window.RepaintImmediately();

                // go to next page and then come back
                automatedWindow.Click(FindElementWithText(automatedWindow, nextButtonText, "next button"));
                yield return(null);

                m_Window.RepaintImmediately();
                automatedWindow.Click(FindElementWithStyle(automatedWindow, m_Window.allTutorialStyles.backButton, "back button"));
                yield return(null);

                m_Window.RepaintImmediately();
            }

            // now only tutorial window should be unmasked
            foreach (var view in views)
            {
                if (view == m_Window.m_Parent || view is TooltipView)
                {
                    Assert.IsFalse(MaskingManager.IsMasked(new GUIViewProxy(view), rects));
                }
                else
                {
                    Assert.IsTrue(MaskingManager.IsMasked(new GUIViewProxy(view), rects));
                }
            }
        }
コード例 #9
0
        public void TestGetViewsAndRects_ThrowsArgumentException_WhenTryingToGetRectsFromTwoEditorWindowsInTheSameDockArea()
        {
            EditorUtility.LoadWindowLayout("Packages/com.unity.learn.iet-framework/Tests/Editor/UnmaskedViewTestLayout.dwlt");

            // these two windows are docked together in the test layout
            var unmaskedViews = new[] {
                UnmaskedView.CreateInstanceForEditorWindow <SceneView>(),
                UnmaskedView.CreateInstanceForEditorWindow <GameView>(),
            };

            Assert.Throws <ArgumentException>(
                () => UnmaskedView.GetViewsAndRects(unmaskedViews),
                "Did not throw ArgumentException when getting rects for two EditorWindows in the same DockArea"
                );
        }
        public void ApplyHighlighting_ToOnlySpecifiedControls_WhenMaskingSettingsSpecifyControlsAndEntireWindowsAndViews()
        {
            var playButtonContrlSelector = new GuiControlSelector
            {
                SelectorMode = GuiControlSelector.Mode.NamedControl,
                ControlName  = "ToolbarPlayModePlayButton"
            };

            firstPage.m_Paragraphs[0].MaskingSettings.SetUnmaskedViews(
                new[]
            {
                UnmaskedView.CreateInstanceForGUIView <Toolbar>(new[] { playButtonContrlSelector }),
                UnmaskedView.CreateInstanceForGUIView <AppStatusBar>()
            }
                );
            firstPage.m_Paragraphs[0].MaskingSettings.Enabled = true;
            firstPage.RaiseTutorialPageMaskingSettingsChangedEvent();

            m_Window.RepaintImmediately();

            List <GUIView> views = new List <GUIView>();

            GUIViewDebuggerHelper.GetViews(views);

            // only the play button should be highlighted
            var rects = new List <Rect>();

            foreach (var view in views)
            {
                if (view == Toolbar.get)
                {
                    Assert.IsTrue(MaskingManager.IsHighlighted(new GUIViewProxy(view), rects));
                    Assert.AreEqual(1, rects.Count);
                    var viewPosition = view.position;
                    var controlRect  = rects[0];
                    Assert.Greater(controlRect.xMin, viewPosition.xMin);
                    Assert.Greater(controlRect.yMin, viewPosition.yMin);
                    Assert.Less(controlRect.xMax, viewPosition.xMax);
                    Assert.Less(controlRect.yMax, viewPosition.yMax);
                }
                else
                {
                    Assert.IsFalse(MaskingManager.IsHighlighted(new GUIViewProxy(view), rects));
                }
            }
        }
コード例 #11
0
        public IEnumerator TestGetViewsAndRects_ForSerializedPropertyInInspector_WhenParentPropertyIsCollapsed(
            bool parentPropertyExpanded, bool expectedFoundAncestorProperty)
        {
            var testObject = new GameObject("TestGetViewsAndRects_ForContractedPropertyInInspector",
                                            typeof(TestComponents.ComponentWithNestedValues));

            Selection.activeObject = testObject;
            try
            {
                var serializedObject = new SerializedObject(testObject.GetComponent <TestComponents.ComponentWithNestedValues>());
                var parentProperty   = serializedObject.FindProperty("componentWithNestedValuesFieldA");
                var childProperty    = serializedObject.FindProperty(
                    "componentWithNestedValuesFieldA.componentWithNestedValuesFieldB");

                Assert.That(parentProperty, Is.Not.Null);
                Assert.That(childProperty, Is.Not.Null);

                parentProperty.isExpanded = parentPropertyExpanded;
                serializedObject.ApplyModifiedProperties();

                var inspectorWindow = EditorWindow.GetWindow <InspectorWindow>();

                Rect labelRectOfExpectedFoundProperty;
                using (var automatedWindow = new AutomatedWindow <InspectorWindow>(inspectorWindow))
                {
                    inspectorWindow.Repaint();
                    yield return(null);

                    if (expectedFoundAncestorProperty)
                    {
                        var parentElements = automatedWindow.FindElementsByGUIContent(
                            new GUIContent("Component With Nested Values Field A"));
                        Assert.That(parentElements.Count(), Is.EqualTo(1));
                        labelRectOfExpectedFoundProperty = parentElements.Single().rect;
                    }
                    else
                    {
                        var childElements = automatedWindow.FindElementsByGUIContent(
                            new GUIContent("Component With Nested Values Field B"));
                        Assert.That(childElements.Count(), Is.EqualTo(1));
                        labelRectOfExpectedFoundProperty = childElements.Single().rect;
                    }
                }

                var unmaskedViews = new[] {
                    UnmaskedView.CreateInstanceForEditorWindow <InspectorWindow>(
                        new[] {
                        new GUIControlSelector()
                        {
                            selectorMode = GUIControlSelector.Mode.Property,
                            targetType   = typeof(TestComponents.ComponentWithNestedValues),
                            propertyPath = "componentWithNestedValuesFieldA.componentWithNestedValuesFieldB"
                        }
                    }
                        )
                };

                bool foundAncestorProperty;
                var  viewsAndRects = UnmaskedView.GetViewsAndRects(unmaskedViews, out foundAncestorProperty)
                                     .m_MaskData;

                Assert.That(foundAncestorProperty, Is.EqualTo(expectedFoundAncestorProperty));
                Assert.That(viewsAndRects.Count, Is.EqualTo(1), "Did not find one view for the Inspector");

                var rects = viewsAndRects.Values.First().rects;
                Assert.That(rects.Count, Is.EqualTo(1),
                            "Did not find exactly one control for the SerializedPropert " +
                            "componentWithNestedValuesFieldA.componentWithNestedValuesFieldB for ComponentWithNestedValues");

                var rect = rects.Single();
                Assert.That(rect.yMin, Is.GreaterThanOrEqualTo(labelRectOfExpectedFoundProperty.yMin),
                            "Found property rect does not contain of label rect of expected found property");
                Assert.That(rect.yMax, Is.LessThanOrEqualTo(labelRectOfExpectedFoundProperty.yMax),
                            "Found property rect does not contain of label rect of expected found property");
            }
            finally
            {
                UnityEngine.Object.DestroyImmediate(testObject);
            }
        }
コード例 #12
0
        public void TestGetViewsAndRects_ForNamedControlsInToolbar()
        {
            // 0) Setup
            var toolbarType     = GUIViewProxy.ToolbarType;
            var sceneViewType   = typeof(SceneView);
            var umaskedControls = new Dictionary <Type, List <GuiControlSelector> >
            {
                { toolbarType, new List <GuiControlSelector>() },
                { sceneViewType, new List <GuiControlSelector>() },
            };

            var playModeControls = new[]
            {
                CreateGuiControlSelector("ToolbarPlayModePlayButton", "Play"),
                CreateGuiControlSelector("ToolbarPlayModePauseButton", "Pause"),
                CreateGuiControlSelector("ToolbarPlayModeStepButton", "Step")
            };

            // These controls are still in toolbar regardless of Unity version
            umaskedControls[toolbarType].AddRange(playModeControls);

            var sceneToolControls = new[]
            {
                CreateGuiControlSelector("ToolbarPersistentToolsPan", "ViewTool"),
                CreateGuiControlSelector("ToolbarPersistentToolsTranslate", "MoveTool"),
                CreateGuiControlSelector("ToolbarPersistentToolsRotate", "RotateTool"),
                CreateGuiControlSelector("ToolbarPersistentToolsScale", "ScaleTool"),
                CreateGuiControlSelector("ToolbarPersistentToolsRect", "RectTool"),
                CreateGuiControlSelector("ToolbarToolPivotPositionButton", "Pivot Mode"),
                CreateGuiControlSelector("ToolbarToolPivotOrientationButton", "Pivot Rotation"),
            };

            // These controls are now in the Scene view instead of Toolbar beginning from 2021.1
#if UNITY_2021_1_OR_NEWER
            umaskedControls[sceneViewType].AddRange(sceneToolControls);
#else
            umaskedControls[toolbarType].AddRange(sceneToolControls);
#endif

            // 1) Toolbar tests
            var unmaskedToolbarViews    = new List <UnmaskedView>();
            var unmaskedToolbarControls = umaskedControls[toolbarType];
            if (unmaskedToolbarControls.Any())
            {
                unmaskedToolbarViews.Add(UnmaskedView.CreateInstanceForGUIView(toolbarType, unmaskedToolbarControls));
            }

            var viewsAndRects = UnmaskedView.GetViewsAndRects(unmaskedToolbarViews).m_MaskData;
            Assert.AreEqual(unmaskedToolbarViews.Count, viewsAndRects.Count, "Did not find expected amount of views for the Toolbar views");
            if (viewsAndRects.Count > 0)
            {
                var rects = viewsAndRects.Values.FirstOrDefault().rects;
                Assert.AreEqual(unmaskedToolbarControls.Count(), rects.Count, "Did not find all of the expected controls in the Toolbar");
            }

            // 2) SceneView tests
            var unmaskedSceneViewViews    = new List <UnmaskedView>();
            var unmaskedSceneViewControls = umaskedControls[sceneViewType];
            if (unmaskedSceneViewControls.Any())
            {
                unmaskedSceneViewViews.Add(UnmaskedView.CreateInstanceForEditorWindow(sceneViewType, unmaskedSceneViewControls));
            }

            viewsAndRects = UnmaskedView.GetViewsAndRects(unmaskedSceneViewViews).m_MaskData;
            Assert.AreEqual(unmaskedSceneViewViews.Count, viewsAndRects.Count, "Did not find expected amount of views for the SceneView views");
            if (viewsAndRects.Count > 0)
            {
                var rects = viewsAndRects.Values.FirstOrDefault().rects;
                Assert.AreEqual(unmaskedSceneViewControls.Count(), rects.Count, "Did not find all of the expected controls in the SceneView");
            }
        }