예제 #1
0
        private void DrawBoxAndContent(Rect rect, Event e, GUIContent content, PropertyOptions options)
        {
            if (options.reference_property != null && ShaderEditor.active.propertyDictionary.ContainsKey(options.reference_property))
            {
                GUI.Box(rect, new GUIContent("     " + content.text, content.tooltip), Styles.dropDownHeader);
                DrawIcons(rect, e);
                DrawButton(rect, options, e);

                Rect togglePropertyRect = new Rect(rect);
                togglePropertyRect.x      += 5;
                togglePropertyRect.y      += 2;
                togglePropertyRect.height -= 4;
                togglePropertyRect.width   = GUI.skin.font.fontSize * 3;
                float fieldWidth = EditorGUIUtility.fieldWidth;
                EditorGUIUtility.fieldWidth = 20;
                ShaderProperty prop = ShaderEditor.active.propertyDictionary[options.reference_property];

                int xOffset = prop.xOffset;
                prop.xOffset = 0;
                prop.Draw(new CRect(togglePropertyRect), new GUIContent(), isInHeader: true);
                prop.xOffset = xOffset;
                EditorGUIUtility.fieldWidth = fieldWidth;
            }
            else if (keyword != null)
            {
                GUI.Box(rect, "     " + content.text, Styles.dropDownHeader);
                DrawIcons(rect, e);
                DrawButton(rect, options, e);

                Rect togglePropertyRect = new Rect(rect);
                togglePropertyRect.x    += 20;
                togglePropertyRect.width = 20;

                EditorGUI.BeginChangeCheck();
                bool keywordOn = EditorGUI.Toggle(togglePropertyRect, "", ShaderEditor.active.materials[0].IsKeywordEnabled(keyword));
                if (EditorGUI.EndChangeCheck())
                {
                    MaterialHelper.ToggleKeyword(ShaderEditor.active.materials, keyword, keywordOn);
                }
            }
            else
            {
                GUI.Box(rect, content, Styles.dropDownHeader);
                DrawIcons(rect, e);
                DrawButton(rect, options, e);
            }
        }
예제 #2
0
파일: Helper.cs 프로젝트: bmjoy/qtengine
 public static void SetMaterialPropertyValue(MaterialProperty p, Material[] materials, string value)
 {
     if (p.type == MaterialProperty.PropType.Texture)
     {
         Texture tex = AssetDatabase.LoadAssetAtPath <Texture>(value);
         if (tex != null)
         {
             foreach (Material m in materials)
             {
                 m.SetTexture(p.name, tex);
             }
         }
     }
     else if (p.type == MaterialProperty.PropType.Float || p.type == MaterialProperty.PropType.Range)
     {
         float f_value;
         if (float.TryParse(value, out f_value))
         {
             p.floatValue = f_value;
             string[] drawer = ShaderHelper.GetDrawer(p);
             if (drawer != null && drawer.Length > 1 && drawer[0] == "Toggle" && drawer[1] != "__")
             {
                 MaterialHelper.ToggleKeyword(p, drawer[1], f_value == 1);
             }
         }
     }
     else if (p.type == MaterialProperty.PropType.Vector)
     {
         string[] xyzw   = value.Split(",".ToCharArray());
         Vector4  vector = new Vector4(float.Parse(xyzw[0]), float.Parse(xyzw[1]), float.Parse(xyzw[2]), float.Parse(xyzw[3]));
         foreach (Material m in materials)
         {
             m.SetVector(p.name, vector);
         }
     }
     else if (p.type == MaterialProperty.PropType.Color)
     {
         Color col = Converter.stringToColor(value);
         foreach (Material m in materials)
         {
             m.SetColor(p.name, col);
         }
     }
 }