public static IEnumerator TestUIElementAddedCorrectlyOnInvisibleParent <TComponent, TComponentModel>(ParcelScene scene, CLASS_ID classId)
            where TComponent : UIShape
            where TComponentModel : UIShape.Model, new()
        {
            UIScreenSpace parentElement = TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene, CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(parentElement.routine);

            // make canvas invisible
            yield return(SharedComponentUpdate(parentElement, new UIScreenSpace.Model {
                visible = false
            }));

            TComponent targetUIElement =
                SharedComponentCreate <TComponent, TComponentModel>(scene,
                                                                    classId,
                                                                    new TComponentModel
            {
                parentComponent = parentElement.id,
                width           = new UIValue(100f),
                height          = new UIValue(100f)
            });

            yield return(targetUIElement.routine);

            RectTransform uiCanvasRectTransform = parentElement.childHookRectTransform.GetComponentInParent <RectTransform>();

            Assert.AreEqual(uiCanvasRectTransform.rect.width / 2, targetUIElement.referencesContainer.layoutElementRT.anchoredPosition.x);
            Assert.AreEqual(-uiCanvasRectTransform.rect.height / 2, targetUIElement.referencesContainer.layoutElementRT.anchoredPosition.y);

            Assert.AreEqual(100f, targetUIElement.referencesContainer.layoutElementRT.rect.width);
            Assert.AreEqual(100f, targetUIElement.referencesContainer.layoutElementRT.rect.height);
        }
Exemple #2
0
        public IEnumerator TestScaleWhenCharacterIsElsewhere()
        {
            // Position character outside parcel
            TestHelpers.SetCharacterPosition(new Vector3(50f, 3f, 50f));

            yield return(null);

            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            RectTransform canvasRectTransform = screenSpaceShape.canvas.GetComponent <RectTransform>();

            const float diffThreshold  = 0.1f; //to ensure float point comparison
            Vector2     canvasRealSize = canvasRectTransform.sizeDelta * canvasRectTransform.localScale;
            Vector2     screenSize     = new Vector2(Screen.width, Screen.height);

            //Canvas should have the same size of the screen
            Assert.IsTrue(Mathf.Abs((canvasRealSize - screenSize).magnitude) < diffThreshold);

            yield return(new WaitForAllMessagesProcessed());

            screenSpaceShape.Dispose();
        }
Exemple #3
0
        public IEnumerator NormalizedSize()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            // Create UIContainerStack
            UIContainerStack uiContainerStack =
                TestHelpers.SharedComponentCreate <UIContainerStack, UIContainerStack.Model>(scene,
                                                                                             CLASS_ID.UI_CONTAINER_STACK,
                                                                                             new UIContainerStack.Model
            {
                parentComponent = screenSpaceShape.id,
                width           = new UIValue(50, UIValue.Unit.PERCENT),
                height          = new UIValue(30, UIValue.Unit.PERCENT)
            });

            yield return(uiContainerStack.routine);

            UnityEngine.UI.Image image = uiContainerStack.childHookRectTransform.GetComponent <UnityEngine.UI.Image>();

            // Check updated properties are applied correctly
            Assert.AreEqual(screenSpaceShape.childHookRectTransform.rect.width * 0.5f,
                            uiContainerStack.childHookRectTransform.rect.width, 0.01f);
            Assert.AreEqual(screenSpaceShape.childHookRectTransform.rect.height * 0.3f,
                            uiContainerStack.childHookRectTransform.rect.height, 0.01f);

            screenSpaceShape.Dispose();
            yield return(null);
        }
Exemple #4
0
    protected IEnumerator InitUIVisualTestScene(string testName)
    {
        yield return(InitScene());

        yield return(VisualTestHelpers.InitVisualTestsScene(testName));

        // Create UIScreenSpace
        UIScreenSpace screenSpace = TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene, CLASS_ID.UI_SCREEN_SPACE_SHAPE);

        yield return(screenSpace.routine);

        screenSpaceId = screenSpace.id;

        // The canvas has to be in ScreenSpaceCamera mode to be able to render the UI correctly for the snapshots
        screenSpace.canvas.renderMode    = RenderMode.ScreenSpaceCamera;
        screenSpace.canvas.worldCamera   = VisualTestController.i.camera;
        screenSpace.canvas.planeDistance = 1;

        // The camera should only render UI to decrease conflict chance with future ground changes, etc.
        VisualTestController.i.camera.cullingMask = 1 << LayerMask.NameToLayer("UI");

        int id = GameViewUtils.AddOrGetCustomSize(GameViewUtils.GameViewSizeType.FixedResolution, UnityEditor.GameViewSizeGroupType.Standalone, 1280, 720, "Test Resolution");

        GameViewUtils.SetSize(id);
    }
Exemple #5
0
    protected IEnumerator InitUIVisualTestScene(string testName)
    {
        VisualTestHelpers.snapshotIndex   = 0;
        VisualTestHelpers.currentTestName = testName;

        yield return(InitScene());

        //NOTE(Brian): If we don't wait a frame, RenderingController.Awake sets the rendering state back to false.
        yield return(null);

        RenderProfileManifest.i.Initialize(RenderProfileManifest.i.testProfile);

        base.SetUp_Renderer();

        // Create UIScreenSpace
        UIScreenSpace screenSpace = TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene, CLASS_ID.UI_SCREEN_SPACE_SHAPE);

        yield return(screenSpace.routine);

        screenSpaceId = screenSpace.id;

        // The canvas has to be in ScreenSpaceCamera mode to be able to render the UI correctly for the snapshots
        screenSpace.canvas.renderMode    = RenderMode.ScreenSpaceCamera;
        screenSpace.canvas.worldCamera   = VisualTestController.i.camera;
        screenSpace.canvas.planeDistance = 1;

        // The camera should only render UI to decrease conflict chance with future ground changes, etc.
        VisualTestController.i.camera.cullingMask = 1 << LayerMask.NameToLayer("UI");

        int id = GameViewUtils.AddOrGetCustomSize(GameViewUtils.GameViewSizeType.FixedResolution, UnityEditor.GameViewSizeGroupType.Standalone, 1280, 720, "Test Resolution");

        GameViewUtils.SetSize(id);
    }
