- Home /
Question by
nickk2002 · Apr 28, 2020 at 05:55 AM ·
custom editortogglepropertydrawer
Custom Inspector Add a toggle next to list item
I have a BotBehaviour class which holds BotActions. I want to be able to add a tick button on the left side of each item in the list, and use that button to enable/disable that specific action.
BotBehaviour and BotAction are both serializable here is my attempt:
[CustomPropertyDrawer(typeof(BotBehaviour))]
public class BotBehaviourEditor : PropertyDrawer
{
private bool pressed;
private GUIStyle buttonStyle;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.PropertyField(position, property, label, true);
EditorGUI.BeginProperty(position, label, property);
var indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 10;
Vector2 hospitalPosition = property.FindPropertyRelative("hospital").rectValue.position;
//hospitalPosition.y -= 10;
Rect rect = new Rect(0,55, 10, 10);
pressed = EditorGUI.Toggle(rect, pressed);
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property);
}
}
bot-inspector.jpg
(12.1 kB)
Comment
Your answer
Follow this Question
Related Questions
EditorGUILayout.PropertyField cannot draw custom class? 2 Answers
Is there a better way to code this custom-propertydrawer? 1 Answer
PropertyDrawer inserting large space for list 0 Answers
Bool field in CustomPropertyDrawer isn't clickable? 2 Answers
Why is my propertydrawer being automatically disabled? 1 Answer