Ejemplo n.º 1
0
    private void DrawDuplicateMaterial(string errorMessage = null)
    {
        var showError = string.IsNullOrEmpty(errorMessage) == false;

        BeginError(showError);
        {
            if (showError == true)
            {
                EditorGUILayout.HelpBox(errorMessage, MessageType.Error);
            }

            BeginColor(showError == true ? Color.green : GUI.color);
            {
                if (Button("Duplicate") == true)
                {
                    materials[currentMaterialIndex] = currentMaterial = P3D_Helper.Clone(currentMaterial);

                    lockedRenderer.sharedMaterials = materials;

                    P3D_Helper.SetDirty(this);
                }
            }
            EndColor();
        }
        EndError();
    }
Ejemplo n.º 2
0
    public void Awake(GameObject gameObject)
    {
        if (DuplicateOnAwake == true)
        {
            // Get cloned material
            var material = P3D_Helper.CloneMaterial(gameObject, MaterialIndex);

            if (material != null)
            {
                // Get texture
                var texture = material.GetTexture(TextureName);

                if (texture != null)
                {
                    // Clone material
                    texture = P3D_Helper.Clone(texture);

                    // Update material
                    material.SetTexture(TextureName, texture);
                }
            }
        }

        if (CreateOnAwake == true && CreateWidth > 0 && CreateHeight > 0)
        {
            var material = P3D_Helper.GetMaterial(gameObject, MaterialIndex);

            if (material != null)
            {
                var texture    = material.GetTexture(TextureName);
                var format     = P3D_Helper.GetTextureFormat(CreateFormat);
                var newTexture = P3D_Helper.CreateTexture(CreateWidth, CreateHeight, format, CreateMipMaps);

                if (texture != null)
                {
                    Debug.LogWarning("There is already a texture in this texture slot, maybe set it to null to save memory?", gameObject);
                }

                texture = newTexture;

                P3D_Helper.ClearTexture(newTexture, CreateColor, true);

                material.SetTexture(TextureName, texture);

                // Enable a keyword?
                if (string.IsNullOrEmpty(CreateKeyword) == false)
                {
                    material.EnableKeyword(CreateKeyword);
                }
            }
        }

        UpdateTexture(gameObject);
    }
Ejemplo n.º 3
0
 public void Awake(GameObject gameObject)
 {
     if (this.DuplicateOnAwake)
     {
         Material material = P3D_Helper.CloneMaterial(gameObject, this.MaterialIndex);
         if (material != null)
         {
             Texture o = material.GetTexture(this.TextureName);
             if (o != null)
             {
                 o = P3D_Helper.Clone<Texture>(o, true);
                 material.SetTexture(this.TextureName, o);
             }
         }
     }
     if (this.CreateOnAwake && ((this.CreateWidth > 0) && (this.CreateHeight > 0)))
     {
         Material material = P3D_Helper.GetMaterial(gameObject, this.MaterialIndex);
         if (material != null)
         {
             TextureFormat textureFormat = P3D_Helper.GetTextureFormat(this.CreateFormat);
             Texture2D textured = P3D_Helper.CreateTexture(this.CreateWidth, this.CreateHeight, textureFormat, this.CreateMipMaps);
             if (material.GetTexture(this.TextureName) != null)
             {
                 Debug.LogWarning("There is already a texture in this texture slot, maybe set it to null to save memory?", gameObject);
             }
             Texture texture2 = textured;
             P3D_Helper.ClearTexture(textured, this.CreateColor, true);
             material.SetTexture(this.TextureName, texture2);
             if (!string.IsNullOrEmpty(this.CreateKeyword))
             {
                 material.EnableKeyword(this.CreateKeyword);
             }
         }
     }
     this.UpdateTexture(gameObject);
 }