Beispiel #1
0
        protected override void OnMaterialChanged(Material material)
        {
            var keyword = String.Empty;

            if (m_args.GetField(out keyword, "keyword", String.Empty))
            {
                while (m_prop != null)
                {
                    if (!ShaderGUIHelper.IsModeMatched(this, m_args))
                    {
                        break;
                    }
                    var cmp = ShaderGUIHelper.ExcuteLogicOp(this, m_prop, m_args);
                    if (cmp != -1)
                    {
                        SetKeyword(material, keyword, cmp == 1);
                        return;
                    }
                    break;
                }
                // disable keyword for default
                if (material.IsKeywordEnabled(keyword))
                {
                    SetKeyword(material, keyword, false);
                }
            }
        }
Beispiel #2
0
 public override bool GetLogicOpResult(out String returnValue)
 {
     returnValue = "false";
     if (ShaderGUIHelper.IsModeMatched(this, m_args) &&
         ShaderGUIHelper.ExcuteLogicOp(this, null, m_args) == 1)
     {
         returnValue = "true";
         return(true);
     }
     return(false);
 }
Beispiel #3
0
        public void DrawGUI(Material material)
        {
            if (!ShaderGUIHelper.IsModeMatched(this, m_args) || !GetBoolTestResult())
            {
                return;
            }
            m_MaterialEditor.SetDefaultGUIWidths();
            float h = m_MaterialEditor.GetPropertyHeight(m_prop, m_prop.displayName);
            Rect  r = EditorGUILayout.GetControlRect(true, h, EditorStyles.layerMaskField);

            m_MaterialEditor.ShaderProperty(r, m_prop, m_prop.displayName);
            m_MaterialEditor.SetDefaultGUIWidths();
        }
Beispiel #4
0
 public override bool GetLogicOpResult(out String returnValue, MaterialProperty[] props)
 {
     returnValue = String.Empty;
     if (m_prop != null)
     {
         return(ShaderGUIHelper.IsModeMatched(this, m_args) &&
                ShaderGUIHelper.ExcuteLogicOp(this, m_prop, props, m_args) == 1);
     }
     else
     {
         return(ShaderGUIHelper.IsModeMatched(this, m_args) &&
                GetBoolTestResult(m_MaterialEditor.target as Material, props));
     }
 }
