페이지

2017년 5월 30일 화요일

Unity PropertyDrawer ( Custom instpector)






[System.Serializable]
public struct FloatRange{

    //getter,setter방식은 FindPropertyRelative에서 못찾아내서 사용안함.
    public float value,min,max;

    public FloatRange(float pValue, float pMin, float pMax ){
        value = pValue;
        min = pMin;
        max = pMax;
    }
}


[CustomPropertyDrawer(typeof(FloatRange))]
public class FloatRangeDrawer : PropertyDrawer {
 
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label){
        label = EditorGUI.BeginProperty(position, label, property);
        Rect contentPosition = EditorGUI.PrefixLabel(position, label);
        contentPosition.width *= 0.33f;
        EditorGUI.indentLevel = 0;
        EditorGUIUtility.labelWidth = 14f;
        //value
        EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("value"), GUIContent.none);

        //min
        contentPosition.x += contentPosition.width;
        EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("min"), new GUIContent(","));
     
        //max
        contentPosition.x += contentPosition.width;
        EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("max"), new GUIContent("~"));

        EditorGUI.EndProperty();
    }
}

댓글 없음:

댓글 쓰기