Ejemplo n.º 1
0
 void SetMaterialTexture(int materialPropertyId, string textureComponentId, DCLTexture cachedDCLTexture)
 {
     if (!string.IsNullOrEmpty(textureComponentId))
     {
         if (!AreSameTextureComponent(cachedDCLTexture, textureComponentId))
         {
             CoroutineStarter.Start(DCLTexture.FetchTextureComponent(scene, textureComponentId,
                                                                     (fetchedDCLTexture) =>
             {
                 if (material != null)
                 {
                     material.SetTexture(materialPropertyId, fetchedDCLTexture.texture);
                     SwitchTextureComponent(cachedDCLTexture, fetchedDCLTexture);
                 }
             }));
         }
     }
     else
     {
         material.SetTexture(materialPropertyId, null);
         cachedDCLTexture?.DetachFrom(this);
     }
 }
Ejemplo n.º 2
0
 void SwitchTextureComponent(DCLTexture cachedTexture, DCLTexture newTexture)
 {
     cachedTexture?.DetachFrom(this);
     cachedTexture = newTexture;
     cachedTexture.AttachTo(this);
 }
Ejemplo n.º 3
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);
        }