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();
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }