97 lines
4.2 KiB
C#
97 lines
4.2 KiB
C#
using Minigames.Airplane.Data;
|
|
using Minigames.Airplane.Settings;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace Editor.Minigames.Airplane
|
|
{
|
|
/// <summary>
|
|
/// Custom editor for AirplaneSettings that conditionally shows default obstacle positioning fields.
|
|
/// Integrates with SettingsEditorWindow.
|
|
/// </summary>
|
|
[CustomEditor(typeof(AirplaneSettings))]
|
|
public class AirplaneSettingsEditor : UnityEditor.Editor
|
|
{
|
|
public override void OnInspectorGUI()
|
|
{
|
|
serializedObject.Update();
|
|
|
|
// Draw all properties except the default obstacle positioning section
|
|
SerializedProperty iterator = serializedObject.GetIterator();
|
|
bool enterChildren = true;
|
|
|
|
while (iterator.NextVisible(enterChildren))
|
|
{
|
|
enterChildren = false;
|
|
|
|
// Skip script field
|
|
if (iterator.propertyPath == "m_Script")
|
|
continue;
|
|
|
|
// Handle Default Obstacle Positioning section specially
|
|
if (iterator.propertyPath == "defaultObstaclePositionMode")
|
|
{
|
|
DrawDefaultObstaclePositioningSection();
|
|
|
|
// Skip the related fields as we'll draw them conditionally
|
|
iterator.NextVisible(false); // Skip defaultObstacleRandomYMin
|
|
iterator.NextVisible(false); // Skip defaultObstacleRandomYMax
|
|
continue;
|
|
}
|
|
|
|
EditorGUILayout.PropertyField(iterator, true);
|
|
}
|
|
|
|
// Apply changes and mark dirty for SettingsEditorWindow integration
|
|
if (serializedObject.ApplyModifiedProperties())
|
|
{
|
|
EditorUtility.SetDirty(target);
|
|
}
|
|
}
|
|
|
|
private void DrawDefaultObstaclePositioningSection()
|
|
{
|
|
var modeProperty = serializedObject.FindProperty("defaultObstaclePositionMode");
|
|
var randomYMinProperty = serializedObject.FindProperty("defaultObstacleRandomYMin");
|
|
var randomYMaxProperty = serializedObject.FindProperty("defaultObstacleRandomYMax");
|
|
|
|
EditorGUILayout.Space();
|
|
EditorGUILayout.PropertyField(modeProperty, new GUIContent("Default Position Mode"));
|
|
|
|
SpawnPositionMode currentMode = (SpawnPositionMode)modeProperty.enumValueIndex;
|
|
|
|
EditorGUILayout.Space(5);
|
|
|
|
switch (currentMode)
|
|
{
|
|
case SpawnPositionMode.SnapToGround:
|
|
EditorGUILayout.HelpBox("Obstacles will raycast to find ground and snap to it. If raycast fails, Fallback Y Position (configured in Ground Snapping section above) will be used.", MessageType.Info);
|
|
break;
|
|
|
|
case SpawnPositionMode.SpecifiedY:
|
|
EditorGUILayout.HelpBox("Obstacles will spawn at Fallback Y Position (configured in Ground Snapping section above).", MessageType.Info);
|
|
break;
|
|
|
|
case SpawnPositionMode.RandomRange:
|
|
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
|
|
EditorGUILayout.LabelField("Random Y Range", EditorStyles.miniBoldLabel);
|
|
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($"Obstacles will spawn at random Y between {randomYMinProperty.floatValue:F2} and {randomYMaxProperty.floatValue:F2}.", MessageType.Info);
|
|
}
|
|
EditorGUILayout.EndVertical();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|