Example #1
0
        protected override bool OnInitProperties(MaterialProperty[] props)
        {
            if (m_args != null && props.Length > 0)
            {
                var material = this.m_MaterialEditor.target as Material;
                if (ShaderGUIHelper.IsModeMatched(this, m_args) && GetBoolTestResult(material, props))
                {
                    var values = m_args.GetField("values");
                    if (values != null && values.type == JSONObject.Type.OBJECT)
                    {
                        for (int i = 0; i < values.keys.Count; ++i)
                        {
                            var key   = values.keys[i];
                            var value = values.GetField(key);
                            var prop  = ShaderGUI.FindProperty(key, props);
                            if (prop != null && !String.IsNullOrEmpty(key) && value != null)
                            {
                                switch (prop.type)
                                {
                                case MaterialProperty.PropType.Float: {
                                    float f;
                                    if (ShaderGUIHelper.ParseValue(this, values, key, out f))
                                    {
                                        prop.floatValue = f;
                                    }
                                }
                                break;

                                case MaterialProperty.PropType.Range: {
                                    float f;
                                    if (ShaderGUIHelper.ParseValue(this, values, key, out f))
                                    {
                                        prop.floatValue = Mathf.Clamp(f, prop.rangeLimits.x, prop.rangeLimits.y);
                                    }
                                }
                                break;

                                case MaterialProperty.PropType.Color: {
                                    Vector4 c = prop.colorValue;
                                    int     comp;
                                    if (ShaderGUIHelper.TryParseVector4(this, values, key, ref c, out comp))
                                    {
                                        if ((prop.flags & MaterialProperty.PropFlags.HDR) != 0)
                                        {
                                            c.x = Mathf.Clamp01(c.x);
                                            c.y = Mathf.Clamp01(c.y);
                                            c.z = Mathf.Clamp01(c.z);
                                            c.w = Mathf.Clamp01(c.w);
                                        }
                                        prop.colorValue = new Color(c.x, c.y, c.z, c.w);
                                    }
                                }
                                break;

                                case MaterialProperty.PropType.Vector: {
                                    Vector4 v = prop.colorValue;
                                    int     comp;
                                    if (ShaderGUIHelper.TryParseVector4(this, values, key, ref v, out comp))
                                    {
                                        prop.vectorValue = v;
                                    }
                                }
                                break;
                                }
                            }
                        }
                    }
                }
                var features = m_args.GetField("shader_feature_list");
                if (features != null && features.type == JSONObject.Type.ARRAY)
                {
                    var features_list = new List <String>(features.list.Count);
                    for (int i = 0; i < features.list.Count; ++i)
                    {
                        var o = features.list[i];
                        if (o != null && o.type == JSONObject.Type.STRING &&
                            !String.IsNullOrEmpty(o.str))
                        {
                            features_list.Add(o.str);
                        }
                    }
                    for (int i = 0; i < BlendModeNames.Length; ++i)
                    {
                        features_list.Add("_MODE_" + BlendModeNames[i].ToUpper());
                    }
                    features_list.Add("_BLEND_ADDITIVE_SERIES");
                    features_list.Add("_ALPHAPREMULTIPLY_ON");

                    m_featureList = features_list.Distinct().ToList();
                }
            }
            return(true);
        }