public IEnumerator WorkCorrectlyWhenAttachedBeforeShape()
    {
        IDCLEntity entity = TestHelpers.CreateSceneEntity(scene);

        DCLTexture dclTexture = TestHelpers.CreateDCLTexture(
            scene,
            TestAssetsUtils.GetPath() + "/Images/atlas.png",
            DCLTexture.BabylonWrapMode.CLAMP,
            FilterMode.Bilinear);

        yield return(dclTexture.routine);

        BasicMaterial mat = TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>
                                (scene, CLASS_ID.BASIC_MATERIAL,
                                new BasicMaterial.Model
        {
            texture   = dclTexture.id,
            alphaTest = 0.5f
        });

        yield return(mat.routine);

        TestHelpers.SharedComponentAttach(mat, entity);

        SphereShape shape = TestHelpers.SharedComponentCreate <SphereShape, SphereShape.Model>(scene,
                                                                                               CLASS_ID.SPHERE_SHAPE,
                                                                                               new SphereShape.Model {
        });

        TestHelpers.SharedComponentAttach(shape, entity);

        Assert.IsTrue(entity.meshRootGameObject != null);
        Assert.IsTrue(entity.meshRootGameObject.GetComponent <MeshRenderer>() != null);
        Assert.AreEqual(entity.meshRootGameObject.GetComponent <MeshRenderer>().sharedMaterial, mat.material);
    }
    public IEnumerator NotDestroySharedTextureWhenDisposed()
    {
        DCLTexture texture =
            TestHelpers.CreateDCLTexture(scene, TestAssetsUtils.GetPath() + "/Images/atlas.png");

        yield return(texture.routine);

        BasicMaterial mat = TestHelpers.CreateEntityWithBasicMaterial(scene,
                                                                      new BasicMaterial.Model
        {
            texture   = texture.id,
            alphaTest = 1,
        },
                                                                      out IDCLEntity entity1);

        yield return(mat.routine);

        BasicMaterial mat2 = TestHelpers.CreateEntityWithBasicMaterial(scene,
                                                                       new BasicMaterial.Model
        {
            texture   = texture.id,
            alphaTest = 1,
        },
                                                                       out IDCLEntity entity2);

        yield return(mat2.routine);

        TestHelpers.SharedComponentDispose(mat);
        Assert.IsTrue(texture.texture != null, "Texture should persist because is used by the other material!!");
    }
Esempio n. 3
0
        public IEnumerator VideoTextureReplaceOtherTextureCorrectly()
        {
            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");

            yield return(videoTexture.routine);

            Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, "DCLVideoTexture started with attachedMaterials != 0");

            DCLTexture dclTexture = TestHelpers.CreateDCLTexture(
                scene,
                Utils.GetTestsAssetsPath() + "/Images/atlas.png",
                DCLTexture.BabylonWrapMode.CLAMP,
                FilterMode.Bilinear);

            yield return(dclTexture.routine);

            BasicMaterial mat = TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>
                                    (scene, CLASS_ID.BASIC_MATERIAL,
                                    new BasicMaterial.Model
            {
                texture = dclTexture.id
            });

            yield return(mat.routine);

            yield return(TestHelpers.SharedComponentUpdate <BasicMaterial, BasicMaterial.Model>(mat, new BasicMaterial.Model()
            {
                texture = videoTexture.id
            }));

            Assert.IsTrue(videoTexture.attachedMaterials.Count == 1, $"did DCLVideoTexture attach to material? {videoTexture.attachedMaterials.Count} expected 1");
        }
Esempio n. 4
0
    public IEnumerator AlphaTextureShouldWork()
    {
        yield return(InitVisualTestsScene("PBRMaterialVisualTests_AlphaTextureShouldWork"));

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

        yield return(texture.routine);

        Vector3 camTarget = new Vector3(5, 2, 5);

        VisualTestHelpers.RepositionVisualTestsCamera(VisualTestController.i.camera, camTarget - new Vector3(2, -1, 2), camTarget);

        PBRMaterial matPBR = TestHelpers.CreateEntityWithPBRMaterial(scene, new PBRMaterial.Model
        {
            albedoTexture    = texture.id,
            transparencyMode = 2,
            albedoColor      = Color.blue
        }, camTarget, out DecentralandEntity entity);

        yield return(matPBR.routine);


        yield return(new WaitForAllMessagesProcessed());

        yield return(VisualTestHelpers.TakeSnapshot());
    }
Esempio n. 5
0
 bool AreSameTextureComponent(DCLTexture dclTexture, string textureId)
 {
     if (dclTexture == null)
     {
         return(false);
     }
     return(dclTexture.id == textureId);
 }
Esempio n. 6
0
        public override void Dispose()
        {
            dclTexture?.DetachFrom(this);
            dclTexture = null;

            Utils.SafeDestroy(referencesContainer.gameObject);

            base.Dispose();
        }
        public void Texture_OnReadyBeforeLoading()
        {
            DCLTexture dclTexture = TestHelpers.CreateDCLTexture(scene, DCL.Helpers.Utils.GetTestsAssetsPath() + "/Images/avatar.png");
            bool       isOnReady  = false;

            dclTexture.CallWhenReady((x) => { isOnReady = true; });

            Assert.IsTrue(isOnReady); //DCLTexture is ready on creation
        }
        public IEnumerator Texture_OnReadyWaitLoading()
        {
            DCLTexture dclTexture = TestHelpers.CreateDCLTexture(scene, DCL.Helpers.Utils.GetTestsAssetsPath() + "/Images/avatar.png");
            bool       isOnReady  = false;

            dclTexture.CallWhenReady((x) => { isOnReady = true; });
            yield return(dclTexture.routine);

            Assert.IsTrue(isOnReady);
        }
        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));
        }
Esempio n. 10
0
        public IEnumerator Texture_OnReadyAfterLoadingInstantlyCalled()
        {
            DCLTexture dclTexture = TestHelpers.CreateDCLTexture(scene, TestAssetsUtils.GetPath() + "/Images/avatar.png");

            yield return(dclTexture.routine);

            bool isOnReady = false;

            dclTexture.CallWhenReady((x) => { isOnReady = true; });
            Assert.IsTrue(isOnReady);
        }
Esempio n. 11
0
        public override void Dispose()
        {
            dclTexture?.DetachFrom(this);
            dclTexture = null;

            if (material != null)
            {
                GameObject.Destroy(material);
            }

            base.Dispose();
        }
Esempio n. 12
0
        public override IEnumerator ApplyChanges(BaseModel newModel)
        {
            RectTransform parentRecTransform = referencesContainer.GetComponentInParent <RectTransform>();

            // Fetch texture
            if (!string.IsNullOrEmpty(model.source))
            {
                if (dclTexture == null || (dclTexture != null && dclTexture.id != model.source))
                {
                    if (fetchRoutine != null)
                    {
                        CoroutineStarter.Stop(fetchRoutine);
                        fetchRoutine = null;
                    }

                    IEnumerator fetchIEnum = DCLTexture.FetchTextureComponent(scene, model.source, (downloadedTexture) =>
                    {
                        referencesContainer.image.texture = downloadedTexture.texture;
                        fetchRoutine = null;
                        dclTexture?.DetachFrom(this);
                        dclTexture = downloadedTexture;
                        dclTexture.AttachTo(this);

                        ConfigureUVRect(parentRecTransform);
                    });

                    fetchRoutine = CoroutineStarter.Start(fetchIEnum);
                }
            }
            else
            {
                referencesContainer.image.texture = null;
                dclTexture?.DetachFrom(this);
                dclTexture = null;
            }

            referencesContainer.image.enabled = model.visible;
            referencesContainer.image.color   = Color.white;

            ConfigureUVRect(parentRecTransform);

            // Apply padding
            referencesContainer.paddingLayoutGroup.padding.bottom = Mathf.RoundToInt(model.paddingBottom);
            referencesContainer.paddingLayoutGroup.padding.top    = Mathf.RoundToInt(model.paddingTop);
            referencesContainer.paddingLayoutGroup.padding.left   = Mathf.RoundToInt(model.paddingLeft);
            referencesContainer.paddingLayoutGroup.padding.right  = Mathf.RoundToInt(model.paddingRight);

            Utils.ForceRebuildLayoutImmediate(parentRecTransform);
            return(null);
        }
Esempio n. 13
0
        public override void Dispose()
        {
            albedoDCLTexture?.DetachFrom(this);
            emissiveDCLTexture?.DetachFrom(this);
            bumpDCLTexture?.DetachFrom(this);

            albedoDCLTexture   = null;
            emissiveDCLTexture = null;
            bumpDCLTexture     = null;

            if (material != null)
            {
                GameObject.Destroy(material);
            }

            base.Dispose();
        }
    public IEnumerator UIImageTest1()
    {
        yield return(InitUIVisualTestScene("UIImageTest"));

        string mainContainerId = "herodes";

        yield return(CreateUIComponent <UIContainerRect, UIContainerRect.Model>(CLASS_ID.UI_CONTAINER_RECT, new UIContainerRect.Model
        {
            parentComponent = screenSpaceId,
            color = Color.green,
            width = new UIValue(50f, UIValue.Unit.PERCENT),
            height = new UIValue(50f, UIValue.Unit.PERCENT)
        }, mainContainerId));

        yield return(CreateUIComponent <UIContainerRect, UIContainerRect.Model>(CLASS_ID.UI_CONTAINER_RECT, new UIContainerRect.Model
        {
            parentComponent = mainContainerId,
            color = Color.red,
            width = new UIValue(128f),
            height = new UIValue(128f)
        }, "imageBack"));

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

        yield return(texture.routine);

        yield return(CreateUIComponent <UIImage, UIImage.Model>(CLASS_ID.UI_IMAGE_SHAPE, new UIImage.Model
        {
            parentComponent = mainContainerId,
            source = texture.id,
            width = new UIValue(128f),
            height = new UIValue(128f),
            sourceWidth = 128f,
            sourceHeight = 128f,
            sourceTop = 0f,
            sourceLeft = 0f,
            paddingLeft = 10f,
            paddingRight = 10f,
            paddingTop = 10f,
            paddingBottom = 10f,
            isPointerBlocker = true,
        }, "testUIImage"));

        yield return(VisualTestHelpers.TakeSnapshot(new Vector3(0f, 2f, 0f)));
    }
Esempio n. 15
0
        public override IEnumerator ApplyChanges(BaseModel newModel)
        {
            if (material == null)
            {
                yield break; // We escape ApplyChanges called in the parent's constructor
            }

#if UNITY_EDITOR
            material.name = "BasicMaterial_" + id;
#endif

            Model model = (Model)newModel;

            if (!string.IsNullOrEmpty(model.texture))
            {
                if (dclTexture == null || dclTexture.id != model.texture)
                {
                    yield return(DCLTexture.FetchTextureComponent(scene, model.texture, (downloadedTexture) =>
                    {
                        dclTexture?.DetachFrom(this);
                        material.SetTexture(_BaseMap, downloadedTexture.texture);
                        dclTexture = downloadedTexture;
                        dclTexture.AttachTo(this);
                    }));
                }
            }
            else
            {
                material.mainTexture = null;
                dclTexture?.DetachFrom(this);
                dclTexture = null;
            }

            material.EnableKeyword("_ALPHATEST_ON");
            material.SetInt(_ZWrite, 1);
            material.SetFloat(_AlphaClip, 1);
            material.SetFloat(_Cutoff, model.alphaTest);
            material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;

            foreach (IDCLEntity decentralandEntity in attachedEntities)
            {
                InitMaterial(decentralandEntity.meshRootGameObject);
            }
        }
        public IEnumerator TextureCreateAndLoadTest()
        {
            DCLTexture dclTexture = TestHelpers.CreateDCLTexture(scene,
                                                                 Utils.GetTestsAssetsPath() + "/Images/avatar.png",
                                                                 DCLTexture.BabylonWrapMode.CLAMP,
                                                                 FilterMode.Bilinear);

            yield return(dclTexture.routine);

            Assert.IsTrue(dclTexture.texture != null, "Texture didn't load correctly?");
            Assert.IsTrue(dclTexture.unityWrap == TextureWrapMode.Clamp, "Bad wrap mode!");
            Assert.IsTrue(dclTexture.unitySamplingMode == FilterMode.Bilinear, "Bad sampling mode!");

            dclTexture.Dispose();

            yield return(null);

            Assert.IsTrue(dclTexture.texture == null, "Texture didn't dispose correctly?");
        }
    public IEnumerator Emission_AlphaTexture_AlbedoAlpha(float alpha, float emissiveIntensity)
    {
        yield return(InitVisualTestsScene($"PBRMaterialVisualTests_Emission_AlphaTexture_AlbedoAlpha_{alpha.ToString(CultureInfo.InvariantCulture)}_{emissiveIntensity.ToString(CultureInfo.InvariantCulture)}"));

        VisualTestHelpers.SetSSAOActive(true);

        Vector3 camTarget = new Vector3(5, 1, 5);

        VisualTestHelpers.RepositionVisualTestsCamera(VisualTestController.i.camera, new Vector3(4.6f, 1.8f, 0.6f), camTarget);

        DCLTexture texture         = TestHelpers.CreateDCLTexture(scene, TestAssetsUtils.GetPath() + "/Images/avatar.png");
        DCLTexture alphaTexture    = TestHelpers.CreateDCLTexture(scene, TestAssetsUtils.GetPath() + "/Images/alphaTexture.png");
        DCLTexture emissionTexture = TestHelpers.CreateDCLTexture(scene, TestAssetsUtils.GetPath() + "/Images/Gradient A4.png");

        yield return(texture.routine);

        yield return(alphaTexture.routine);

        yield return(emissionTexture.routine);

        PlaneShape plane       = TestHelpers.CreateEntityWithPlaneShape(scene, new Vector3(5, 1, 5), true);
        IDCLEntity planeEntity = plane.attachedEntities.FirstOrDefault();

        TestHelpers.SetEntityTransform(scene, planeEntity, new Vector3(5, 1, 5), Quaternion.Euler(0, 0, 180), Vector3.one * 3);
        PBRMaterial planeMaterial = TestHelpers.AttachPBRMaterialToEntity(scene, planeEntity, new PBRMaterial.Model
        {
            albedoColor       = new Color(1, 1, 1, alpha),
            transparencyMode  = 2,
            albedoTexture     = texture.id,
            alphaTexture      = alphaTexture.id,
            emissiveColor     = Color.blue,
            emissiveIntensity = emissiveIntensity,
            emissiveTexture   = emissionTexture.id
        });

        yield return(plane.routine);

        yield return(planeMaterial.routine);

        yield return(null);

        yield return(VisualTestHelpers.TakeSnapshot());
    }
Esempio n. 18
0
 void SetMaterialTexture(int materialPropertyId, string textureComponentId, DCLTexture cachedDCLTexture)
 {
     if (!string.IsNullOrEmpty(textureComponentId))
     {
         if (!AreSameTextureComponent(cachedDCLTexture, textureComponentId))
         {
             CoroutineStarter.Start(DCLTexture.FetchTextureComponent(scene, textureComponentId,
                                                                     (fetchedDCLTexture) =>
             {
                 material.SetTexture(materialPropertyId, fetchedDCLTexture.texture);
                 SwitchTextureComponent(cachedDCLTexture, fetchedDCLTexture);
             }));
         }
     }
     else
     {
         material.SetTexture(materialPropertyId, null);
         cachedDCLTexture?.DetachFrom(this);
     }
 }
Esempio n. 19
0
    public IEnumerator WorkCorrectlyWhenAttachedBeforeShape()
    {
        DecentralandEntity entity = TestHelpers.CreateSceneEntity(scene);

        DCLTexture dclTexture = TestHelpers.CreateDCLTexture(
            scene,
            Utils.GetTestsAssetsPath() + "/Images/atlas.png",
            DCLTexture.BabylonWrapMode.CLAMP,
            FilterMode.Bilinear);

        yield return(dclTexture.routine);

        PBRMaterial mat = TestHelpers.SharedComponentCreate <PBRMaterial, PBRMaterial.Model>(scene,
                                                                                             CLASS_ID.PBR_MATERIAL,
                                                                                             new PBRMaterial.Model
        {
            albedoTexture = dclTexture.id,
            metallic      = 0,
            roughness     = 1,
        }
                                                                                             );

        yield return(mat.routine);

        TestHelpers.SharedComponentAttach(mat, entity);

        SphereShape shape = TestHelpers.SharedComponentCreate <SphereShape, SphereShape.Model>(scene,
                                                                                               CLASS_ID.SPHERE_SHAPE,
                                                                                               new SphereShape.Model {
        });

        yield return(shape.routine);

        TestHelpers.SharedComponentAttach(shape, entity);

        Assert.IsTrue(entity.meshRootGameObject != null);
        Assert.IsTrue(entity.meshRootGameObject.GetComponent <MeshRenderer>() != null);
        Assert.AreEqual(entity.meshRootGameObject.GetComponent <MeshRenderer>().sharedMaterial, mat.material);
    }
Esempio n. 20
0
        public IEnumerator PBRMaterialUpdate()
        {
            DCLTexture texture =
                TestHelpers.CreateDCLTexture(scene, Utils.GetTestsAssetsPath() + "/Images/atlas.png");

            yield return(texture.routine);

            DecentralandEntity entity = null;

            PBRMaterial matPBR = TestHelpers.CreateEntityWithPBRMaterial(scene,
                                                                         new PBRMaterial.Model
            {
                albedoTexture = texture.id,
                metallic      = 0,
                roughness     = 1,
            },
                                                                         out entity);

            yield return(matPBR.routine);

            {
                Assert.IsTrue(entity.meshRootGameObject != null,
                              "Every entity with a shape should have the mandatory 'Mesh' object as a child");

                var meshRenderer = entity.meshRootGameObject.GetComponent <MeshRenderer>();
                Assert.IsTrue(meshRenderer != null, "MeshRenderer must exist");

                var assignedMaterial = meshRenderer.sharedMaterial;
                Assert.IsTrue(meshRenderer != null, "MeshRenderer.sharedMaterial must be the same as assignedMaterial");
                Assert.AreEqual(assignedMaterial, matPBR.material, "Assigned material");

                var loadedTexture = meshRenderer.sharedMaterial.GetTexture("_BaseMap");
                Assert.IsTrue(loadedTexture != null, "Texture must be loaded");
                Assert.AreEqual(texture.texture, loadedTexture, "Texture data must be correct");
            }
        }
        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);
        }
    void Start()
    {
        var sceneController = FindObjectOfType <SceneController>();
        var scenesToLoad    = (Resources.Load("TestJSON/SceneLoadingTest") as TextAsset).text;

        sceneController.UnloadAllScenes();
        sceneController.LoadParcelScenes(scenesToLoad);

        var scene = sceneController.loadedScenes["0,0"];

        DCLTexture dclAtlasTexture = TestHelpers.CreateDCLTexture(
            scene,
            Utils.GetTestsAssetsPath() + "/Images/atlas.png",
            DCLTexture.BabylonWrapMode.CLAMP,
            FilterMode.Bilinear);

        DCLTexture dclAvatarTexture = TestHelpers.CreateDCLTexture(
            scene,
            Utils.GetTestsAssetsPath() + "/Images/avatar.png",
            DCLTexture.BabylonWrapMode.CLAMP,
            FilterMode.Bilinear);


        DecentralandEntity entity;

        TestHelpers.CreateEntityWithBasicMaterial(
            scene,
            new BasicMaterial.Model
        {
            texture = dclAtlasTexture.id,
        },
            out entity);

        TestHelpers.CreateEntityWithPBRMaterial(scene,
                                                new PBRMaterial.Model
        {
            albedoTexture = dclAvatarTexture.id,
            metallic      = 0,
            roughness     = 1,
        },
                                                out entity);

        PBRMaterial mat = TestHelpers.CreateEntityWithPBRMaterial(scene,
                                                                  new PBRMaterial.Model
        {
            albedoTexture = dclAvatarTexture.id,
            metallic      = 1,
            roughness     = 1,
            alphaTexture  = dclAvatarTexture.id,
        },
                                                                  out entity);

        // Re-assign last PBR material to new entity
        BoxShape      shape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(5, 1, 2));
        BasicMaterial m     =
            TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>(scene, CLASS_ID.BASIC_MATERIAL);

        Color color1;

        ColorUtility.TryParseHtmlString("#FF9292", out color1);

        // Update material attached to 2 entities, adding albedoColor
        scene.SharedComponentUpdate(m.id, JsonUtility.ToJson(new DCL.Components.PBRMaterial.Model
        {
            albedoTexture = dclAvatarTexture.id,
            metallic      = 1,
            roughness     = 1,
            alphaTexture  = dclAvatarTexture.id,
            albedoColor   = color1
        }));
    }
Esempio n. 25
0
 void SwitchTextureComponent(DCLTexture cachedTexture, DCLTexture newTexture)
 {
     cachedTexture?.DetachFrom(this);
     cachedTexture = newTexture;
     cachedTexture.AttachTo(this);
 }
Esempio n. 26
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);
        }
Esempio n. 27
0
    public IEnumerator BeUpdatedProperly()
    {
        string entityId   = "1";
        string materialID = "a-material";

        // Instantiate entity with default PBR Material
        TestHelpers.InstantiateEntityWithMaterial(scene, entityId, Vector3.zero,
                                                  new PBRMaterial.Model(), materialID);

        var materialComponent = scene.disposableComponents[materialID] as DCL.Components.PBRMaterial;

        yield return(materialComponent.routine);

        Assert.IsTrue(materialComponent is DCL.Components.PBRMaterial, "material is PBRMaterial");

        // Check if material initialized correctly
        {
            Assert.IsTrue(scene.entities[entityId].meshRootGameObject != null,
                          "Every entity with a shape should have the mandatory 'Mesh' object as a child");

            var meshRenderer = scene.entities[entityId].meshRootGameObject.GetComponent <MeshRenderer>();

            Assert.IsTrue(meshRenderer != null, "MeshRenderer must exist");

            var assignedMaterial = meshRenderer.sharedMaterial;
            Assert.IsTrue(meshRenderer != null, "MeshRenderer.sharedMaterial must be the same as assignedMaterial");

            Assert.AreEqual(assignedMaterial, materialComponent.material, "Assigned material");
        }

        // Check default properties
        {
            // Texture
            Assert.IsTrue(materialComponent.material.GetTexture("_BaseMap") == null);

            // Colors
            Assert.AreEqual("FFFFFF", ColorUtility.ToHtmlStringRGB(materialComponent.material.GetColor("_BaseColor")));
            Assert.AreEqual("000000",
                            ColorUtility.ToHtmlStringRGB(materialComponent.material.GetColor("_EmissionColor")));
            Assert.AreEqual("FFFFFF",
                            ColorUtility.ToHtmlStringRGB(materialComponent.material.GetColor("_SpecColor")));

            // Other properties
            Assert.AreApproximatelyEqual(0.5f, materialComponent.material.GetFloat("_Metallic"));
            Assert.AreApproximatelyEqual(0.5f, materialComponent.material.GetFloat("_Smoothness"));
            Assert.AreApproximatelyEqual(1.0f, materialComponent.material.GetFloat("_EnvironmentReflections"));
            Assert.AreApproximatelyEqual(1.0f, materialComponent.material.GetFloat("_SpecularHighlights"));
            Assert.AreApproximatelyEqual(.0f, materialComponent.material.GetFloat("_AlphaClip"));
        }

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

        yield return(texture.routine);

        Color color1, color2, color3;

        ColorUtility.TryParseHtmlString("#99deff", out color1);
        ColorUtility.TryParseHtmlString("#42f4aa", out color2);
        ColorUtility.TryParseHtmlString("#601121", out color3);

        scene.SharedComponentUpdate(materialID, JsonUtility.ToJson(new DCL.Components.PBRMaterial.Model
        {
            albedoTexture     = texture.id,
            albedoColor       = color1,
            emissiveColor     = color2,
            emissiveIntensity = 1,
            reflectivityColor = color3,
            metallic          = 0.37f,
            roughness         = 0.9f,
            microSurface      = 0.4f,
            specularIntensity = 2f,
            transparencyMode  = 2,
        }));

        yield return(materialComponent.routine);

        // Check updated properties
        {
            // Texture
            Assert.IsTrue(materialComponent.material.GetTexture("_BaseMap") != null, "texture is null!");

            // Colors
            Assert.AreEqual("99DEFF", ColorUtility.ToHtmlStringRGB(materialComponent.material.GetColor("_BaseColor")));
            Assert.AreEqual("42F4AA",
                            ColorUtility.ToHtmlStringRGB(materialComponent.material.GetColor("_EmissionColor")));
            Assert.AreEqual("601121",
                            ColorUtility.ToHtmlStringRGB(materialComponent.material.GetColor("_SpecColor")));

            // Other properties
            Assert.AreApproximatelyEqual(0.37f, materialComponent.material.GetFloat("_Metallic"));
            Assert.AreApproximatelyEqual(0.1f, materialComponent.material.GetFloat("_Smoothness"));
            Assert.AreApproximatelyEqual(0.4f, materialComponent.material.GetFloat("_EnvironmentReflections"));
            Assert.AreApproximatelyEqual(2.0f, materialComponent.material.GetFloat("_SpecularHighlights"));
            Assert.AreApproximatelyEqual(.0f, materialComponent.material.GetFloat("_AlphaClip"));
            Assert.AreEqual((int)UnityEngine.Rendering.BlendMode.SrcAlpha,
                            materialComponent.material.GetInt("_SrcBlend"));
            Assert.AreEqual((int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha,
                            materialComponent.material.GetInt("_DstBlend"));
            Assert.AreEqual(0, materialComponent.material.GetInt("_ZWrite"));
        }
    }
Esempio n. 28
0
    public IEnumerator EntityBasicMaterialUpdate()
    {
        string entityId   = "1";
        string materialID = "a-material";

        Assert.IsFalse(scene.disposableComponents.ContainsKey(materialID));

        // Instantiate entity with default material
        TestHelpers.InstantiateEntityWithMaterial(scene, entityId, new Vector3(8, 1, 8),
                                                  new BasicMaterial.Model(), materialID);

        var meshObject = scene.entities[entityId].meshRootGameObject;

        Assert.IsTrue(meshObject != null,
                      "Every entity with a shape should have the mandatory 'Mesh' object as a child");

        var meshRenderer      = meshObject.GetComponent <MeshRenderer>();
        var materialComponent = scene.disposableComponents[materialID] as BasicMaterial;

        yield return(materialComponent.routine);

        // Check if material initialized correctly
        {
            Assert.IsTrue(meshRenderer != null, "MeshRenderer must exist");

            var assignedMaterial = meshRenderer.sharedMaterial;
            Assert.IsTrue(meshRenderer != null, "MeshRenderer.sharedMaterial must be the same as assignedMaterial");

            Assert.AreEqual(assignedMaterial, materialComponent.material, "Assigned material");
        }

        // Check default properties
        {
            Assert.IsTrue(materialComponent.material.GetTexture("_BaseMap") == null);
            Assert.AreApproximatelyEqual(1.0f, materialComponent.material.GetFloat("_AlphaClip"));
        }

        DCLTexture dclTexture = TestHelpers.CreateDCLTexture(
            scene,
            Utils.GetTestsAssetsPath() + "/Images/atlas.png",
            DCLTexture.BabylonWrapMode.MIRROR,
            FilterMode.Bilinear);

        // Update material
        scene.SharedComponentUpdate(materialID, JsonUtility.ToJson(new BasicMaterial.Model
        {
            texture   = dclTexture.id,
            alphaTest = 0.5f,
        }));

        yield return(materialComponent.routine);

        // Check updated properties
        {
            Texture mainTex = materialComponent.material.GetTexture("_BaseMap");
            Assert.IsTrue(mainTex != null);
            Assert.AreApproximatelyEqual(0.5f, materialComponent.material.GetFloat("_Cutoff"));
            Assert.AreApproximatelyEqual(1.0f, materialComponent.material.GetFloat("_AlphaClip"));
            Assert.AreEqual(TextureWrapMode.Mirror, mainTex.wrapMode);
            Assert.AreEqual(FilterMode.Bilinear, mainTex.filterMode);
        }
    }
Esempio n. 29
0
    public IEnumerator UIContainerStackTest1()
    {
        yield return(InitUIVisualTestScene("UIContainerStackTest"));

        string mainContainerId = "herodes";

        yield return(CreateUIComponent <UIContainerStack, UIContainerStack.Model>(CLASS_ID.UI_CONTAINER_STACK, new UIContainerStack.Model
        {
            parentComponent = screenSpaceId,
            color = Color.green,
            width = new UIValue(50f, UIValue.Unit.PERCENT),
            height = new UIValue(50f, UIValue.Unit.PERCENT)
        }, mainContainerId));

        yield return(CreateUIComponent <UIContainerRect, UIContainerRect.Model>(CLASS_ID.UI_CONTAINER_RECT, new UIContainerRect.Model
        {
            parentComponent = mainContainerId,
            color = Color.blue,
            width = new UIValue(200f),
            height = new UIValue(200f)
        }, "testContainerRect1"));

        DCLTexture texture = TestHelpers.CreateDCLTexture(scene, TestAssetsUtils.GetPath() + "/Images/atlas.png");

        yield return(texture.routine);

        yield return(CreateUIComponent <UIImage, UIImage.Model>(CLASS_ID.UI_IMAGE_SHAPE, new UIImage.Model
        {
            parentComponent = mainContainerId,
            source = texture.id,
            width = new UIValue(100f),
            height = new UIValue(100f),
            positionX = new UIValue(20f),
            sourceWidth = 100f,
            sourceHeight = 100f
        }, "testUIImage"));

        string mainContainer2Id = "herodes2";

        yield return(CreateUIComponent <UIContainerStack, UIContainerStack.Model>(CLASS_ID.UI_CONTAINER_STACK, new UIContainerStack.Model
        {
            parentComponent = mainContainerId,
            color = Color.red,
            stackOrientation = UIContainerStack.StackOrientation.HORIZONTAL,
            positionX = new UIValue(20f),
            positionY = new UIValue(20f),
            width = new UIValue(200f),
            height = new UIValue(200f)
        }, mainContainer2Id));

        yield return(CreateUIComponent <UIContainerRect, UIContainerRect.Model>(CLASS_ID.UI_CONTAINER_RECT, new UIContainerRect.Model
        {
            parentComponent = mainContainer2Id,
            color = Color.blue,
            width = new UIValue(200f),
            height = new UIValue(200f),
            positionY = new UIValue(0f)
        }, "testContainerRect2"));

        yield return(CreateUIComponent <UIContainerRect, UIContainerRect.Model>(CLASS_ID.UI_CONTAINER_RECT, new UIContainerRect.Model
        {
            parentComponent = mainContainer2Id,
            color = Color.magenta,
            width = new UIValue(200f),
            height = new UIValue(200f),
            positionY = new UIValue(10f)
        }, "testContainerRect3"));

        yield return(CreateUIComponent <UIContainerRect, UIContainerRect.Model>(CLASS_ID.UI_CONTAINER_RECT, new UIContainerRect.Model
        {
            parentComponent = mainContainer2Id,
            color = Color.yellow,
            width = new UIValue(200f),
            height = new UIValue(200f),
            positionY = new UIValue(20f)
        }, "testContainerRect4"));

        yield return(VisualTestHelpers.TakeSnapshot(new Vector3(0f, 2f, 0f)));
    }
Esempio n. 30
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);
        }