Exemple #6
0
        public IEnumerator PropertiesAreAppliedCorrectly()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            // Create UIContainerStack
            UIContainerStack uiContainerStack =
                TestHelpers.SharedComponentCreate <UIContainerStack, UIContainerStack.Model>(scene,
                                                                                             CLASS_ID.UI_CONTAINER_STACK);

            yield return(uiContainerStack.routine);

            UnityEngine.UI.Image image = uiContainerStack.referencesContainer.image;

            // Check default properties are applied correctly
            Assert.IsTrue(image.color == new Color(0f, 0f, 0f, 0f));
            Assert.IsTrue(uiContainerStack.referencesContainer.canvasGroup.blocksRaycasts);
            Assert.AreEqual(100f, uiContainerStack.childHookRectTransform.rect.width);
            Assert.AreEqual(50f, uiContainerStack.childHookRectTransform.rect.height);
            Assert.AreEqual(Vector3.zero, uiContainerStack.childHookRectTransform.localPosition);

            yield return(TestHelpers.SharedComponentUpdate(uiContainerStack,
                                                           new UIContainerStack.Model
            {
                parentComponent = screenSpaceShape.id,
                color = new Color(0.2f, 0.7f, 0.05f, 1f),
                isPointerBlocker = true,
                width = new UIValue(275f),
                height = new UIValue(130f),
                positionX = new UIValue(-30f),
                positionY = new UIValue(-15f),
                hAlign = "right",
                vAlign = "bottom"
            }));

            // Check updated properties are applied correctly
            Assert.IsTrue(uiContainerStack.referencesContainer.transform.parent ==
                          screenSpaceShape.childHookRectTransform);
            Assert.IsTrue(image.color == new Color(0.2f, 0.7f, 0.05f, 1f));
            Assert.IsTrue(image.raycastTarget);
            Assert.AreEqual(275f, uiContainerStack.childHookRectTransform.rect.width);
            Assert.AreEqual(130f, uiContainerStack.childHookRectTransform.rect.height);
            Assert.IsTrue(uiContainerStack.referencesContainer.layoutGroup.childAlignment == TextAnchor.LowerRight);

            Vector2 alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                                       uiContainerStack.childHookRectTransform.rect, "bottom", "right");

            alignedPosition += new Vector2(-30, -15); // apply offset position

            Assert.AreEqual(alignedPosition.ToString(),
                            uiContainerStack.childHookRectTransform.anchoredPosition.ToString());

            screenSpaceShape.Dispose();
        }
        public IEnumerator TestVisibilityUpdate()
        {
            scene.isPersistent = false;
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            CanvasGroup canvasGroup = screenSpaceShape.canvas.GetComponent <CanvasGroup>();

            // Check visibility
            Assert.IsTrue(canvasGroup.alpha == 1f,
                          "When the character is inside the scene, the UIScreenSpaceShape should be visible");

            // Update canvas visibility value manually
            yield return(TestHelpers.SharedComponentUpdate(screenSpaceShape,
                                                           new UIScreenSpace.Model
            {
                visible = false
            }));

            // Check visibility
            Assert.IsTrue(canvasGroup.alpha == 0f,
                          "When the UIScreenSpaceShape is explicitly updated as 'invisible', its canvas shouldn't be visible");

            // Re-enable visibility
            yield return(TestHelpers.SharedComponentUpdate(screenSpaceShape,
                                                           new UIScreenSpace.Model
            {
                visible = true
            }));

            TestHelpers.SetCharacterPosition(Vector3.zero);

            yield return(screenSpaceShape.routine);

            // Check visibility
            Assert.IsTrue(canvasGroup.alpha == 1f,
                          "When the UIScreenSpaceShape is explicitly updated as 'visible', its canvas should be visible");

            // Position character outside parcel
            TestHelpers.SetCharacterPosition(new Vector3(100, 3f, 100f));

            yield return(null);

            // Check visibility
            Assert.IsTrue(canvasGroup.alpha == 0f,
                          "When the character is outside the scene, the UIScreenSpaceShape shouldn't be visible");

            yield return(new WaitForAllMessagesProcessed());

            screenSpaceShape.Dispose();
        }
        public IEnumerator TestOnClickOnInvisibleShapeEvent()
        {
            UIScreenSpace screenSpaceShape = TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene, CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            Assert.IsFalse(screenSpaceShape == null);

            DCLTexture texture = TestHelpers.CreateDCLTexture(scene, DCL.Helpers.Utils.GetTestsAssetsPath() + "/Images/atlas.png");

            yield return(texture.routine);

            // --------------------------------------------------------------------------------------
            // Visible image that should trigger click events
            UIImage uiImage = TestHelpers.SharedComponentCreate <UIImage, UIImage.Model>(scene, CLASS_ID.UI_IMAGE_SHAPE);

            yield return(uiImage.routine);

            string uiImageOnClickEventId = "UUIDFakeEventId";

            yield return(TestHelpers.SharedComponentUpdate(uiImage, new UIImage.Model
            {
                visible = true,
                parentComponent = screenSpaceShape.id,
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),
                onClick = uiImageOnClickEventId
            }));

            // --------------------------------------------------------------------------------------
            // Invisible image
            // Create an invisible image to check that it doesn't trigger click events
            // and that doesn't prevent previous image from triggering click events
            UIImage uiImage2 = TestHelpers.SharedComponentCreate <UIImage, UIImage.Model>(scene, CLASS_ID.UI_IMAGE_SHAPE);

            yield return(uiImage2.routine);

            yield return(TestHelpers.SharedComponentUpdate(uiImage2, new UIImage.Model
            {
                visible = false,
                parentComponent = screenSpaceShape.id,
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),

                onClick = uiImageOnClickEventId
            }));

            // --------------------------------------------------------------------------------------
            // We need to cast a ray to check clicked objects
            Assert.IsFalse(TestHelpers.TestUIClick(screenSpaceShape.canvas, uiImage2.referencesContainer.childHookRectTransform));
            Assert.IsTrue(TestHelpers.TestUIClick(screenSpaceShape.canvas, uiImage.referencesContainer.childHookRectTransform));
        }
        public IEnumerator TestOnClickEvent()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            UIScrollRect scrRect =
                TestHelpers.SharedComponentCreate <UIScrollRect, UIScrollRect.Model>(scene, CLASS_ID.UI_SLIDER_SHAPE);

            yield return(scrRect.routine);

            // Force a new update to pass the first apply
            yield return(TestHelpers.SharedComponentUpdate(scrRect, new UIScrollRect.Model
            {
                name = "newName"
            }));

            // Update UIScrollRect properties
            yield return(TestHelpers.SharedComponentUpdate(scrRect,
                                                           new UIScrollRect.Model
            {
                parentComponent = screenSpaceShape.id,
                isPointerBlocker = false,
                width = new UIValue(275f),
                height = new UIValue(130f),
                positionX = new UIValue(-30f),
                positionY = new UIValue(-15f),
                hAlign = "right",
                vAlign = "bottom",
                onClick = "UUIDFakeEventId"
            }));

            //------------------------------------------------------------------------
            // Test click events
            bool eventResult = false;

            yield return(TestHelpers.TestUIClickEventPropagation(
                             scene.sceneData.id,
                             scrRect.model.onClick,
                             scrRect.referencesContainer.childHookRectTransform,
                             (bool res) =>
            {
                // Check image object clicking triggers the correct event
                eventResult = res;
            }));

            Assert.IsTrue(eventResult);

            screenSpaceShape.Dispose();
        }
Exemple #10
0
        public IEnumerator MissingValuesGetDefaultedOnUpdate()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            yield return(TestHelpers.TestSharedComponentDefaultsOnUpdate <UIContainerStack.Model, UIContainerStack>(
                             scene, CLASS_ID.UI_CONTAINER_STACK));
        }
        public IEnumerator TestMissingValuesGetDefaultedOnUpdate()
        {
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            Assert.IsFalse(screenSpaceShape == null);

            yield return(TestHelpers.TestSharedComponentDefaultsOnUpdate <UIImage.Model, UIImage>(scene,
                                                                                                  CLASS_ID.UI_IMAGE_SHAPE));
        }
        public IEnumerator TestMissingValuesGetDefaultedOnUpdate()
        {
            //// Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            Assert.IsFalse(screenSpaceShape == null);

            yield return(TestHelpers.TestSharedComponentDefaultsOnUpdate <UIContainerRect.Model, UIContainerRect>(scene,
                                                                                                                  CLASS_ID.UI_CONTAINER_RECT));
        }
        public IEnumerator TestOnClickEvent()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            // Create UIContainerRectShape
            UIContainerRect uiContainerRectShape =
                TestHelpers.SharedComponentCreate <UIContainerRect, UIContainerRect.Model>(scene,
                                                                                           CLASS_ID.UI_CONTAINER_RECT);

            yield return(uiContainerRectShape.routine);

            // Update UIContainerRectShape properties
            uiContainerRectShape = scene.SharedComponentUpdate(uiContainerRectShape.id, JsonUtility.ToJson(new UIContainerRect.Model
            {
                parentComponent  = screenSpaceShape.id,
                thickness        = 5,
                color            = new Color(0.2f, 0.7f, 0.05f, 1f),
                isPointerBlocker = false,
                width            = new UIValue(275f),
                height           = new UIValue(130f),
                positionX        = new UIValue(-30f),
                positionY        = new UIValue(-15f),
                hAlign           = "right",
                vAlign           = "bottom",
                onClick          = "UUIDFakeEventId"
            })) as UIContainerRect;

            yield return(uiContainerRectShape.routine);

            //------------------------------------------------------------------------
            // Test click events
            bool eventResult = false;

            yield return(TestHelpers.TestUIClickEventPropagation(
                             scene.sceneData.id,
                             uiContainerRectShape.model.onClick,
                             uiContainerRectShape.referencesContainer.childHookRectTransform,
                             (bool res) =>
            {
                // Check image object clicking triggers the correct event
                eventResult = res;
            }));

            Assert.IsTrue(eventResult);
        }
Exemple #14
0
        public IEnumerator TestChildrenAreHandledCorrectly()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            // Create UIContainerStack
            UIContainerStack uiContainerStack =
                TestHelpers.SharedComponentCreate <UIContainerStack, UIContainerStack.Model>(scene,
                                                                                             CLASS_ID.UI_CONTAINER_STACK);

            yield return(uiContainerStack.routine);


            // Create 1st child object
            UIContainerRect childComponent1 = TestHelpers.SharedComponentCreate <UIContainerRect, UIContainerRect.Model>(
                scene, CLASS_ID.UI_CONTAINER_RECT,
                new UIContainerRect.Model()
            {
                parentComponent = uiContainerStack.id
            });

            yield return(childComponent1.routine);

            Assert.IsTrue(uiContainerStack.stackContainers.ContainsKey(childComponent1.id));
            Assert.IsTrue(childComponent1.referencesContainer.transform.parent.gameObject ==
                          uiContainerStack.stackContainers[childComponent1.id]);

            // Create 2nd child object
            UIImage childComponent2 = TestHelpers.SharedComponentCreate <UIImage, UIImage.Model>(scene,
                                                                                                 CLASS_ID.UI_IMAGE_SHAPE,
                                                                                                 new UIImage.Model
            {
                parentComponent = uiContainerStack.id,
            });

            yield return(childComponent2.routine);

            Assert.IsTrue(uiContainerStack.stackContainers.ContainsKey(childComponent2.id));
            Assert.IsTrue(childComponent2.referencesContainer.transform.parent.gameObject ==
                          uiContainerStack.stackContainers[childComponent2.id]);

            screenSpaceShape.Dispose();
            yield return(null);
        }
Exemple #15
0
        public IEnumerator InputTextCreate()
        {
            ssshape = TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(
                scene,
                DCL.Models.CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(ssshape.routine);

            if (mockCamera == null)
            {
                GameObject go = new GameObject("Mock camera");
                mockCamera                 = go.AddComponent <Camera>();
                mockCamera.clearFlags      = CameraClearFlags.Color;
                mockCamera.backgroundColor = Color.black;
            }

            textInput = TestHelpers.SharedComponentCreate <UIInputText, UIInputText.Model>(
                scene,
                DCL.Models.CLASS_ID.UI_INPUT_TEXT_SHAPE,
                new UIInputText.Model()
            {
                textModel = new DCL.Components.TextShape.Model()
                {
                    color   = Color.white,
                    opacity = 1,
                },

                isPointerBlocker  = true,
                placeholder       = "Chat here!",
                placeholderColor  = Color.grey,
                focusedBackground = Color.black,
                parentComponent   = ssshape.id,
                positionX         = new UIValue(0.5f, UIValue.Unit.PERCENT),
                positionY         = new UIValue(0.5f, UIValue.Unit.PERCENT),
                height            = new UIValue(100),
                width             = new UIValue(100),
                onClick           = "UUIDFakeEventId"
            });

            yield return(textInput.routine);

            yield return(null);

            if (mockCamera != null)
            {
                Object.Destroy(mockCamera.gameObject);
            }
        }
Exemple #16
0
        public IEnumerator TestConstrainedPanelMaskAppliesToParcelsUI()
        {
            yield return(null);

            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            Assert.IsFalse(scene.isPersistent);
            Assert.IsTrue(screenSpaceShape.childHookRectTransform.GetComponent <UnityEngine.UI.RectMask2D>() != null);

            screenSpaceShape.Dispose();
        }
        public IEnumerator TestParenting()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            // Create UIContainerRectShape
            UIContainerRect uiContainerRectShape =
                TestHelpers.SharedComponentCreate <UIContainerRect, UIContainerRect.Model>(scene,
                                                                                           CLASS_ID.UI_CONTAINER_RECT);

            yield return(uiContainerRectShape.routine);

            // Update UIContainerRectShape parent
            scene.SharedComponentUpdate(uiContainerRectShape.id, JsonUtility.ToJson(new UIContainerRect.Model
            {
                parentComponent = screenSpaceShape.id,
            }));
            yield return(uiContainerRectShape.routine);

            // Check updated parent
            Assert.IsTrue(uiContainerRectShape.referencesContainer.transform.parent ==
                          screenSpaceShape.childHookRectTransform);

            // Create 2nd UIContainerRectShape
            UIContainerRect uiContainerRectShape2 =
                TestHelpers.SharedComponentCreate <UIContainerRect, UIContainerRect.Model>(scene,
                                                                                           CLASS_ID.UI_CONTAINER_RECT);

            yield return(uiContainerRectShape2.routine);

            // Update UIContainerRectShape parent to the previous container
            scene.SharedComponentUpdate(uiContainerRectShape2.id, JsonUtility.ToJson(new UIContainerRect.Model
            {
                parentComponent = uiContainerRectShape.id,
            }));
            yield return(uiContainerRectShape2.routine);

            // Check updated parent
            Assert.IsTrue(uiContainerRectShape2.referencesContainer.transform.parent ==
                          uiContainerRectShape.childHookRectTransform);

            screenSpaceShape.Dispose();
        }
Exemple #18
0
        public IEnumerator TestConstrainedPanelMaskDoesntApplyToDecentralandUI()
        {
            scene.isPersistent = true;

            yield return(null);

            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            Assert.IsTrue(scene.isPersistent);
            Assert.IsTrue(screenSpaceShape.childHookRectTransform.GetComponent <UnityEngine.UI.RectMask2D>() == null);

            // UIScreenSpace.InitializeCanvas is not awaited by screenSpaceShape.routine
            // todo fix it properly
            yield return(new WaitForSeconds(0.2f));

            screenSpaceShape.Dispose();
        }
