Ejemplo n.º 1
0
        protected void OnGUI()
        {
            EZEditorGUIUtility.WindowTitle(this);

            if (materials.Length == 0)
            {
                EditorGUILayout.HelpBox("No Material Selected", MessageType.Info);
                return;
            }

            if (GUILayout.Button("Optimize Properties"))
            {
                for (int i = 0; i < materials.Length; i++)
                {
                    Material           material          = materials[i];
                    SerializedObject   serializedObject  = new SerializedObject(material);
                    SerializedProperty m_SavedProperties = serializedObject.FindProperty("m_SavedProperties");
                    SerializedProperty m_TexEnvs         = m_SavedProperties.FindPropertyRelative("m_TexEnvs");
                    SerializedProperty m_Floats          = m_SavedProperties.FindPropertyRelative("m_Floats");
                    SerializedProperty m_Colors          = m_SavedProperties.FindPropertyRelative("m_Colors");
                    EZShaderGUIUtility.OptimizeProperties(material, m_TexEnvs, m_Floats, m_Colors);
                }
            }

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            for (int i = 0; i < materials.Length; i++)
            {
                Material         material         = materials[i];
                SerializedObject serializedObject = new SerializedObject(material);

                GUI.enabled = false;
                EditorGUILayout.ObjectField(material, typeof(Material), true);
                GUI.enabled = true;

                EditorGUI.indentLevel++;

                EditorGUILayout.LabelField("Keywords", EditorStyles.boldLabel);
                SerializedProperty m_ShaderKeywords = serializedObject.FindProperty("m_ShaderKeywords");
                EZShaderGUIUtility.KeywordsGUI(material, m_ShaderKeywords);

                SerializedProperty m_SavedProperties = serializedObject.FindProperty("m_SavedProperties");
                SerializedProperty m_TexEnvs         = m_SavedProperties.FindPropertyRelative("m_TexEnvs");
                SerializedProperty m_Floats          = m_SavedProperties.FindPropertyRelative("m_Floats");
                SerializedProperty m_Colors          = m_SavedProperties.FindPropertyRelative("m_Colors");
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Extra Properties", EditorStyles.boldLabel);
                if (GUILayout.Button("Optimize"))
                {
                    EZShaderGUIUtility.OptimizeProperties(material, m_TexEnvs, m_Floats, m_Colors);
                }
                EditorGUILayout.EndHorizontal();
                EZShaderGUIUtility.ExtraPropertiesGUI(material, m_TexEnvs, m_Floats, m_Colors);

                serializedObject.ApplyModifiedProperties();
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndScrollView();
        }
Ejemplo n.º 2
0
        protected void OnGUI()
        {
            EZEditorGUIUtility.WindowTitle(this);

            if (materials.Length == 0)
            {
                EditorGUILayout.HelpBox("No Material Selected", MessageType.Info);
                return;
            }

            if (GUILayout.Button("Optimize Properties"))
            {
                for (int i = 0; i < materials.Length; i++)
                {
                    EZShaderGUIUtility.OptimizeProperties(materials[i], texEnvs[i], floats[i], colors[i]);
                    serializedMaterials[i].ApplyModifiedProperties();
                }
            }

            propertyName1 = EditorGUILayout.TextField("Copy From", propertyName1);
            propertyName2 = EditorGUILayout.TextField("To", propertyName2);
            GUI.enabled   = !(string.IsNullOrEmpty(propertyName1) || string.IsNullOrEmpty(propertyName2) || propertyName1 == propertyName2);
            if (GUILayout.Button("Copy Property"))
            {
                for (int i = 0; i < materials.Length; i++)
                {
                    Material material = materials[i];
                    for (int j = 0; j < texEnvs[i].arraySize; j++)
                    {
                        SerializedProperty property1 = texEnvs[i].GetArrayElementAtIndex(j);
                        if (property1.FindPropertyRelative("first").stringValue == propertyName1)
                        {
                            Undo.RecordObject(material, "Copy Material Properties");
                            SerializedProperty texture = property1.FindPropertyRelative("second.m_Texture");
                            SerializedProperty scale   = property1.FindPropertyRelative("second.m_Scale");
                            SerializedProperty offset  = property1.FindPropertyRelative("second.m_Offset");
                            material.SetTexture(propertyName2, texture.objectReferenceValue as Texture);
                            material.SetTextureScale(propertyName2, scale.vector2Value);
                            material.SetTextureOffset(propertyName2, offset.vector2Value);
                            serializedMaterials[i].Update();
                        }
                    }
                    for (int j = 0; j < floats[i].arraySize; j++)
                    {
                        Undo.RecordObject(material, "Copy Material Properties");
                        SerializedProperty property1 = floats[i].GetArrayElementAtIndex(j);
                        if (property1.FindPropertyRelative("first").stringValue == propertyName1)
                        {
                            SerializedProperty second = property1.FindPropertyRelative("second");
                            material.SetFloat(propertyName2, second.floatValue);
                        }
                    }
                    for (int j = 0; j < colors[i].arraySize; j++)
                    {
                        Undo.RecordObject(material, "Copy Material Properties");
                        SerializedProperty property1 = colors[i].GetArrayElementAtIndex(j);
                        if (property1.FindPropertyRelative("first").stringValue == propertyName1)
                        {
                            SerializedProperty second = property1.FindPropertyRelative("second");
                            material.SetVector(propertyName2, second.colorValue);
                        }
                    }
                    serializedMaterials[i].Update();
                }
            }
            GUI.enabled = true;

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            for (int i = 0; i < materials.Length; i++)
            {
                EditorGUI.indentLevel++;
                serializedMaterials[i].Update();

                GUI.enabled = false;
                EditorGUILayout.ObjectField(materials[i], typeof(Material), true);
                GUI.enabled = true;

                EZShaderGUIUtility.PropertiesGUI(materials[i], texEnvs[i], floats[i], colors[i], MaterialPropertyFilter.All);
                EZShaderGUIUtility.KeywordsGUI(materials[i], shaderKeywords[i]);

                serializedMaterials[i].ApplyModifiedProperties();
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndScrollView();
        }