//////////////////////////////////// // Helper Functions // //////////////////////////////////// #region HelperFunctions public static void TwoFloatSingleLine(GUIContent title, MaterialProperty prop1, GUIContent prop1Label, MaterialProperty prop2, GUIContent prop2Label, MaterialEditor materialEditor, float labelWidth = 30f) { const int kInterFieldPadding = 2; MaterialEditor.BeginProperty(prop1); MaterialEditor.BeginProperty(prop2); Rect rect = EditorGUILayout.GetControlRect(); EditorGUI.PrefixLabel(rect, title); var indent = EditorGUI.indentLevel; var preLabelWidth = EditorGUIUtility.labelWidth; EditorGUI.indentLevel = 0; EditorGUIUtility.labelWidth = labelWidth; Rect propRect1 = new Rect(rect.x + preLabelWidth, rect.y, (rect.width - preLabelWidth) * 0.5f - 1, EditorGUIUtility.singleLineHeight); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop1.hasMixedValue; var prop1val = EditorGUI.FloatField(propRect1, prop1Label, prop1.floatValue); if (EditorGUI.EndChangeCheck()) { prop1.floatValue = prop1val; } Rect propRect2 = new Rect(propRect1.x + propRect1.width + kInterFieldPadding, rect.y, propRect1.width, EditorGUIUtility.singleLineHeight); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop2.hasMixedValue; var prop2val = EditorGUI.FloatField(propRect2, prop2Label, prop2.floatValue); if (EditorGUI.EndChangeCheck()) { prop2.floatValue = prop2val; } EditorGUI.indentLevel = indent; EditorGUIUtility.labelWidth = preLabelWidth; EditorGUI.showMixedValue = false; MaterialEditor.EndProperty(); MaterialEditor.EndProperty(); }
void BlendModePopup() { MaterialEditor.BeginProperty(blendMode); var mode = (BlendMode)blendMode.floatValue; EditorGUI.BeginChangeCheck(); mode = (BlendMode)EditorGUILayout.Popup(Styles.renderingMode, (int)mode, Styles.blendNames); if (EditorGUI.EndChangeCheck()) { m_MaterialEditor.RegisterPropertyChangeUndo("Rendering Mode"); blendMode.floatValue = (float)mode; } MaterialEditor.EndProperty(); }
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { if (!IsPropertyTypeSuitable(prop)) { GUIContent c = EditorGUIUtility.TempContent("KeywordEnum used on a non-float property: " + prop.name, EditorGUIUtility.GetHelpIcon(MessageType.Warning)); EditorGUI.LabelField(position, c, EditorStyles.helpBox); return; } MaterialEditor.BeginProperty(position, prop); if (prop.type != MaterialProperty.PropType.Int) { EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; var value = (int)prop.floatValue; value = EditorGUI.Popup(position, label, value, keywords); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { prop.floatValue = value; SetKeyword(prop, value); } } else { EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; var value = prop.intValue; value = EditorGUI.Popup(position, label, value, keywords); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { prop.intValue = value; SetKeyword(prop, value); } } MaterialEditor.EndProperty(); }
// Helper to show texture and color properties public static Rect TextureColorProps(MaterialEditor materialEditor, GUIContent label, MaterialProperty textureProp, MaterialProperty colorProp, bool hdr = false) { MaterialEditor.BeginProperty(textureProp); if (colorProp != null) { MaterialEditor.BeginProperty(colorProp); } Rect rect = EditorGUILayout.GetControlRect(); EditorGUI.showMixedValue = textureProp.hasMixedValue; materialEditor.TexturePropertyMiniThumbnail(rect, textureProp, label.text, label.tooltip); EditorGUI.showMixedValue = false; if (colorProp != null) { EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = colorProp.hasMixedValue; int indentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; Rect rectAfterLabel = new Rect(rect.x + EditorGUIUtility.labelWidth, rect.y, EditorGUIUtility.fieldWidth, EditorGUIUtility.singleLineHeight); var col = EditorGUI.ColorField(rectAfterLabel, GUIContent.none, colorProp.colorValue, true, false, hdr); EditorGUI.indentLevel = indentLevel; if (EditorGUI.EndChangeCheck()) { materialEditor.RegisterPropertyChangeUndo(colorProp.displayName); colorProp.colorValue = col; } EditorGUI.showMixedValue = false; } if (colorProp != null) { MaterialEditor.EndProperty(); } MaterialEditor.EndProperty(); return(rect); }
internal static void DrawFloatToggleProperty(GUIContent styles, MaterialProperty prop, int indentLevel = 0, bool isDisabled = false) { if (prop == null) { return; } EditorGUI.BeginDisabledGroup(isDisabled); EditorGUI.indentLevel += indentLevel; EditorGUI.BeginChangeCheck(); MaterialEditor.BeginProperty(prop); bool newValue = EditorGUILayout.Toggle(styles, prop.floatValue == 1); if (EditorGUI.EndChangeCheck()) { prop.floatValue = newValue ? 1.0f : 0.0f; } MaterialEditor.EndProperty(); EditorGUI.indentLevel -= indentLevel; EditorGUI.EndDisabledGroup(); }
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { if (!IsPropertyTypeSuitable(prop)) { GUIContent c = EditorGUIUtility.TempContent("Enum used on a non-float property: " + prop.name, EditorGUIUtility.GetHelpIcon(MessageType.Warning)); EditorGUI.LabelField(position, c, EditorStyles.helpBox); return; } MaterialEditor.BeginProperty(position, prop); if (prop.type == MaterialProperty.PropType.Float || prop.type == MaterialProperty.PropType.Range) { EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; var value = (int)prop.floatValue; int selectedIndex = -1; for (var index = 0; index < values.Length; index++) { var i = values[index]; if (i == value) { selectedIndex = index; break; } } var selIndex = EditorGUI.Popup(position, label, selectedIndex, names); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { prop.floatValue = (float)values[selIndex]; } } else { EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; var value = prop.intValue; int selectedIndex = -1; for (var index = 0; index < values.Length; index++) { var i = values[index]; if (i == value) { selectedIndex = index; break; } } var selIndex = EditorGUI.Popup(position, label, selectedIndex, names); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { prop.intValue = values[selIndex]; } } MaterialEditor.EndProperty(); }