Exemple #19
0
        public IEnumerator Start()
        {
            yield return(InitScene(spawnCharController: false));

            DCLCharacterController.i.gravity = 0;

            UIScreenSpace ssshape = TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(
                scene,
                DCL.Models.CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(ssshape.routine);

            UIInputText text = TestHelpers.SharedComponentCreate <UIInputText, UIInputText.Model>(
                scene,
                Models.CLASS_ID.UI_INPUT_TEXT_SHAPE,
                new UIInputText.Model()
            {
                textModel = new DCL.Components.TextShape.Model()
                {
                    color   = Color.white,
                    opacity = 1,
                },

                placeholder       = "Chat here!",
                placeholderColor  = Color.grey,
                focusedBackground = Color.black,
                parentComponent   = ssshape.id,
                positionX         = new UIValue(200, UIValue.Unit.PIXELS),
                positionY         = new UIValue(200, UIValue.Unit.PIXELS),
                height            = new UIValue(200, UIValue.Unit.PIXELS),
                width             = new UIValue(200, UIValue.Unit.PIXELS),
                hAlign            = "left",
                vAlign            = "top",
            });

            yield return(text.routine);
        }
Exemple #20
0
        public IEnumerator TestPropertiesAreAppliedCorrectly()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            // Create UITextShape
            UIText uiTextShape = TestHelpers.SharedComponentCreate <UIText, UIText.Model>(scene, CLASS_ID.UI_TEXT_SHAPE,
                                                                                          new UIText.Model {
            });

            yield return(uiTextShape.routine);

            // Check default properties are applied correctly
            Assert.IsTrue(uiTextShape.referencesContainer.transform.parent == screenSpaceShape.childHookRectTransform);
            Assert.IsTrue(uiTextShape.referencesContainer.canvasGroup.blocksRaycasts);
            Assert.AreEqual(100f, uiTextShape.childHookRectTransform.rect.width);
            Assert.AreEqual(50f, uiTextShape.childHookRectTransform.rect.height);
            Assert.IsTrue(uiTextShape.referencesContainer.text.enabled);
            Assert.AreEqual(Color.white, uiTextShape.referencesContainer.text.color);
            Assert.AreEqual(100f, uiTextShape.referencesContainer.text.fontSize);
            Assert.AreEqual("", uiTextShape.referencesContainer.text.text);
            Assert.AreEqual(int.MaxValue, uiTextShape.referencesContainer.text.maxVisibleLines);
            Assert.AreEqual(0, uiTextShape.referencesContainer.text.lineSpacing);
            Assert.IsFalse(uiTextShape.referencesContainer.text.enableAutoSizing);
            Assert.IsFalse(uiTextShape.referencesContainer.text.enableWordWrapping);
            Assert.IsFalse(uiTextShape.referencesContainer.text.fontMaterial.IsKeywordEnabled("UNDERLAY_ON"));

            Vector2 alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                                       uiTextShape.childHookRectTransform.rect);

            Assert.AreEqual(alignedPosition.ToString(), uiTextShape.childHookRectTransform.anchoredPosition.ToString());

            Assert.AreEqual(0, uiTextShape.referencesContainer.text.margin.x);
            Assert.AreEqual(0, uiTextShape.referencesContainer.text.margin.y);
            Assert.AreEqual(0, uiTextShape.referencesContainer.text.margin.z);
            Assert.AreEqual(0, uiTextShape.referencesContainer.text.margin.w);

            // Update UITextShape
            yield return(TestHelpers.SharedComponentUpdate <UIText>(uiTextShape,
                                                                    new UIText.Model
            {
                isPointerBlocker = true,
                hAlign = "left",
                vAlign = "bottom",
                textModel = new TextShape.Model
                {
                    value = "hello world",
                    color = Color.green,
                    opacity = 0.5f,
                    fontSize = 35f,
                    paddingTop = 10f,
                    paddingRight = 30f,
                    paddingBottom = 20f,
                    paddingLeft = 15,
                    lineSpacing = 0.1f,
                    lineCount = 3,
                    shadowOffsetX = 0.1f,
                    shadowOffsetY = 0.1f,
                    shadowColor = Color.yellow,
                    textWrapping = true
                }
            }));

            // Check default properties are applied correctly
            Assert.IsTrue(uiTextShape.referencesContainer.transform.parent == screenSpaceShape.childHookRectTransform);
            Assert.IsTrue(uiTextShape.referencesContainer.text.raycastTarget);
            Assert.AreEqual(100f, uiTextShape.childHookRectTransform.rect.width);
            Assert.AreEqual(50f, uiTextShape.childHookRectTransform.rect.height);
            Assert.AreEqual("hello world", uiTextShape.referencesContainer.text.text);
            Assert.IsTrue(uiTextShape.referencesContainer.text.enabled);
            Assert.AreEqual(new Color(0f, 1f, 0f, 0.5f), uiTextShape.referencesContainer.text.color);
            Assert.AreEqual(35f, uiTextShape.referencesContainer.text.fontSize);
            Assert.AreEqual(3, uiTextShape.referencesContainer.text.maxVisibleLines);
            Assert.AreEqual(0.1f, uiTextShape.referencesContainer.text.lineSpacing);
            Assert.IsTrue(uiTextShape.referencesContainer.text.enableWordWrapping);
            Assert.IsTrue(uiTextShape.referencesContainer.text.fontMaterial.IsKeywordEnabled("UNDERLAY_ON"));
            Assert.AreEqual(Color.yellow, uiTextShape.referencesContainer.text.fontMaterial.GetColor("_UnderlayColor"));

            alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                               uiTextShape.childHookRectTransform.rect, "bottom", "left");
            Assert.AreEqual(alignedPosition.ToString(), uiTextShape.childHookRectTransform.anchoredPosition.ToString());

            Assert.AreEqual(15f, uiTextShape.referencesContainer.text.margin.x);
            Assert.AreEqual(10f, uiTextShape.referencesContainer.text.margin.y);
            Assert.AreEqual(30f, uiTextShape.referencesContainer.text.margin.z);
            Assert.AreEqual(20f, uiTextShape.referencesContainer.text.margin.w);

            yield return(TestHelpers.SharedComponentUpdate <UIText>(uiTextShape,
                                                                    new UIText.Model
            {
                positionX = new UIValue(80),
                positionY = new UIValue(80),
            }));

            Assert.AreEqual(80f, uiTextShape.model.positionX.value);
            Assert.AreEqual(80f, uiTextShape.model.positionY.value);
        }
