/// <summary> /// <para>Draw two Property fields on a single line.</para> /// The pixel width of each field is manually specified, /// and the programmer must ensure it fits within the GUI. /// </summary> public static void DrawTwoValueFieldManualWidth( Rect position, GUIContent label, float labelWidth, bool lowWidth, float fieldWidth, GUIContent labelOne, MaterialProperty propertyOne, GUIContent labelTwo, MaterialProperty propertyTwo, MaterialValueType valueType) { position = DrawPrefixLabel( position, label, lowWidth ); // I dunno why this is necessary, but if this part of the drawer executes with an // indent level, each field will be indented, totally throwing off the layout. int oldIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; if( propertyOne != null ) { position = DrawValueField( position, labelWidth, labelOne, fieldWidth, propertyOne, valueType ); } else position.x += labelWidth + 2f + fieldWidth + 2f; if( propertyTwo != null ) { position = PositionForwardAndUpdateWidth( position, labelWidth ); position = DrawValueField( position, labelWidth, labelTwo, fieldWidth, propertyTwo, valueType ); } else position.x += labelWidth + 2f + fieldWidth + 2f; // Reset indent level EditorGUI.indentLevel = oldIndentLevel; }
/// <summary> /// <para>Draw two Property fields on a single line.</para> /// Each property will take up about half of the available space. /// </summary> public static void DrawTwoValueFieldAutoWidth( Rect position, GUIContent label, float labelWidth, bool lowWidth, GUIContent labelOne, MaterialProperty propertyOne, GUIContent labelTwo, MaterialProperty propertyTwo, MaterialValueType valueType) { float fieldWidth = ((position.width - EditorGUIUtility.labelWidth) / 2f) - labelWidth - 2f - 2f; DrawTwoValueFieldManualWidth( position, label, labelWidth, lowWidth, fieldWidth, labelOne, propertyOne, labelTwo, propertyTwo, valueType); }
/************************************ * Material Editor * //**********************************/ #region Material Properties /// <summary> /// <para>Draw three Property fields on a single line.</para> /// Each property will take up about a third of the available space. /// </summary> public static void DrawThreeValueFieldAutoWidth( Rect position, GUIContent label, float labelWidth, bool lowWidth, GUIContent labelOne, MaterialProperty propertyOne, GUIContent labelTwo, MaterialProperty propertyTwo, GUIContent labelThree, MaterialProperty propertyThree, MaterialValueType valueType) { float fieldWidth = (position.width / 3f) - labelWidth - 2f - 2f; DrawThreeValueFieldManualWidth( position, label, labelWidth, lowWidth, fieldWidth, labelOne, propertyOne, labelTwo, propertyTwo, labelThree, propertyThree, valueType); }
/// <summary> /// Draw a single prefix label and property field. /// </summary> private static Rect DrawValueField( Rect position, float labelWidth, GUIContent label, float fieldWidth, MaterialProperty property, MaterialValueType valueType) { position = DrawControlLabelAndUpdatePosition( position, label, labelWidth, fieldWidth ); switch( valueType ) { case MaterialValueType.Int: property.floatValue = EditorGUI.IntField( position, (int)property.floatValue ); break; case MaterialValueType.Float: property.floatValue = EditorGUI.FloatField( position, property.floatValue ); break; case MaterialValueType.Color: property.colorValue = EditorGUI.ColorField( position, property.colorValue ); break; case MaterialValueType.Bool: property.floatValue = EditorGUI.Toggle( position, property.floatValue > 0f ) ? 1f : 0f; break; default: UnityEngine.Debug.LogError( "Trying to draw Material Property with invalid value type (" + valueType.ToString() + ")" ); break; } return position; }