using UnityEngine; using UnityEditor; using SplashEdit.RuntimeCode; namespace SplashEdit.EditorCode { /// /// Custom inspector for PSXInteractable component. /// [CustomEditor(typeof(PSXInteractable))] public class PSXInteractableEditor : UnityEditor.Editor { private bool _interactionFoldout = true; private bool _advancedFoldout = false; private SerializedProperty _interactionRadius; private SerializedProperty _interactButton; private SerializedProperty _isRepeatable; private SerializedProperty _cooldownFrames; private SerializedProperty _showPrompt; private SerializedProperty _requireLineOfSight; private SerializedProperty _interactionOffset; private static readonly string[] ButtonNames = { "Select", "L3", "R3", "Start", "Up", "Right", "Down", "Left", "L2", "R2", "L1", "R1", "Triangle", "Circle", "Cross", "Square" }; private void OnEnable() { _interactionRadius = serializedObject.FindProperty("interactionRadius"); _interactButton = serializedObject.FindProperty("interactButton"); _isRepeatable = serializedObject.FindProperty("isRepeatable"); _cooldownFrames = serializedObject.FindProperty("cooldownFrames"); _showPrompt = serializedObject.FindProperty("showPrompt"); _requireLineOfSight = serializedObject.FindProperty("requireLineOfSight"); _interactionOffset = serializedObject.FindProperty("interactionOffset"); } public override void OnInspectorGUI() { serializedObject.Update(); DrawHeader(); EditorGUILayout.Space(5); _interactionFoldout = DrawFoldoutSection("Interaction Settings", _interactionFoldout, () => { EditorGUILayout.PropertyField(_interactionRadius); // Button selector with visual EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Interact Button"); _interactButton.intValue = EditorGUILayout.Popup(_interactButton.intValue, ButtonNames); EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(_isRepeatable); if (_isRepeatable.boolValue) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(_cooldownFrames, new GUIContent("Cooldown (frames)")); // Show cooldown in seconds float seconds = _cooldownFrames.intValue / 60f; EditorGUILayout.LabelField($"≈ {seconds:F2} seconds at 60fps", EditorStyles.miniLabel); EditorGUI.indentLevel--; } EditorGUILayout.PropertyField(_showPrompt); }); _advancedFoldout = DrawFoldoutSection("Advanced", _advancedFoldout, () => { EditorGUILayout.PropertyField(_requireLineOfSight); EditorGUILayout.PropertyField(_interactionOffset); }); DrawLuaEventsInfo(new[] { "onInteract" }); serializedObject.ApplyModifiedProperties(); } private void DrawHeader() { EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); GUILayout.Label(EditorGUIUtility.IconContent("d_Selectable Icon"), GUILayout.Width(30), GUILayout.Height(30)); EditorGUILayout.BeginVertical(); GUILayout.Label("PSX Interactable", EditorStyles.boldLabel); GUILayout.Label("Player interaction trigger for PS1", EditorStyles.miniLabel); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } private bool DrawFoldoutSection(string title, bool isExpanded, System.Action drawContent) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); isExpanded = EditorGUILayout.Foldout(isExpanded, title, true, EditorStyles.foldoutHeader); if (isExpanded) { EditorGUI.indentLevel++; drawContent?.Invoke(); EditorGUI.indentLevel--; } EditorGUILayout.EndVertical(); EditorGUILayout.Space(3); return isExpanded; } private void DrawLuaEventsInfo(string[] events) { EditorGUILayout.Space(5); EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label("Lua Events", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); foreach (var evt in events) { GUILayout.Label($"• {evt}", EditorStyles.miniLabel); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } } }