Esempio n. 1
0
        public override IEnumerator ApplyChanges(string newJson)
        {
            if (material == null)
            {
                yield break; // We escape ApplyChanges called in the parent's constructor
            }

            model = SceneController.i.SafeFromJson <Model>(newJson);

            if (!string.IsNullOrEmpty(model.texture))
            {
                if (dclTexture == null || (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;
        }
Esempio n. 2
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. 3
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);
            }
        }
Esempio n. 4
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. 5
0
        public override IEnumerator ApplyChanges(string newJson)
        {
            // Fetch texture
            if (!string.IsNullOrEmpty(model.source))
            {
                if (dclTexture == null || (dclTexture != null && dclTexture.id != model.source))
                {
                    if (fetchRoutine != null)
                    {
                        scene.StopCoroutine(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);
                    });

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

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

            RectTransform parentRecTransform = referencesContainer.GetComponentInParent <RectTransform>();

            if (referencesContainer.image.texture != null)
            {
                // Configure uv rect
                Vector2 normalizedSourceCoordinates = new Vector2(
                    model.sourceLeft / referencesContainer.image.texture.width,
                    -model.sourceTop / referencesContainer.image.texture.height);


                Vector2 normalizedSourceSize = new Vector2(
                    model.sourceWidth * (model.sizeInPixels ? 1f : parentRecTransform.rect.width) /
                    referencesContainer.image.texture.width,
                    model.sourceHeight * (model.sizeInPixels ? 1f : parentRecTransform.rect.height) /
                    referencesContainer.image.texture.height);

                referencesContainer.image.uvRect = new Rect(normalizedSourceCoordinates.x,
                                                            normalizedSourceCoordinates.y + (1 - normalizedSourceSize.y),
                                                            normalizedSourceSize.x,
                                                            normalizedSourceSize.y);
            }

            // 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);

            LayoutRebuilder.ForceRebuildLayoutImmediate(parentRecTransform);
            return(null);
        }