using UnityEngine; using UnityEditor; using Interactions; using System; [CustomPropertyDrawer(typeof(InteractionTimelineAction.TimelineEventMapping))] public class TimelineEventMappingDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Use default property drawer, but initialize values if needed InitializeDefaultValues(property); EditorGUI.PropertyField(position, property, label, true); } public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { return EditorGUI.GetPropertyHeight(property, label, true); } // Called when property is created to initialize default values private void InitializeDefaultValues(SerializedProperty property) { // Check if this is a new/empty property that needs initialization SerializedProperty timelinesArray = property.FindPropertyRelative("timelines"); if (timelinesArray != null && timelinesArray.arraySize == 0) { // This appears to be a new property, so initialize default values // Initialize timelines array with one empty element timelinesArray.ClearArray(); timelinesArray.InsertArrayElementAtIndex(0); timelinesArray.GetArrayElementAtIndex(0).objectReferenceValue = null; // Set default binding values property.FindPropertyRelative("bindPlayerCharacter").boolValue = true; property.FindPropertyRelative("bindPulverCharacter").boolValue = true; property.FindPropertyRelative("playerTrackName").stringValue = "Player"; property.FindPropertyRelative("pulverTrackName").stringValue = "Pulver"; property.FindPropertyRelative("timeoutSeconds").floatValue = 30f; property.FindPropertyRelative("loopLast").boolValue = false; property.FindPropertyRelative("loopAll").boolValue = false; // Make sure to apply modifications property.serializedObject.ApplyModifiedProperties(); } } }