Exemple #21
0
        public BaseDisposable SharedComponentCreate(string id, string name, int classId)
        {
            SceneController.i.OnMessageDecodeStart?.Invoke("ComponentCreated");
            sharedComponentCreatedMessage.id      = id;
            sharedComponentCreatedMessage.name    = name;
            sharedComponentCreatedMessage.classId = classId;
            SceneController.i.OnMessageDecodeEnds?.Invoke("ComponentCreated");

            BaseDisposable disposableComponent;

            if (disposableComponents.TryGetValue(sharedComponentCreatedMessage.id, out disposableComponent))
            {
                return(disposableComponent);
            }

            BaseDisposable newComponent = null;

            switch ((CLASS_ID)sharedComponentCreatedMessage.classId)
            {
            case CLASS_ID.BOX_SHAPE:
            {
                newComponent = new BoxShape(this);
                break;
            }

            case CLASS_ID.SPHERE_SHAPE:
            {
                newComponent = new SphereShape(this);
                break;
            }

            case CLASS_ID.CONE_SHAPE:
            {
                newComponent = new ConeShape(this);
                break;
            }

            case CLASS_ID.CYLINDER_SHAPE:
            {
                newComponent = new CylinderShape(this);
                break;
            }

            case CLASS_ID.PLANE_SHAPE:
            {
                newComponent = new PlaneShape(this);
                break;
            }

            case CLASS_ID.GLTF_SHAPE:
            {
                newComponent = new GLTFShape(this);
                break;
            }

            case CLASS_ID.NFT_SHAPE:
            {
                newComponent = new NFTShape(this);
                break;
            }

            case CLASS_ID.OBJ_SHAPE:
            {
                newComponent = new OBJShape(this);
                break;
            }

            case CLASS_ID.BASIC_MATERIAL:
            {
                newComponent = new BasicMaterial(this);
                break;
            }

            case CLASS_ID.PBR_MATERIAL:
            {
                newComponent = new PBRMaterial(this);
                break;
            }

            case CLASS_ID.AUDIO_CLIP:
            {
                newComponent = new DCLAudioClip(this);
                break;
            }

            case CLASS_ID.TEXTURE:
            {
                newComponent = new DCLTexture(this);
                break;
            }

            case CLASS_ID.UI_INPUT_TEXT_SHAPE:
            {
                newComponent = new UIInputText(this);
                break;
            }

            case CLASS_ID.UI_FULLSCREEN_SHAPE:
            case CLASS_ID.UI_SCREEN_SPACE_SHAPE:
            {
                if (uiScreenSpace == null)
                {
                    newComponent = new UIScreenSpace(this);
                }

                break;
            }

            case CLASS_ID.UI_CONTAINER_RECT:
            {
                newComponent = new UIContainerRect(this);
                break;
            }

            case CLASS_ID.UI_SLIDER_SHAPE:
            {
                newComponent = new UIScrollRect(this);
                break;
            }

            case CLASS_ID.UI_CONTAINER_STACK:
            {
                newComponent = new UIContainerStack(this);
                break;
            }

            case CLASS_ID.UI_IMAGE_SHAPE:
            {
                newComponent = new UIImage(this);
                break;
            }

            case CLASS_ID.UI_TEXT_SHAPE:
            {
                newComponent = new UIText(this);
                break;
            }

            case CLASS_ID.VIDEO_CLIP:
            {
                newComponent = new DCLVideoClip(this);
                break;
            }

            case CLASS_ID.VIDEO_TEXTURE:
            {
                newComponent = new DCLVideoTexture(this);
                break;
            }

            case CLASS_ID.FONT:
            {
                newComponent = new DCLFont(this);
                break;
            }

            default:
                Debug.LogError($"Unknown classId");
                break;
            }

            if (newComponent != null)
            {
                newComponent.id = sharedComponentCreatedMessage.id;
                disposableComponents.Add(sharedComponentCreatedMessage.id, newComponent);

                if (state != State.READY)
                {
                    disposableNotReady.Add(id);
                }
            }

            return(newComponent);
        }
        public IEnumerator OnPointerHoverFeedbackIsBlockedByUI()
        {
            IDCLEntity entity;
            BoxShape   shape;

            shape = TestHelpers.InstantiateEntityWithShape <BoxShape, BoxShape.Model>(
                scene,
                DCL.Models.CLASS_ID.BOX_SHAPE,
                Vector3.zero,
                out entity,
                new BoxShape.Model()
            {
            });

            TestHelpers.SetEntityTransform(scene, entity, new Vector3(8, 2, 10), Quaternion.identity, new Vector3(3, 3, 3));
            yield return(shape.routine);

            var onPointerDownModel = new OnPointerDown.Model()
            {
                type = OnPointerDown.NAME,
                uuid = "pointerevent-1"
            };
            var component = TestHelpers.EntityComponentCreate <OnPointerDown, OnPointerDown.Model>(scene, entity,
                                                                                                   onPointerDownModel, CLASS_ID_COMPONENT.UUID_CALLBACK);

            Assert.IsTrue(component != null);

            yield return(null);

            DCLCharacterController.i.SetPosition(new Vector3(8, 1, 7f));

            var cameraController = GameObject.FindObjectOfType <CameraController>();

            // Rotate camera towards the interactive object
            cameraController.SetRotation(45, 0, 0);

            yield return(null);

            var hoverCanvasController = InteractionHoverCanvasController.i;

            Assert.IsNotNull(hoverCanvasController);

            // Check hover feedback is enabled
            Assert.IsTrue(hoverCanvasController.canvas.enabled);

            // Put UI in the middle
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            UIContainerRect uiContainerRectShape =
                TestHelpers.SharedComponentCreate <UIContainerRect, UIContainerRect.Model>(scene,
                                                                                           CLASS_ID.UI_CONTAINER_RECT);

            yield return(uiContainerRectShape.routine);

            yield return(null);

            // Check hover feedback is no longer enabled
            Assert.IsFalse(hoverCanvasController.canvas.enabled);

            DCLCharacterController.i.ResumeGravity();
        }
Exemple #23
0
        public IEnumerator TestOnClickEvent()
        {
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            Assert.IsFalse(screenSpaceShape == null);

            // Create UITextShape
            UIText uiTextShape = TestHelpers.SharedComponentCreate <UIText, UIText.Model>(scene, CLASS_ID.UI_TEXT_SHAPE,
                                                                                          new UIText.Model {
            });

            yield return(uiTextShape.routine);

            // Update UITextShape
            yield return(TestHelpers.SharedComponentUpdate(
                             uiTextShape,
                             new UIText.Model
            {
                isPointerBlocker = true,
                hAlign = "left",
                vAlign = "bottom",
                onClick = "UUIDFakeEventId",
                textModel = new TextShape.Model
                {
                    value = "hello world",
                    color = Color.green,
                    opacity = 0.5f,
                    fontSize = 35f,
                    paddingTop = 10f,
                    paddingRight = 30f,
                    paddingBottom = 20f,
                    paddingLeft = 15,
                    lineSpacing = 0.1f,
                    lineCount = 3,
                    shadowOffsetX = 0.1f,
                    shadowOffsetY = 0.1f,
                    shadowColor = Color.yellow,
                    textWrapping = true,
                }
            }));

            //------------------------------------------------------------------------
            // Test click events
            bool eventResult = false;

            yield return(TestHelpers.TestUIClickEventPropagation(
                             scene.sceneData.id,
                             uiTextShape.model,
                             uiTextShape.referencesContainer.childHookRectTransform,
                             (bool res) =>
            {
                // Check image object clicking triggers the correct event
                eventResult = res;
            }));

            Assert.IsTrue(eventResult);
        }
