private void OnEnable() { _asset = (StateEventsCollectionAsset)target; _list = new AdvancedReorderableList <StateEventListItem>(serializedObject, serializedObject.FindProperty(STATE_EVENTS), true, true, true); _list.OnDrawHeaderCallback = rect => EditorGUI.LabelField(rect, "States"); _list.OnAddCallback = list => { list.serializedProperty.AddArrayElement().FindPropertyRelative(nameof(StateEventsAsset.Name)).stringValue = ValidateStateName("New State"); }; _list.OnDrawCallback = (list, prop, data, index) => { list.Space(TOP_PADDING); list.Draw(EditorGUI.GetPropertyHeight(SerializedPropertyType.String, new GUIContent("Name")), rect => { SerializedProperty nameProp = prop.FindPropertyRelative(nameof(StateEventsAsset.Name)); DrawEditableNameFoldout(rect, nameProp.stringValue, newName => nameProp.stringValue = ValidateStateName(newName), prop.isExpanded, newExpandedState => prop.isExpanded = newExpandedState); }); if (prop.isExpanded) { list.Space(TOP_PADDING); list.Draw(data.List.GetHeight(), rect => data.List.DoList(rect)); } list.Space(BOTTOM_PADDING); }; }
public StateEventListItem() { List = new AdvancedReorderableList(null, null, true, true, true); List.OnAddCallback = list => { List.Elements.AddArrayElement().FindPropertyRelative(nameof(StateEventAsset.Name)).stringValue = ValidateEventName("New Event", List.Elements); }; List.OnDrawCallback = (list, prop, index) => { list.Space(TOP_PADDING); list.Draw(EditorGUI.GetPropertyHeight(SerializedPropertyType.String, new GUIContent("Name")), rect => { SerializedProperty nameProp = prop.FindPropertyRelative(nameof(StateEventAsset.Name)); DrawEditableNameFoldout(rect, nameProp.stringValue, newName => nameProp.stringValue = ValidateEventName(newName, list.Elements), prop.isExpanded, newExpandedState => prop.isExpanded = newExpandedState); }); if (prop.isExpanded) { list.Space(TOP_PADDING); var typeProp = prop.FindPropertyRelative(nameof(StateEventAsset.Type)); list.Draw(typeProp, INTERNAL_VERTICAL_MARGIN); if ((EventType)typeProp.enumValueIndex == EventType.Trigger) { list.Draw(nameof(StateEventAsset.TriggerTime)); } else { list.Draw(nameof(StateEventAsset.StartTime), INTERNAL_VERTICAL_MARGIN); list.Draw(nameof(StateEventAsset.EndTime)); } } list.Space(BOTTOM_PADDING); }; }