Object Drawers
Object Drawers customize how a task field or custom shared-variable value is
edited inside Behavior Designer. They are the Behavior Designer equivalent of a
Unity Property Drawer.
Draw a custom type
Place the drawer in an Editor folder or editor-only assembly. Register the value
type with CustomObjectDrawer and override OnGUI.
using BehaviorDesigner.Editor;
using UnityEditor;
using UnityEngine;
[CustomObjectDrawer(typeof(TargetInfo))]
public class TargetInfoDrawer : ObjectDrawer
{
public override void OnGUI(GUIContent label)
{
var targetInfo = value as TargetInfo ?? new TargetInfo();
targetInfo.Target = (GameObject)EditorGUILayout.ObjectField(
"Target", targetInfo.Target, typeof(GameObject), true);
targetInfo.LastSeenTime = EditorGUILayout.FloatField(
"Last Seen Time", targetInfo.LastSeenTime);
value = targetInfo;
}
}
The runtime TargetInfo type and its
shared-variable wrapper must not
reference UnityEditor.
Draw by attribute
Derive an attribute from ObjectDrawerAttribute, apply it to a task field, and
register a drawer for the attribute type. Read the configured attribute through
the drawer’s attribute member and assign the edited result back to value.
using BehaviorDesigner.Runtime.ObjectDrawers;
using BehaviorDesigner.Runtime.Tasks;
public class ClampAttribute : ObjectDrawerAttribute
{
public readonly float Min;
public readonly float Max;
public ClampAttribute(float min, float max)
{
Min = min;
Max = max;
}
}
using BehaviorDesigner.Editor;
using UnityEditor;
using UnityEngine;
[CustomObjectDrawer(typeof(ClampAttribute))]
public class ClampDrawer : ObjectDrawer
{
public override void OnGUI(GUIContent label)
{
var clamp = (ClampAttribute)attribute;
value = EditorGUILayout.Slider(label, (float)value, clamp.Min, clamp.Max);
}
}
Verify serialization
Edit the value through the task Inspector, save the scene or external tree, and
reopen it. If edits disappear, confirm the drawer assigns back to value and
the runtime type is serializable. If the drawer never appears, confirm it is in
an editor assembly and the CustomObjectDrawer type matches the value or
attribute exactly.