Exemple #24
0
        public BaseDisposable SharedComponentCreate(string id, int classId)
        {
            BaseDisposable disposableComponent;

            if (disposableComponents.TryGetValue(id, out disposableComponent))
            {
                return(disposableComponent);
            }

            BaseDisposable newComponent = null;

            switch ((CLASS_ID)classId)
            {
            case CLASS_ID.BOX_SHAPE:
            {
                newComponent = new BoxShape(this);
                break;
            }

            case CLASS_ID.SPHERE_SHAPE:
            {
                newComponent = new SphereShape(this);
                break;
            }

            case CLASS_ID.CONE_SHAPE:
            {
                newComponent = new ConeShape(this);
                break;
            }

            case CLASS_ID.CYLINDER_SHAPE:
            {
                newComponent = new CylinderShape(this);
                break;
            }

            case CLASS_ID.PLANE_SHAPE:
            {
                newComponent = new PlaneShape(this);
                break;
            }

            case CLASS_ID.GLTF_SHAPE:
            {
                newComponent = new GLTFShape(this);
                break;
            }

            case CLASS_ID.NFT_SHAPE:
            {
                newComponent = new NFTShape(this);
                break;
            }

            case CLASS_ID.OBJ_SHAPE:
            {
                newComponent = new OBJShape(this);
                break;
            }

            case CLASS_ID.BASIC_MATERIAL:
            {
                newComponent = new BasicMaterial(this);
                break;
            }

            case CLASS_ID.PBR_MATERIAL:
            {
                newComponent = new PBRMaterial(this);
                break;
            }

            case CLASS_ID.AUDIO_CLIP:
            {
                newComponent = new DCLAudioClip(this);
                break;
            }

            case CLASS_ID.TEXTURE:
            {
                newComponent = new DCLTexture(this);
                break;
            }

            case CLASS_ID.UI_INPUT_TEXT_SHAPE:
            {
                newComponent = new UIInputText(this);
                break;
            }

            case CLASS_ID.UI_FULLSCREEN_SHAPE:
            case CLASS_ID.UI_SCREEN_SPACE_SHAPE:
            {
                if (GetSharedComponent <UIScreenSpace>() == null)
                {
                    newComponent = new UIScreenSpace(this);
                }

                break;
            }

            case CLASS_ID.UI_CONTAINER_RECT:
            {
                newComponent = new UIContainerRect(this);
                break;
            }

            case CLASS_ID.UI_SLIDER_SHAPE:
            {
                newComponent = new UIScrollRect(this);
                break;
            }

            case CLASS_ID.UI_CONTAINER_STACK:
            {
                newComponent = new UIContainerStack(this);
                break;
            }

            case CLASS_ID.UI_IMAGE_SHAPE:
            {
                newComponent = new UIImage(this);
                break;
            }

            case CLASS_ID.UI_TEXT_SHAPE:
            {
                newComponent = new UIText(this);
                break;
            }

            case CLASS_ID.VIDEO_CLIP:
            {
                newComponent = new DCLVideoClip(this);
                break;
            }

            case CLASS_ID.VIDEO_TEXTURE:
            {
                newComponent = new DCLVideoTexture(this);
                break;
            }

            case CLASS_ID.FONT:
            {
                newComponent = new DCLFont(this);
                break;
            }

            case CLASS_ID.NAME:
            {
                newComponent = new DCLName(this);
                break;
            }

            case CLASS_ID.LOCKED_ON_EDIT:
            {
                newComponent = new DCLLockedOnEdit(this);
                break;
            }

            case CLASS_ID.VISIBLE_ON_EDIT:
            {
                newComponent = new DCLVisibleOnEdit(this);
                break;
            }

            default:
                Debug.LogError($"Unknown classId");
                break;
            }

            if (newComponent != null)
            {
                newComponent.id = id;
                disposableComponents.Add(id, newComponent);
                OnAddSharedComponent?.Invoke(id, newComponent);
            }

            return(newComponent);
        }
        public IEnumerator TestAlignment()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            // Create UIImage
            UIImage uiImageShape =
                TestHelpers.SharedComponentCreate <UIImage, UIImage.Model>(scene, CLASS_ID.UI_IMAGE_SHAPE);

            yield return(uiImageShape.routine);

            DCLTexture texture =
                TestHelpers.CreateDCLTexture(scene, DCL.Helpers.Utils.GetTestsAssetsPath() + "/Images/atlas.png");

            yield return(texture.routine);

            // Align to right-bottom
            yield return(TestHelpers.SharedComponentUpdate(uiImageShape, new UIImage.Model
            {
                parentComponent = screenSpaceShape.id,
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),
                hAlign = "right",
                vAlign = "bottom"
            }));

            // Check alignment position was applied correctly
            Vector2 alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                                       uiImageShape.childHookRectTransform.rect, "bottom", "right");

            Assert.AreEqual(alignedPosition.ToString(),
                            uiImageShape.referencesContainer.layoutElementRT.anchoredPosition.ToString());
            Assert.AreEqual(TextAnchor.LowerRight, uiImageShape.referencesContainer.layoutGroup.childAlignment);

            // Align to right-center
            yield return(TestHelpers.SharedComponentUpdate(uiImageShape, new UIImage.Model
            {
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),
                hAlign = "right",
                vAlign = "center"
            }));

            // Check alignment position was applied correctly
            alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                               uiImageShape.childHookRectTransform.rect, "center", "right");
            Assert.AreEqual(alignedPosition.ToString(),
                            uiImageShape.referencesContainer.layoutElementRT.anchoredPosition.ToString());
            Assert.AreEqual(TextAnchor.MiddleRight, uiImageShape.referencesContainer.layoutGroup.childAlignment);

            // Align to right-top
            yield return(TestHelpers.SharedComponentUpdate(uiImageShape, new UIImage.Model
            {
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),
                hAlign = "right",
                vAlign = "top"
            }));

            // Check alignment position was applied correctly
            alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                               uiImageShape.childHookRectTransform.rect, "top", "right");
            Assert.AreEqual(alignedPosition.ToString(),
                            uiImageShape.referencesContainer.layoutElementRT.anchoredPosition.ToString());
            Assert.AreEqual(TextAnchor.UpperRight, uiImageShape.referencesContainer.layoutGroup.childAlignment);

            // Align to center-bottom
            yield return(TestHelpers.SharedComponentUpdate(uiImageShape, new UIImage.Model
            {
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),
                hAlign = "center",
                vAlign = "bottom"
            }));

            // Check alignment position was applied correctly
            alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                               uiImageShape.childHookRectTransform.rect, "bottom", "center");
            Assert.AreEqual(alignedPosition.ToString(),
                            uiImageShape.referencesContainer.layoutElementRT.anchoredPosition.ToString());
            Assert.AreEqual(TextAnchor.LowerCenter, uiImageShape.referencesContainer.layoutGroup.childAlignment);

            // Align to center-center
            yield return(TestHelpers.SharedComponentUpdate(uiImageShape, new UIImage.Model
            {
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),
                hAlign = "center",
                vAlign = "center"
            }));

            // Check alignment position was applied correctly
            alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                               uiImageShape.childHookRectTransform.rect, "center", "center");
            Assert.AreEqual(alignedPosition.ToString(),
                            uiImageShape.referencesContainer.layoutElementRT.anchoredPosition.ToString());
            Assert.AreEqual(TextAnchor.MiddleCenter, uiImageShape.referencesContainer.layoutGroup.childAlignment);

            // Align to center-top
            yield return(TestHelpers.SharedComponentUpdate(uiImageShape, new UIImage.Model
            {
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),
                hAlign = "center",
                vAlign = "top"
            }));

            // Check alignment position was applied correctly
            alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                               uiImageShape.childHookRectTransform.rect, "top", "center");
            Assert.AreEqual(alignedPosition.ToString(),
                            uiImageShape.referencesContainer.layoutElementRT.anchoredPosition.ToString());
            Assert.AreEqual(TextAnchor.UpperCenter, uiImageShape.referencesContainer.layoutGroup.childAlignment);

            // Align to left-bottom
            yield return(TestHelpers.SharedComponentUpdate(uiImageShape, new UIImage.Model
            {
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),
                hAlign = "left",
                vAlign = "bottom"
            }));

            // Check alignment position was applied correctly
            alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                               uiImageShape.childHookRectTransform.rect, "bottom", "left");
            Assert.AreEqual(alignedPosition.ToString(),
                            uiImageShape.referencesContainer.layoutElementRT.anchoredPosition.ToString());
            Assert.AreEqual(TextAnchor.LowerLeft, uiImageShape.referencesContainer.layoutGroup.childAlignment);

            // Align to left-center
            yield return(TestHelpers.SharedComponentUpdate(uiImageShape, new UIImage.Model
            {
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),
                hAlign = "left",
                vAlign = "center"
            }));

            // Check alignment position was applied correctly
            alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                               uiImageShape.childHookRectTransform.rect, "center", "left");
            Assert.AreEqual(alignedPosition.ToString(),
                            uiImageShape.referencesContainer.layoutElementRT.anchoredPosition.ToString());
            Assert.AreEqual(TextAnchor.MiddleLeft, uiImageShape.referencesContainer.layoutGroup.childAlignment);

            // Align to left-top
            yield return(TestHelpers.SharedComponentUpdate(uiImageShape, new UIImage.Model
            {
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),
                hAlign = "left",
                vAlign = "top",
            }));

            // Check alignment position was applied correctly
            alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                               uiImageShape.childHookRectTransform.rect, "top", "left");
            Assert.AreEqual(alignedPosition.ToString(),
                            uiImageShape.referencesContainer.layoutElementRT.anchoredPosition.ToString());
            Assert.AreEqual(TextAnchor.UpperLeft, uiImageShape.referencesContainer.layoutGroup.childAlignment);

            screenSpaceShape.Dispose();
        }
        public IEnumerator TestPropertiesAreAppliedCorrectly()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            // Create UIImage
            UIImage uiImageShape =
                TestHelpers.SharedComponentCreate <UIImage, UIImage.Model>(scene, CLASS_ID.UI_IMAGE_SHAPE);

            yield return(uiImageShape.routine);

            // Check default properties are applied correctly
            Assert.IsTrue(uiImageShape.referencesContainer.transform.parent == screenSpaceShape.childHookRectTransform);
            Assert.IsTrue(uiImageShape.referencesContainer.image.color == new Color(1, 1, 1, 1));
            Assert.IsTrue(uiImageShape.referencesContainer.canvasGroup.blocksRaycasts);
            Assert.AreEqual(100f, uiImageShape.childHookRectTransform.rect.width);
            Assert.AreEqual(50f, uiImageShape.childHookRectTransform.rect.height);
            Assert.IsTrue(uiImageShape.referencesContainer.image.enabled);
            Assert.IsTrue(uiImageShape.referencesContainer.image.texture == null);

            Vector2 alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                                       uiImageShape.childHookRectTransform.rect);

            Assert.AreEqual(alignedPosition.ToString(),
                            uiImageShape.referencesContainer.layoutElementRT.anchoredPosition.ToString());

            // Update UIImage properties
            DCLTexture texture =
                TestHelpers.CreateDCLTexture(scene, DCL.Helpers.Utils.GetTestsAssetsPath() + "/Images/atlas.png");

            yield return(texture.routine);

            yield return(TestHelpers.SharedComponentUpdate(uiImageShape, new UIImage.Model
            {
                parentComponent = screenSpaceShape.id,
                source = texture.id,
                opacity = 0.7f,
                isPointerBlocker = true,
                width = new UIValue(128f),
                height = new UIValue(128f),
                positionX = new UIValue(-55f),
                positionY = new UIValue(30f),
                hAlign = "right",
                vAlign = "bottom",
                sourceLeft = 64f,
                sourceTop = 64f,
                sourceWidth = 64f,
                sourceHeight = 64f,
                paddingTop = 10f,
                paddingRight = 10f,
                paddingBottom = 10f,
                paddingLeft = 10f
            }));

            // Check default properties are applied correctly
            Assert.IsTrue(uiImageShape.referencesContainer.transform.parent == screenSpaceShape.childHookRectTransform);
            Assert.AreEqual(new Color(1, 1, 1, 1), uiImageShape.referencesContainer.image.color);
            Assert.IsTrue(uiImageShape.referencesContainer.canvasGroup.blocksRaycasts);

            Assert.AreEqual(108f, uiImageShape.childHookRectTransform.rect.width);  // 128 - 20 (left and right padding)
            Assert.AreEqual(108f, uiImageShape.childHookRectTransform.rect.height); // 128 - 20 (left and right padding)
            Assert.IsTrue(uiImageShape.referencesContainer.image.enabled);
            Assert.IsTrue(uiImageShape.referencesContainer.image.texture != null);

            alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                               uiImageShape.childHookRectTransform.rect, "bottom", "right");
            alignedPosition += new Vector2(-65f, 40f); // affected by padding

            Assert.AreEqual(alignedPosition.ToString(),
                            uiImageShape.referencesContainer.layoutElementRT.anchoredPosition.ToString());

            Assert.AreEqual(0.5f, uiImageShape.referencesContainer.image.uvRect.x);
            Assert.AreEqual(0f, uiImageShape.referencesContainer.image.uvRect.y);
            Assert.AreEqual(0.5f, uiImageShape.referencesContainer.image.uvRect.width);
            Assert.AreEqual(0.5f, uiImageShape.referencesContainer.image.uvRect.height);

            Assert.AreEqual(10, uiImageShape.referencesContainer.paddingLayoutGroup.padding.bottom);
            Assert.AreEqual(10, uiImageShape.referencesContainer.paddingLayoutGroup.padding.top);
            Assert.AreEqual(10, uiImageShape.referencesContainer.paddingLayoutGroup.padding.left);
            Assert.AreEqual(10, uiImageShape.referencesContainer.paddingLayoutGroup.padding.right);

            screenSpaceShape.Dispose();
        }
        public IEnumerator TestOnClickEvent()
        {
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            Assert.IsFalse(screenSpaceShape == null);

            DCLTexture texture =
                TestHelpers.CreateDCLTexture(scene, DCL.Helpers.Utils.GetTestsAssetsPath() + "/Images/atlas.png");

            yield return(texture.routine);

            UIImage uiImage = TestHelpers.SharedComponentCreate <UIImage, UIImage.Model>(scene, CLASS_ID.UI_IMAGE_SHAPE);

            yield return(uiImage.routine);

            string uiImageOnClickEventId = "UUIDFakeEventId";

            yield return(TestHelpers.SharedComponentUpdate(uiImage, new UIImage.Model
            {
                parentComponent = screenSpaceShape.id,
                source = texture.id,
                width = new UIValue(128f),
                height = new UIValue(128f),
                onClick = uiImageOnClickEventId
            }));

            bool eventResult = false;

            yield return(TestHelpers.TestUIClickEventPropagation(
                             scene.sceneData.id,
                             uiImageOnClickEventId,
                             (RectTransform)uiImage.referencesContainer.image.transform,
                             (bool res) =>
            {
                // Check image object clicking triggers the correct event
                eventResult = res;
            }));

            Assert.IsTrue(eventResult);

            // Check UI children won't trigger the parent/root image component event
            UIContainerRect uiContainer =
                TestHelpers.SharedComponentCreate <UIContainerRect, UIContainerRect.Model>(scene,
                                                                                           CLASS_ID.UI_CONTAINER_RECT);

            yield return(uiContainer.routine);

            yield return(TestHelpers.SharedComponentUpdate(uiContainer, new UIContainerRect.Model
            {
                parentComponent = uiImage.id
            }));

            eventResult = false;

            yield return(TestHelpers.TestUIClickEventPropagation(
                             scene.sceneData.id,
                             uiImageOnClickEventId,
                             (RectTransform)uiContainer.referencesContainer.image.transform,
                             (bool res) =>
            {
                // Check image object clicking doesn't trigger event
                eventResult = res;
            }));

            Assert.IsFalse(eventResult);

            yield return(null);

            yield return(null);

            yield return(null);

            yield return(null);
        }
