Added lots of examples for editor customization
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Data.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Ability))]
|
||||
public class AbilityDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
position = EditorGUI.PrefixLabel(position, label);
|
||||
|
||||
// everything in one line
|
||||
float totalWidth = position.width;
|
||||
position.width = totalWidth * 0.75f;
|
||||
EditorGUI.PropertyField(position, property.FindPropertyRelative("Name"), GUIContent.none);
|
||||
|
||||
position.x += position.width + totalWidth * 0.05f;
|
||||
position.width = totalWidth * 0.2f;
|
||||
EditorGUI.PropertyField(position, property.FindPropertyRelative("Value"), GUIContent.none);
|
||||
|
||||
// below each other without foldout
|
||||
// position.height = EditorGUIUtility.singleLineHeight;
|
||||
// EditorGUI.PropertyField(position, property.FindPropertyRelative("Name"), GUIContent.none);
|
||||
//
|
||||
// position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
// EditorGUI.PropertyField(position, property.FindPropertyRelative("Value"), GUIContent.none);
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight; // draw everything in one line
|
||||
|
||||
// draw properties below each other without foldout
|
||||
// return EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user