Files
HauntedBloodlines/Assets/Editor/NearbyRoomsMultiChangerEditor.cs
2025-05-29 22:31:40 +03:00

40 lines
1.6 KiB
C#

using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(NearbyRoomsMultiChanger.RoomCategoryChange))]
public class RoomCategoryChangeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
SerializedProperty roomTriggerProp = property.FindPropertyRelative("roomTrigger");
SerializedProperty categoryIndexProp = property.FindPropertyRelative("categoryIndex");
Rect triggerRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
Rect popupRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight + 2, position.width, EditorGUIUtility.singleLineHeight);
EditorGUI.PropertyField(triggerRect, roomTriggerProp);
RoomTrigger trigger = roomTriggerProp.objectReferenceValue as RoomTrigger;
if (trigger != null && trigger.nearbyRoomCategories != null && trigger.nearbyRoomCategories.Count > 0)
{
string[] options = new string[trigger.nearbyRoomCategories.Count];
for (int i = 0; i < options.Length; i++)
{
options[i] = trigger.nearbyRoomCategories[i].categoryName;
}
categoryIndexProp.intValue = EditorGUI.Popup(popupRect, "Selected Category", categoryIndexProp.intValue, options);
}
else
{
EditorGUI.PropertyField(popupRect, categoryIndexProp);
}
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUIUtility.singleLineHeight * 2 + 4;
}
}