Files
AppleHillsProduction/Assets/Editor/ControllerSwitchItemEditor.cs
tschesky c62f169d08 maze_switching (#82)
Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com>
Reviewed-on: #82
2025-12-15 09:20:15 +00:00

102 lines
4.2 KiB
C#

using UnityEditor;
using UnityEngine;
using Items;
namespace Editor
{
/// <summary>
/// Custom editor for ControllerSwitchItem that shows only relevant fields based on camera switch mode.
/// </summary>
[CustomEditor(typeof(ControllerSwitchItem))]
public class ControllerSwitchItemEditor : UnityEditor.Editor
{
private SerializedProperty _targetControllerName;
private SerializedProperty _cameraSwitchMode;
private SerializedProperty _targetVirtualCamera;
private SerializedProperty _targetCameraState;
private SerializedProperty _visualRepresentation;
// Base class properties
private SerializedProperty _isOneTime;
private SerializedProperty _cooldown;
private SerializedProperty _characterToInteract;
private void OnEnable()
{
// Controller Switch Settings
_targetControllerName = serializedObject.FindProperty("targetControllerName");
_cameraSwitchMode = serializedObject.FindProperty("cameraSwitchMode");
_targetVirtualCamera = serializedObject.FindProperty("targetVirtualCamera");
_targetCameraState = serializedObject.FindProperty("targetCameraState");
_visualRepresentation = serializedObject.FindProperty("visualRepresentation");
// Base class properties
_isOneTime = serializedObject.FindProperty("isOneTime");
_cooldown = serializedObject.FindProperty("cooldown");
_characterToInteract = serializedObject.FindProperty("characterToInteract");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
// Draw script field (read-only)
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField("Script", MonoScript.FromMonoBehaviour((MonoBehaviour)target), GetType(), false);
EditorGUI.EndDisabledGroup();
EditorGUILayout.Space();
// Interaction Settings (from base class)
EditorGUILayout.LabelField("Interaction Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(_isOneTime);
EditorGUILayout.PropertyField(_cooldown);
EditorGUILayout.PropertyField(_characterToInteract);
EditorGUILayout.Space();
// Controller Switch Settings
EditorGUILayout.LabelField("Controller Switch Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(_targetControllerName);
EditorGUILayout.Space();
// Camera Settings
EditorGUILayout.LabelField("Camera Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(_cameraSwitchMode);
// Show relevant camera fields based on mode
CameraSwitchMode mode = (CameraSwitchMode)_cameraSwitchMode.enumValueIndex;
switch (mode)
{
case CameraSwitchMode.None:
EditorGUILayout.HelpBox("No camera switching will occur. Only the controller will be switched.", MessageType.Info);
break;
case CameraSwitchMode.DirectReference:
EditorGUILayout.PropertyField(_targetVirtualCamera);
if (_targetVirtualCamera.objectReferenceValue == null)
{
EditorGUILayout.HelpBox("Assign a Cinemachine camera to blend to when switching controllers.", MessageType.Warning);
}
break;
case CameraSwitchMode.TrashMazeCameraState:
EditorGUILayout.PropertyField(_targetCameraState);
EditorGUILayout.HelpBox("Uses TrashMazeCameraController to switch camera state. Make sure TrashMazeCameraController is present in the scene.", MessageType.Info);
break;
}
EditorGUILayout.Space();
// Visual Feedback
EditorGUILayout.LabelField("Visual Feedback", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(_visualRepresentation);
serializedObject.ApplyModifiedProperties();
}
}
}