public static void GetGradientPropertiesForPreview(PropertyCollector properties, string name, Gradient value)
        {
            properties.AddShaderProperty(new Vector1ShaderProperty()
            {
                overrideReferenceName = string.Format("{0}_Type", name),
                value = (int)value.mode,
                generatePropertyBlock = false
            });

            properties.AddShaderProperty(new Vector1ShaderProperty()
            {
                overrideReferenceName = string.Format("{0}_ColorsLength", name),
                value = value.colorKeys.Length,
                generatePropertyBlock = false
            });

            properties.AddShaderProperty(new Vector1ShaderProperty()
            {
                overrideReferenceName = string.Format("{0}_AlphasLength", name),
                value = value.alphaKeys.Length,
                generatePropertyBlock = false
            });

            for (int i = 0; i < 8; i++)
            {
                properties.AddShaderProperty(new Vector4ShaderProperty()
                {
                    overrideReferenceName = string.Format("{0}_ColorKey{1}", name, i),
                    value = i < value.colorKeys.Length ? GradientUtils.ColorKeyToVector(value.colorKeys[i]) : Vector4.zero,
                    generatePropertyBlock = false
                });
            }

            for (int i = 0; i < 8; i++)
            {
                properties.AddShaderProperty(new Vector2ShaderProperty()
                {
                    overrideReferenceName = string.Format("{0}_AlphaKey{1}", name, i),
                    value = i < value.alphaKeys.Length ? GradientUtils.AlphaKeyToVector(value.alphaKeys[i]) : Vector2.zero,
                    generatePropertyBlock = false
                });
            }
        }
        public override void CollectPreviewMaterialProperties(List <PreviewProperty> properties)
        {
            base.CollectPreviewMaterialProperties(properties);

            properties.Add(new PreviewProperty(PropertyType.Vector1)
            {
                name       = string.Format("_{0}_Type", GetVariableNameForNode()),
                floatValue = (int)m_Gradient.mode
            });

            properties.Add(new PreviewProperty(PropertyType.Vector1)
            {
                name       = string.Format("_{0}_ColorsLength", GetVariableNameForNode()),
                floatValue = m_Gradient.colorKeys.Length
            });

            properties.Add(new PreviewProperty(PropertyType.Vector1)
            {
                name       = string.Format("_{0}_AlphasLength", GetVariableNameForNode()),
                floatValue = m_Gradient.alphaKeys.Length
            });

            for (int i = 0; i < 8; i++)
            {
                properties.Add(new PreviewProperty(PropertyType.Vector4)
                {
                    name         = string.Format("_{0}_ColorKey{1}", GetVariableNameForNode(), i),
                    vector4Value = i < m_Gradient.colorKeys.Length ? GradientUtils.ColorKeyToVector(m_Gradient.colorKeys[i]) : Vector4.zero
                });
            }

            for (int i = 0; i < 8; i++)
            {
                properties.Add(new PreviewProperty(PropertyType.Vector2)
                {
                    name         = string.Format("_{0}_AlphaKey{1}", GetVariableNameForNode(), i),
                    vector4Value = i < m_Gradient.alphaKeys.Length ? GradientUtils.AlphaKeyToVector(m_Gradient.alphaKeys[i]) : Vector2.zero
                });
            }
        }
        public override void GetPreviewProperties(List <PreviewProperty> properties, string name)
        {
            properties.Add(new PreviewProperty(PropertyType.Vector1)
            {
                name       = string.Format("{0}_Type", name),
                floatValue = (int)value.mode
            });

            properties.Add(new PreviewProperty(PropertyType.Vector1)
            {
                name       = string.Format("{0}_ColorsLength", name),
                floatValue = value.colorKeys.Length
            });

            properties.Add(new PreviewProperty(PropertyType.Vector1)
            {
                name       = string.Format("{0}_AlphasLength", name),
                floatValue = value.alphaKeys.Length
            });

            for (int i = 0; i < 8; i++)
            {
                properties.Add(new PreviewProperty(PropertyType.Vector4)
                {
                    name         = string.Format("{0}_ColorKey{1}", name, i),
                    vector4Value = i < value.colorKeys.Length ? GradientUtils.ColorKeyToVector(value.colorKeys[i]) : Vector4.zero
                });
            }

            for (int i = 0; i < 8; i++)
            {
                properties.Add(new PreviewProperty(PropertyType.Vector2)
                {
                    name         = string.Format("{0}_AlphaKey{1}", name, i),
                    vector4Value = i < value.alphaKeys.Length ? GradientUtils.AlphaKeyToVector(value.alphaKeys[i]) : Vector2.zero
                });
            }
        }
 public void SetMaterialPropertyBlockValue(Material mat)
 {
     if ((propType == PropertyType.Texture2D || propType == PropertyType.Texture2DArray || propType == PropertyType.Texture3D) && textureValue != null)
     {
         mat.SetTexture(name, m_ClassData.textureValue);
     }
     else if (propType == PropertyType.Cubemap && cubemapValue != null)
     {
         mat.SetTexture(name, m_ClassData.cubemapValue);
     }
     else if (propType == PropertyType.Color)
     {
         mat.SetColor(name, m_StructData.colorValue);
     }
     else if (propType == PropertyType.Vector2 || propType == PropertyType.Vector3 || propType == PropertyType.Vector4)
     {
         mat.SetVector(name, m_StructData.vector4Value);
     }
     else if (propType == PropertyType.Vector1)
     {
         mat.SetFloat(name, m_StructData.floatValue);
     }
     else if (propType == PropertyType.Boolean)
     {
         mat.SetFloat(name, m_StructData.booleanValue ? 1 : 0);
     }
     else if (propType == PropertyType.Matrix2 || propType == PropertyType.Matrix3 || propType == PropertyType.Matrix4)
     {
         mat.SetMatrix(name, m_StructData.matrixValue);
     }
     else if (propType == PropertyType.Gradient)
     {
         mat.SetFloat(string.Format("{0}_Type", name), (int)m_ClassData.gradientValue.mode);
         mat.SetFloat(string.Format("{0}_ColorsLength", name), m_ClassData.gradientValue.colorKeys.Length);
         mat.SetFloat(string.Format("{0}_AlphasLength", name), m_ClassData.gradientValue.alphaKeys.Length);
         for (int i = 0; i < 8; i++)
         {
             mat.SetVector(string.Format("{0}_ColorKey{1}", name, i), i < m_ClassData.gradientValue.colorKeys.Length ? GradientUtils.ColorKeyToVector(m_ClassData.gradientValue.colorKeys[i]) : Vector4.zero);
         }
         for (int i = 0; i < 8; i++)
         {
             mat.SetVector(string.Format("{0}_AlphaKey{1}", name, i), i < m_ClassData.gradientValue.alphaKeys.Length ? GradientUtils.AlphaKeyToVector(m_ClassData.gradientValue.alphaKeys[i]) : Vector2.zero);
         }
     }
 }
        public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
        {
            var matOwner = owner as AbstractMaterialNode;

            if (matOwner == null)
            {
                throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
            }

            if (generationMode == GenerationMode.Preview)
            {
                properties.AddShaderProperty(new Vector1ShaderProperty()
                {
                    overrideReferenceName = string.Format("{0}_Type", matOwner.GetVariableNameForSlot(id)),
                    value = (int)value.mode,
                    generatePropertyBlock = false
                });

                properties.AddShaderProperty(new Vector1ShaderProperty()
                {
                    overrideReferenceName = string.Format("{0}_ColorsLength", matOwner.GetVariableNameForSlot(id)),
                    value = value.colorKeys.Length,
                    generatePropertyBlock = false
                });

                properties.AddShaderProperty(new Vector1ShaderProperty()
                {
                    overrideReferenceName = string.Format("{0}_AlphasLength", matOwner.GetVariableNameForSlot(id)),
                    value = value.alphaKeys.Length,
                    generatePropertyBlock = false
                });

                for (int i = 0; i < 8; i++)
                {
                    properties.AddShaderProperty(new Vector4ShaderProperty()
                    {
                        overrideReferenceName = string.Format("{0}_ColorKey{1}", matOwner.GetVariableNameForSlot(id), i),
                        value = i < value.colorKeys.Length ? GradientUtils.ColorKeyToVector(value.colorKeys[i]) : Vector4.zero,
                        generatePropertyBlock = false
                    });
                }

                for (int i = 0; i < 8; i++)
                {
                    properties.AddShaderProperty(new Vector4ShaderProperty()
                    {
                        overrideReferenceName = string.Format("{0}_AlphaKey{1}", matOwner.GetVariableNameForSlot(id), i),
                        value = i < value.alphaKeys.Length ? GradientUtils.AlphaKeyToVector(value.alphaKeys[i]) : Vector2.zero,
                        generatePropertyBlock = false
                    });
                }
            }

            var prop = new GradientShaderProperty();

            prop.overrideReferenceName = matOwner.GetVariableNameForSlot(id);
            prop.generatePropertyBlock = false;
            prop.value = value;

            if (generationMode == GenerationMode.Preview)
            {
                prop.OverrideMembers(matOwner.GetVariableNameForSlot(id));
            }

            properties.AddShaderProperty(prop);
        }