Beispiel #5
0
        public void DrawGUI(Material material)
        {
            if (!ShaderGUIHelper.IsModeMatched(this, m_args) || !GetBoolTestResult(material, null))
            {
                return;
            }
            var gui_enabled = GUI.enabled;

            try {
                GUI.enabled = m_keep == null && m_invertProp == null;
                if (!GUI.enabled && (m_prop.flags & MaterialProperty.PropFlags.HideInInspector) != 0)
                {
                    return;
                }
                m_MaterialEditor.SetDefaultGUIWidths();
                var   label = m_label ?? m_prop.displayName;
                float h     = m_MaterialEditor.GetPropertyHeight(m_prop, label);
                Rect  r     = EditorGUILayout.GetControlRect(true, h, EditorStyles.layerMaskField);
                for (; ;)
                {
                    if (m_invertProp != null)
                    {
                        var mode = ( CullMode )( int )m_invertProp.floatValue;
                        switch (mode)
                        {
                        case CullMode.Off:
                            m_prop.floatValue = ( float )CullMode.Off;
                            break;

                        case CullMode.Front:
                            m_prop.floatValue = ( float )CullMode.Back;
                            break;

                        case CullMode.Back:
                            m_prop.floatValue = ( float )CullMode.Front;
                            break;
                        }
                    }
                    m_MaterialEditor.ShaderProperty(r, m_prop, label);
                    break;
                }
            } finally {
                GUI.enabled = gui_enabled;
            }
            m_MaterialEditor.SetDefaultGUIWidths();
        }
        protected override void OnMaterialChanged(Material material, MaterialProperty[] props)
        {
            var keyword = String.Empty;

            if (m_args != null && m_args.GetField(out keyword, "keyword", String.Empty))
            {
                if (keyword.Equals("none", StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
                var enable_if = TryGetBoolTestResult(material, props, Cfg.Key_EnableIfValue);
                if (enable_if != null && enable_if.Value == false)
                {
                    return;
                }
                if (ShaderGUIHelper.IsModeMatched(this, m_args) && GetBoolTestResult(material, props))
                {
                    if (m_prop != null)
                    {
                        var cmp = ShaderGUIHelper.ExcuteLogicOp(this, m_prop, props, m_args);
                        if (cmp != -1)
                        {
                            if (!keyword.Equals("none", StringComparison.OrdinalIgnoreCase))
                            {
                                SetKeyword(material, keyword, cmp == 1);
                            }
                            return;
                        }
                    }
                    else
                    {
                        SetKeyword(material, keyword, true);
                        return;
                    }
                }
                if (!keyword.Equals("none", StringComparison.OrdinalIgnoreCase))
                {
                    // disable keyword for default
                    if (material.IsKeywordEnabled(keyword))
                    {
                        SetKeyword(material, keyword, false);
                    }
                }
            }
        }
Beispiel #7
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);
        }
        public void DrawGUI(Material material)
        {
            if (!ShaderGUIHelper.IsModeMatched(this, m_args) || !GetBoolTestResult(material, null))
            {
                if (m_autoReset && m_parent.template != null)
                {
                    if (m_dirty == null || m_dirty.Value == true)
                    {
                        m_dirty = false;
                        ResetToDefaultValue(m_parent.template);
                    }
                }
                return;
            }
            m_dirty = true;
            var gui_enabled = GUI.enabled;

            try {
                GUI.enabled = m_keep == null;
                if (!GUI.enabled && (m_prop.flags & MaterialProperty.PropFlags.HideInInspector) != 0)
                {
                    return;
                }
                m_MaterialEditor.SetDefaultGUIWidths();
                var   label = m_label ?? m_prop.displayName;
                float h     = m_MaterialEditor.GetPropertyHeight(m_prop, label);
                Rect  r     = EditorGUILayout.GetControlRect(true, h, EditorStyles.layerMaskField);
                for (; ;)
                {
                    if (m_guiType == Cfg.Value_PropGUIType_Toggle && (m_prop.type == MaterialProperty.PropType.Float || m_prop.type == MaterialProperty.PropType.Range))
                    {
                        m_prop.floatValue = EditorGUI.Toggle(r, label, m_prop.floatValue > 0) ? 1 : 0;
                        break;
                    }
                    if (m_guiType == Cfg.Value_PropGUIType_Rect && (m_prop.type == MaterialProperty.PropType.Vector))
                    {
                        var v      = m_prop.vectorValue;
                        var bounds = new Rect();
                        bounds.xMin = v.x;
                        bounds.xMax = v.y;
                        bounds.yMin = v.z;
                        bounds.yMax = v.w;
                        EditorGUI.LabelField(r, m_prop.displayName);
                        EditorGUI.indentLevel++;
                        bounds = EditorGUILayout.RectField(bounds);
                        EditorGUI.indentLevel--;
                        m_prop.vectorValue = new Vector4(bounds.xMin, bounds.xMax, bounds.yMin, bounds.yMax);
                        break;
                    }
                    if (m_prop.type == MaterialProperty.PropType.Color)
                    {
                        var precision = m_precision;
                        if (precision <= 0)
                        {
                            precision = 256;
                        }
                        if (m_guiType == Cfg.Value_PropGUIType_ColorR)
                        {
                            var c = m_prop.colorValue;
                            c.r = DrawRangeProperty(r, m_prop, m_prop.colorValue.r, label, 0, 1, precision);
                            m_prop.colorValue = c;
                            break;
                        }
                        else if (m_guiType == Cfg.Value_PropGUIType_ColorG)
                        {
                            var c = m_prop.colorValue;
                            c.g = DrawRangeProperty(r, m_prop, m_prop.colorValue.g, label, 0, 1, precision);
                            m_prop.colorValue = c;
                            break;
                        }
                        else if (m_guiType == Cfg.Value_PropGUIType_ColorB)
                        {
                            var c = m_prop.colorValue;
                            c.b = DrawRangeProperty(r, m_prop, m_prop.colorValue.b, label, 0, 1, precision);
                            m_prop.colorValue = c;
                            break;
                        }
                        else if (m_guiType == Cfg.Value_PropGUIType_ColorA)
                        {
                            var c = m_prop.colorValue;
                            c.a = DrawRangeProperty(r, m_prop, m_prop.colorValue.a, label, 0, 1, precision);
                            m_prop.colorValue = c;
                            break;
                        }
                    }
                    m_MaterialEditor.ShaderProperty(r, m_prop, label);
                    if (m_precision >= 0)
                    {
                        var range = new Vector3(0, float.MinValue, float.MaxValue);
                        if (m_prop.type == MaterialProperty.PropType.Float)
                        {
                            var index = ShaderUtils.FindPropertyIndex(material.shader, m_prop.name, ShaderUtil.ShaderPropertyType.Float);
                            if (index >= 0)
                            {
                                range.x = ShaderUtil.GetRangeLimits(material.shader, index, 0);
                            }
                            m_prop.floatValue = _RoundFloat(m_prop.floatValue, range);
                        }
                        else if (m_prop.type == MaterialProperty.PropType.Range)
                        {
                            range.y = m_prop.rangeLimits.x;
                            range.z = m_prop.rangeLimits.y;
                            var index = ShaderUtils.FindPropertyIndex(material.shader, m_prop.name, ShaderUtil.ShaderPropertyType.Range);
                            if (index >= 0)
                            {
                                range.x = ShaderUtil.GetRangeLimits(material.shader, index, 0);
                            }
                            m_prop.floatValue = _RoundFloat(m_prop.floatValue, range);
                        }
                        else if (m_prop.type == MaterialProperty.PropType.Color)
                        {
                            if (m_parent.template != null)
                            {
                                var _type = FindShaderPropertyType(m_parent.template.shader, m_prop.name);
                                if (_type != null && _type.Value == ShaderUtil.ShaderPropertyType.Color)
                                {
                                    var defaultColor = m_parent.template.GetColor(m_prop.name);
                                    var c            = m_prop.colorValue;
                                    c.r = _RoundColorFixed(c.r, new Vector3(defaultColor.r, 0, 1), m_precision);
                                    c.g = _RoundColorFixed(c.r, new Vector3(defaultColor.g, 0, 1), m_precision);
                                    c.b = _RoundColorFixed(c.r, new Vector3(defaultColor.b, 0, 1), m_precision);
                                    c.a = _RoundColorFixed(c.r, new Vector3(defaultColor.a, 0, 1), m_precision);
                                }
                            }
                        }
                    }
                    break;
                }
            } finally {
                GUI.enabled = gui_enabled;
            }
            m_MaterialEditor.SetDefaultGUIWidths();
        }
 protected override void OnDrawPropertiesGUI(Material material, MaterialProperty[] props)
 {
     if (!ShaderGUIHelper.IsModeMatched(this, m_args) || !GetBoolTestResult(material, props))
     {
         return;
     }
     if (!String.IsNullOrEmpty(m_text))
     {
         var jo = m_args.GetField("params");
         m_args.GetField(out m_fontSize, "fontsize", 0);
         List <object> pars = null;
         if (jo != null)
         {
             if (jo.IsArray)
             {
                 for (int i = 0; i < jo.Count; ++i)
                 {
                     var o = jo[i];
                     if (o != null && !o.isContainer)
                     {
                         pars = pars ?? new List <object>();
                         pars.Add(ShaderGUIHelper.JSONValueToString(o));
                     }
                 }
             }
             else if (jo.IsObject == false)
             {
                 pars = pars ?? new List <object>();
                 pars.Add(ShaderGUIHelper.JSONValueToString(jo));
             }
         }
         for ( ; ;)
         {
             var text = m_text;
             var m    = Regex.Matches(m_text, @"\{(\d+)\}");
             if (m.Count > 0)
             {
                 var maxIndex = 0;
                 for (int i = 0; i < m.Count; ++i)
                 {
                     var groups = m[i].Groups;
                     if (groups.Count == 2)
                     {
                         var index = -1;
                         if (int.TryParse(groups[1].ToString(), out index))
                         {
                             if (index > maxIndex && index >= 0)
                             {
                                 maxIndex = index;
                             }
                         }
                     }
                 }
                 if (maxIndex >= 0)
                 {
                     pars = pars ?? new List <object>();
                     if (pars.Count < maxIndex + 1)
                     {
                         pars.Resize(maxIndex + 1);
                     }
                     for (int i = 0; i < pars.Count; ++i)
                     {
                         var ref_id = pars[i] as String;
                         if (!String.IsNullOrEmpty(ref_id))
                         {
                             var prop = FindPropEditor <UnitMaterialEditor>(ref_id);
                             if (prop != null)
                             {
                                 var v = prop.GetReturnValue(props);
                                 if (String.IsNullOrEmpty(v))
                                 {
                                     v = "null";
                                 }
                                 pars[i] = v;
                             }
                         }
                     }
                     text = String.Format(m_text, pars.ToArray());
                 }
             }
             var _richText = m_style.richText;
             var _fontSize = m_style.fontSize;
             m_style.richText = true;
             if (m_fontSize > 0)
             {
                 m_style.fontSize = m_fontSize;
             }
             EditorGUILayout.HelpBox(text, m_type);
             m_style.richText = _richText;
             m_style.fontSize = _fontSize;
             break;
         }
     }
 }
Beispiel #10
0
 public override bool GetLogicOpResult(out String returnValue)
 {
     returnValue = String.Empty;
     return(m_prop != null && ShaderGUIHelper.IsModeMatched(this, m_args) &&
            ShaderGUIHelper.ExcuteLogicOp(this, m_prop, m_args) == 1);
 }