105 lines
5.3 KiB
C#
105 lines
5.3 KiB
C#
|
|
using Minigames.Airplane.Core;
|
||
|
|
using Minigames.Airplane.Data;
|
||
|
|
using UnityEditor;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace Editor.CustomEditorsAndDrawers
|
||
|
|
{
|
||
|
|
[CustomPropertyDrawer(typeof(AirplaneSpawnManager.TargetPrefabEntry))]
|
||
|
|
public class TargetPrefabEntryDrawer : PropertyDrawer
|
||
|
|
{
|
||
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||
|
|
{
|
||
|
|
EditorGUI.BeginProperty(position, label, property);
|
||
|
|
|
||
|
|
// Draw foldout
|
||
|
|
property.isExpanded = EditorGUI.Foldout(new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight),
|
||
|
|
property.isExpanded, label, true);
|
||
|
|
|
||
|
|
if (property.isExpanded)
|
||
|
|
{
|
||
|
|
EditorGUI.indentLevel++;
|
||
|
|
float yPos = position.y + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||
|
|
|
||
|
|
// Draw targetKey
|
||
|
|
SerializedProperty targetKeyProp = property.FindPropertyRelative("targetKey");
|
||
|
|
EditorGUI.PropertyField(new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight), targetKeyProp);
|
||
|
|
yPos += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||
|
|
|
||
|
|
// Draw prefab
|
||
|
|
SerializedProperty prefabProp = property.FindPropertyRelative("prefab");
|
||
|
|
EditorGUI.PropertyField(new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight), prefabProp);
|
||
|
|
yPos += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||
|
|
|
||
|
|
// Draw spawn position mode
|
||
|
|
SerializedProperty spawnModeProp = property.FindPropertyRelative("spawnPositionMode");
|
||
|
|
EditorGUI.PropertyField(new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight), spawnModeProp);
|
||
|
|
yPos += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||
|
|
|
||
|
|
// Draw conditional fields based on mode
|
||
|
|
SpawnPositionMode mode = (SpawnPositionMode)spawnModeProp.enumValueIndex;
|
||
|
|
|
||
|
|
switch (mode)
|
||
|
|
{
|
||
|
|
case SpawnPositionMode.SpecifiedY:
|
||
|
|
SerializedProperty specifiedYProp = property.FindPropertyRelative("specifiedY");
|
||
|
|
EditorGUI.PropertyField(new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight), specifiedYProp);
|
||
|
|
break;
|
||
|
|
|
||
|
|
case SpawnPositionMode.RandomRange:
|
||
|
|
SerializedProperty randomYMinProp = property.FindPropertyRelative("randomYMin");
|
||
|
|
SerializedProperty randomYMaxProp = property.FindPropertyRelative("randomYMax");
|
||
|
|
EditorGUI.PropertyField(new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight), randomYMinProp);
|
||
|
|
yPos += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||
|
|
EditorGUI.PropertyField(new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight), randomYMaxProp);
|
||
|
|
break;
|
||
|
|
|
||
|
|
case SpawnPositionMode.SnapToGround:
|
||
|
|
// No additional fields needed
|
||
|
|
EditorGUI.LabelField(new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight),
|
||
|
|
"Uses raycast to snap to ground", EditorStyles.miniLabel);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
EditorGUI.indentLevel--;
|
||
|
|
}
|
||
|
|
|
||
|
|
EditorGUI.EndProperty();
|
||
|
|
}
|
||
|
|
|
||
|
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||
|
|
{
|
||
|
|
if (!property.isExpanded)
|
||
|
|
return EditorGUIUtility.singleLineHeight;
|
||
|
|
|
||
|
|
float height = EditorGUIUtility.singleLineHeight; // Foldout
|
||
|
|
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // targetKey
|
||
|
|
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // prefab
|
||
|
|
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // spawnPositionMode
|
||
|
|
|
||
|
|
// Add height for mode-specific fields
|
||
|
|
SerializedProperty spawnModeProp = property.FindPropertyRelative("spawnPositionMode");
|
||
|
|
SpawnPositionMode mode = (SpawnPositionMode)spawnModeProp.enumValueIndex;
|
||
|
|
|
||
|
|
switch (mode)
|
||
|
|
{
|
||
|
|
case SpawnPositionMode.SpecifiedY:
|
||
|
|
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // specifiedY
|
||
|
|
break;
|
||
|
|
|
||
|
|
case SpawnPositionMode.RandomRange:
|
||
|
|
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // randomYMin
|
||
|
|
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // randomYMax
|
||
|
|
break;
|
||
|
|
|
||
|
|
case SpawnPositionMode.SnapToGround:
|
||
|
|
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // Info label
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
return height;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|