private static bool FilterProperty(bool hasProperty, MaterialPropertyFilter filter) { if (filter == MaterialPropertyFilter.All) { return(true); } else if (filter == MaterialPropertyFilter.Exposed) { return(hasProperty); } else if (filter == MaterialPropertyFilter.Extra) { return(!hasProperty); } return(true); }
private static void TexturePropertiesGUI(Material material, SerializedProperty property, MaterialPropertyFilter filter) { EditorGUILayout.BeginHorizontal(); property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, filter + " " + property.displayName, true, new GUIStyle(EditorStyles.foldout) { fontStyle = FontStyle.Bold }); if (GUILayout.Button("Optimize")) { OptimizeProperties(material, property); } EditorGUILayout.EndHorizontal(); if (property.isExpanded) { EditorGUIUtility.labelWidth = 0; EditorGUI.indentLevel++; for (int i = property.arraySize - 1; i >= 0; i--) { SerializedProperty child = property.GetArrayElementAtIndex(i); SerializedProperty propertyName = child.FindPropertyRelative("first"); bool hasProperty = material.HasProperty(propertyName.stringValue); if (FilterProperty(hasProperty, filter)) { SerializedProperty texEnv = child.FindPropertyRelative("second"); SerializedProperty texture = texEnv.FindPropertyRelative("m_Texture"); SerializedProperty scale = texEnv.FindPropertyRelative("m_Scale"); SerializedProperty offset = texEnv.FindPropertyRelative("m_Offset"); EditorGUILayout.BeginHorizontal(); texEnv.isExpanded = EditorGUILayout.Foldout(texEnv.isExpanded, propertyName.stringValue, true); if (!texEnv.isExpanded) { EditorGUILayout.PropertyField(texture, GUIContent.none); } GUI.enabled = !hasProperty; if (GUILayout.Button("Delete", GUILayout.Width(80))) { Debug.LogFormat(material, "Remove Property: {0} from {1}", propertyName.stringValue, material.name); property.DeleteArrayElementAtIndex(i); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); if (texEnv.isExpanded) { EditorGUIUtility.wideMode = true; EditorGUI.indentLevel++; EditorGUILayout.PropertyField(texture); EditorGUILayout.PropertyField(scale); EditorGUILayout.PropertyField(offset); EditorGUI.indentLevel--; } } } EditorGUI.indentLevel--; } }
public static void PropertiesGUI(Material material, SerializedProperty m_TexEnvs, SerializedProperty m_Floats, SerializedProperty m_Colors, MaterialPropertyFilter filter) { TexturePropertiesGUI(material, m_TexEnvs, filter); PropertiesGUI(material, m_Floats, filter); PropertiesGUI(material, m_Colors, filter); }