Exemple #28
0
        public IEnumerator HorizontalStackIsAppliedCorrectly()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            // Create UIContainerStack
            UIContainerStack uiContainerStack =
                TestHelpers.SharedComponentCreate <UIContainerStack, UIContainerStack.Model>(scene,
                                                                                             CLASS_ID.UI_CONTAINER_STACK);

            yield return(uiContainerStack.routine);

            yield return(TestHelpers.SharedComponentUpdate(uiContainerStack,
                                                           new UIContainerStack.Model
            {
                width = new UIValue(500f),
                height = new UIValue(300f),
                stackOrientation = UIContainerStack.StackOrientation.HORIZONTAL
            }));

            // Check container stack was initialized correctly
            Assert.IsTrue(uiContainerStack != null);

            var layoutGroup = uiContainerStack.referencesContainer.GetComponentInChildren <HorizontalLayoutGroup>();

            Assert.IsTrue(layoutGroup != null);
            Assert.IsFalse(layoutGroup.childControlHeight);
            Assert.IsFalse(layoutGroup.childControlWidth);
            Assert.IsFalse(layoutGroup.childForceExpandWidth);
            Assert.IsFalse(layoutGroup.childForceExpandHeight);

            // Create 1st child object
            UIContainerRect childComponent1 = TestHelpers.SharedComponentCreate <UIContainerRect, UIContainerRect.Model>(
                scene, CLASS_ID.UI_CONTAINER_RECT,
                new UIContainerRect.Model
            {
                parentComponent = uiContainerStack.id,
                width           = new UIValue(130f),
                height          = new UIValue(70f)
            });

            yield return(childComponent1.routine);

            // Create 2nd child object
            UIImage childComponent2 = TestHelpers.SharedComponentCreate <UIImage, UIImage.Model>(scene,
                                                                                                 CLASS_ID.UI_IMAGE_SHAPE,
                                                                                                 new UIImage.Model
            {
                parentComponent = uiContainerStack.id,
                width           = new UIValue(75f),
                height          = new UIValue(35f)
            });

            yield return(childComponent2.routine);

            /// Create 3rd child object
            UIInputText childComponent3 = TestHelpers.SharedComponentCreate <UIInputText, UIInputText.Model>(scene,
                                                                                                             CLASS_ID.UI_INPUT_TEXT_SHAPE,
                                                                                                             new UIInputText.Model
            {
                parentComponent = uiContainerStack.id,
                width           = new UIValue(150f),
                height          = new UIValue(50f)
            });

            yield return(childComponent3.routine);

            RectTransform child1RT = childComponent1.referencesContainer.transform.parent as RectTransform;
            RectTransform child2RT = childComponent2.referencesContainer.transform.parent as RectTransform;
            RectTransform child3RT = childComponent3.referencesContainer.transform.parent as RectTransform;

            Assert.AreEqual(new Vector2(65, -35).ToString(), child1RT.anchoredPosition.ToString());
            Assert.AreEqual(new Vector2(167.5f, -17.5f).ToString(), child2RT.anchoredPosition.ToString());
            Assert.AreEqual(new Vector2(280, -25).ToString(), child3RT.anchoredPosition.ToString());

            Assert.AreEqual(new Vector2(130, 70).ToString(), child1RT.sizeDelta.ToString());
            Assert.AreEqual(new Vector2(75, 35).ToString(), child2RT.sizeDelta.ToString());
            Assert.AreEqual(new Vector2(150, 50).ToString(), child3RT.sizeDelta.ToString());

            screenSpaceShape.Dispose();
            yield return(null);
        }
