Files
HauntedBloodlines/Assets/Scripts/Events/EventSetDropdownDrawer.cs
2025-05-29 22:31:40 +03:00

45 lines
1.3 KiB
C#

using UnityEditor;
using UnityEngine;
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(EventSetDropdownAttribute))]
public class EventSetDropdownDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var mono = property.serializedObject.targetObject as MonoBehaviour;
if (mono == null)
{
EditorGUI.PropertyField(position, property, label);
return;
}
var targetToolField = mono.GetType().GetField("targetTool");
if (targetToolField == null)
{
EditorGUI.PropertyField(position, property, label);
return;
}
var targetTool = targetToolField.GetValue(mono) as RuntimeEventTool;
if (targetTool == null)
{
EditorGUI.HelpBox(position, "Assign a RuntimeEventTool", MessageType.Info);
return;
}
var sets = targetTool.GetEventSets();
string[] options = sets.ConvertAll(s => s.setName).ToArray();
int index = Mathf.Max(0, System.Array.IndexOf(options, property.stringValue));
int newIndex = EditorGUI.Popup(position, label.text, index, options);
if (newIndex >= 0 && newIndex < options.Length)
{
property.stringValue = options[newIndex];
}
}
}
#endif