Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }