76 lines
3.5 KiB
C#
76 lines
3.5 KiB
C#
using Minigames.Airplane.Data;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace Editor.Minigames.Airplane
|
|
{
|
|
/// <summary>
|
|
/// Custom editor for PrefabSpawnEntryComponent that conditionally shows fields based on spawn mode.
|
|
/// </summary>
|
|
[CustomEditor(typeof(PrefabSpawnEntryComponent))]
|
|
public class PrefabSpawnEntryComponentEditor : UnityEditor.Editor
|
|
{
|
|
private SerializedProperty _spawnPositionModeProperty;
|
|
private SerializedProperty _specifiedYProperty;
|
|
private SerializedProperty _randomYMinProperty;
|
|
private SerializedProperty _randomYMaxProperty;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_spawnPositionModeProperty = serializedObject.FindProperty("spawnPositionMode");
|
|
_specifiedYProperty = serializedObject.FindProperty("specifiedY");
|
|
_randomYMinProperty = serializedObject.FindProperty("randomYMin");
|
|
_randomYMaxProperty = serializedObject.FindProperty("randomYMax");
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
serializedObject.Update();
|
|
|
|
EditorGUILayout.LabelField("Prefab Spawn Positioning", EditorStyles.boldLabel);
|
|
EditorGUILayout.HelpBox("Controls how this prefab is positioned vertically when spawned. If this component is missing, spawner uses default settings from AirplaneSettings.", MessageType.Info);
|
|
EditorGUILayout.Space();
|
|
|
|
// Always show the mode selector
|
|
EditorGUILayout.PropertyField(_spawnPositionModeProperty, new GUIContent("Spawn Position Mode"));
|
|
|
|
SpawnPositionMode currentMode = (SpawnPositionMode)_spawnPositionModeProperty.enumValueIndex;
|
|
|
|
EditorGUILayout.Space();
|
|
|
|
// Show mode-specific fields
|
|
switch (currentMode)
|
|
{
|
|
case SpawnPositionMode.SnapToGround:
|
|
EditorGUILayout.HelpBox("Object will raycast down to find ground and snap its bottom to the surface. If no ground is found, fallback Y position from settings will be used.", MessageType.Info);
|
|
break;
|
|
|
|
case SpawnPositionMode.SpecifiedY:
|
|
EditorGUILayout.LabelField("Fixed Y Position", EditorStyles.boldLabel);
|
|
EditorGUILayout.PropertyField(_specifiedYProperty, new GUIContent("Y Position"));
|
|
EditorGUILayout.HelpBox("Object will spawn at this exact Y coordinate.", MessageType.Info);
|
|
break;
|
|
|
|
case SpawnPositionMode.RandomRange:
|
|
EditorGUILayout.LabelField("Random Y Range", EditorStyles.boldLabel);
|
|
EditorGUILayout.PropertyField(_randomYMinProperty, new GUIContent("Min Y"));
|
|
EditorGUILayout.PropertyField(_randomYMaxProperty, new GUIContent("Max Y"));
|
|
|
|
// Validation
|
|
if (_randomYMinProperty.floatValue > _randomYMaxProperty.floatValue)
|
|
{
|
|
EditorGUILayout.HelpBox("Min Y should be less than Max Y!", MessageType.Warning);
|
|
}
|
|
else
|
|
{
|
|
EditorGUILayout.HelpBox($"Object will spawn at random Y between {_randomYMinProperty.floatValue:F2} and {_randomYMaxProperty.floatValue:F2}.", MessageType.Info);
|
|
}
|
|
break;
|
|
}
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
}
|
|
}
|
|
}
|
|
|