Hello dear friends,
i am pretty new to custom editor scripting and i have a simple question which i cant solve. I want to to draw the default UnityEvents property but i dont know how. I can already draw the 2 other fields. On very bottom i have attached an image of how my list looks like right now.
Here are my scripts:
SCRIPT1
[Serializable]
public class ListTemplate
{
public string templateName;
public SOClass so;
public UnityEvent unityEvent = new UnityEvent(); // i want to draw this into my custom editor
}
------------------------------------------------------------------------------
SCRIPT2
public class EventListener : MonoBehaviour
{
public List<ListTemplate> list;
}
-------------------------------------------------------------------------------
SCRIPT3
[CustomEditor(typeof(EventListener))]
public class CustomEventListener : Editor
{
private EventListener targetscript;
private ReorderableList reorderableList;
private void OnEnable()
{
targetscript = (EventListener)target;
reorderableList = new ReorderableList(serializedObject, serializedObject.FindProperty("list"), true, true, true, true);
reorderableList.drawHeaderCallback += DrawHeader;
reorderableList.drawElementCallback += DrawElement;
reorderableList.elementHeightCallback += ElementHeightCallback;
reorderableList.onAddCallback += AddItem;
reorderableList.onRemoveCallback += RemoveItem;
}
private float ElementHeightCallback(int indexer)
{
float propertyHeight = EditorGUI.GetPropertyHeight(reorderableList.serializedProperty.GetArrayElementAtIndex(indexer), true);
return propertyHeight + 60;
}
public override void OnInspectorGUI()
{
reorderableList.DoLayoutList();
}
private void DrawHeader(Rect rect)
{
GUI.Label(rect, "Eventlist");
}
private void DrawElement(Rect rect, int index, bool active, bool focused)
{
EditorGUI.BeginChangeCheck();
ListTemplate item = targetscript.list[index];
//Here we draw our 2 fields
item.templateName = EditorGUI.TextField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), item.templateName);
item.so = (SOClass)EditorGUI.ObjectField(new Rect(rect.x, rect.y + 20, rect.width, EditorGUIUtility.singleLineHeight), item.so, typeof(SOClass), true);
if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(target);
serializedObject.ApplyModifiedProperties();
}
}
private void AddItem(ReorderableList list)
{
targetscript.list.Add(new ListTemplate());
EditorUtility.SetDirty(target);
}
private void RemoveItem(ReorderableList list)
{
targetscript.list.RemoveAt(list.index);
EditorUtility.SetDirty(target);
}
}