Exemple #29
0
        public IEnumerator AdaptSizeIsAppliedCorrectly()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            // Create UIContainerStack
            UIContainerStack uiContainerStack =
                TestHelpers.SharedComponentCreate <UIContainerStack, UIContainerStack.Model>(scene,
                                                                                             CLASS_ID.UI_CONTAINER_STACK,
                                                                                             new UIContainerStack.Model
            {
                width  = new UIValue(500f),
                height = new UIValue(300f)
            });

            yield return(uiContainerStack.routine);

            // Create 1st child object
            UIContainerRect childComponent1 = TestHelpers.SharedComponentCreate <UIContainerRect, UIContainerRect.Model>(
                scene, CLASS_ID.UI_CONTAINER_RECT,
                new UIContainerRect.Model
            {
                parentComponent = uiContainerStack.id,
                width           = new UIValue(130f),
                height          = new UIValue(70f)
            });

            yield return(childComponent1.routine);

            // Create 2nd child object
            UIImage childComponent2 = TestHelpers.SharedComponentCreate <UIImage, UIImage.Model>(scene,
                                                                                                 CLASS_ID.UI_IMAGE_SHAPE,
                                                                                                 new UIImage.Model
            {
                parentComponent = uiContainerStack.id,
                width           = new UIValue(75f),
                height          = new UIValue(35f)
            });

            yield return(childComponent2.routine);

            // Create 3rd child object
            UIInputText childComponent3 = TestHelpers.SharedComponentCreate <UIInputText, UIInputText.Model>(scene,
                                                                                                             CLASS_ID.UI_INPUT_TEXT_SHAPE,
                                                                                                             new UIInputText.Model
            {
                parentComponent = uiContainerStack.id,
                width           = new UIValue(150f),
                height          = new UIValue(50f)
            });

            yield return(childComponent3.routine);


            yield return(TestHelpers.SharedComponentUpdate(uiContainerStack,
                                                           new UIContainerStack.Model
            {
                adaptHeight = true,
                adaptWidth = true,
            }));

            yield return(null);

            // Check stacked components position
            Assert.AreEqual(150f, uiContainerStack.childHookRectTransform.rect.width, 0.01f);
            Assert.AreEqual(
                childComponent1.referencesContainer.rectTransform.rect.height + childComponent2.referencesContainer
                .rectTransform.rect.height
                + childComponent3.referencesContainer
                .rectTransform.rect.height,
                uiContainerStack.childHookRectTransform.rect.height, 0.01f);

            screenSpaceShape.Dispose();
            yield return(null);
        }
        public IEnumerator TestPropertiesAreAppliedCorrectly()
        {
            // Create UIScreenSpaceShape
            UIScreenSpace screenSpaceShape =
                TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene,
                                                                                       CLASS_ID.UI_SCREEN_SPACE_SHAPE);

            yield return(screenSpaceShape.routine);

            UIScrollRect scrRect =
                TestHelpers.SharedComponentCreate <UIScrollRect, UIScrollRect.Model>(scene, CLASS_ID.UI_SLIDER_SHAPE);

            yield return(scrRect.routine);

            // Force a new update to pass the first apply
            yield return(TestHelpers.SharedComponentUpdate(scrRect, new UIScrollRect.Model
            {
                name = "newName"
            }));

            var refC = scrRect.referencesContainer;

            Assert.IsTrue(refC.canvasGroup.blocksRaycasts);
            //Canvas group is disabled on first apply
            Assert.AreEqual(1, refC.canvasGroup.alpha);

            // Apply padding
            Assert.AreEqual(0, refC.paddingLayoutGroup.padding.bottom);
            Assert.AreEqual(0, refC.paddingLayoutGroup.padding.top);
            Assert.AreEqual(0, refC.paddingLayoutGroup.padding.left);
            Assert.AreEqual(0, refC.paddingLayoutGroup.padding.right);

            Assert.IsFalse(refC.scrollRect.horizontal);
            Assert.IsTrue(refC.scrollRect.vertical);

            Assert.AreEqual(0, refC.HScrollbar.value);
            Assert.AreEqual(0, refC.VScrollbar.value);

            // Update UIScrollRect properties
            yield return(TestHelpers.SharedComponentUpdate(scrRect,
                                                           new UIScrollRect.Model
            {
                parentComponent = screenSpaceShape.id,
                isPointerBlocker = false,
                width = new UIValue(275f),
                height = new UIValue(130f),
                positionX = new UIValue(-30f),
                positionY = new UIValue(-15f),
                hAlign = "right",
                vAlign = "bottom"
            }));

            // Check updated properties are applied correctly
            Assert.IsTrue(scrRect.referencesContainer.transform.parent == screenSpaceShape.childHookRectTransform);
            Assert.IsFalse(scrRect.referencesContainer.canvasGroup.blocksRaycasts);
            Assert.AreEqual(275f, scrRect.childHookRectTransform.rect.width);
            Assert.AreEqual(130f, scrRect.childHookRectTransform.rect.height);
            Assert.IsTrue(scrRect.referencesContainer.layoutGroup.childAlignment == TextAnchor.LowerRight);

            Vector2 alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
                                                                       scrRect.childHookRectTransform.rect, "bottom", "right");

            alignedPosition += new Vector2(-30, -15); // apply offset position

            Assert.AreEqual(alignedPosition.ToString(),
                            scrRect.referencesContainer.layoutElementRT.anchoredPosition.ToString());

            screenSpaceShape.Dispose();
        }