fit : playable with controller
This commit is contained in:
@@ -2,6 +2,8 @@ using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.SceneManagement;
|
||||
using OctoRef = OctoCore.OctoCore;
|
||||
|
||||
namespace Unheimlich.Navigation.Debuging
|
||||
@@ -9,8 +11,8 @@ namespace Unheimlich.Navigation.Debuging
|
||||
/// <summary>
|
||||
/// Listens for debug input combos and drives DebugNavigation.
|
||||
///
|
||||
/// — Gamepad : L2+R2 held 0.5s → unlock/lock. L2/R2 short press → prev/next (menu must be open).
|
||||
/// — Keyboard : backquote (² AZERTY / ~ QWERTY) → unlock/lock. ←/→ → prev/next.
|
||||
/// — Gamepad : L3+R3 simultaneously → unlock/lock. L2/R2 → prev/next scene.
|
||||
/// — Keyboard : backquote (² AZERTY / ~ QWERTY) → unlock/lock. A/E → prev/next.
|
||||
///
|
||||
/// Device display: switches based on last active input, not physical connection.
|
||||
/// </summary>
|
||||
@@ -19,10 +21,6 @@ namespace Unheimlich.Navigation.Debuging
|
||||
[Header("Data")]
|
||||
[SerializeField] private DebugNavigation _debugNavigation;
|
||||
|
||||
[Header("Timing")]
|
||||
[Tooltip("Duration in seconds L2+R2 must be held to toggle the debug menu.")]
|
||||
[SerializeField] private float _holdDuration = 0.5f;
|
||||
|
||||
[Header("Unlock Events")]
|
||||
public UnityEvent OnDebugMenuUnlockedGamepad;
|
||||
public UnityEvent OnDebugMenuUnlockedKeyboard;
|
||||
@@ -41,17 +39,14 @@ namespace Unheimlich.Navigation.Debuging
|
||||
|
||||
// ── State ────────────────────────────────────────────────────────────
|
||||
|
||||
private bool _isUnlocked = false;
|
||||
private bool _isL2Held = false;
|
||||
private bool _isR2Held = false;
|
||||
private float _holdTimer = 0f;
|
||||
private bool _holdFired = false;
|
||||
private bool _isUnlocked = false;
|
||||
private bool _lastWasGamepad = false;
|
||||
|
||||
// Input Actions
|
||||
private InputAction _keyboardUnlockAction;
|
||||
private InputAction _gamepadL2Action;
|
||||
private InputAction _gamepadR2Action;
|
||||
private InputAction _gamepadUnlockAction;
|
||||
private InputAction _gamepadPreviousAction;
|
||||
private InputAction _gamepadNextAction;
|
||||
private InputAction _keyboardPreviousAction;
|
||||
private InputAction _keyboardNextAction;
|
||||
private InputAction _anyGamepadAction;
|
||||
@@ -59,62 +54,60 @@ namespace Unheimlich.Navigation.Debuging
|
||||
|
||||
// ── Unity lifecycle ──────────────────────────────────────────────────
|
||||
|
||||
private void Awake() => BuildInputActions();
|
||||
private void Awake() => BuildInputActions();
|
||||
private void OnEnable() => EnableActions();
|
||||
private void Start()
|
||||
{
|
||||
StartCoroutine(InitWhenReady());
|
||||
}
|
||||
DebugManager.instance.enableRuntimeUI = false;
|
||||
|
||||
private IEnumerator InitWhenReady()
|
||||
{
|
||||
yield return new WaitUntil(() => OctoRef.Instance != null);
|
||||
yield return new WaitUntil(() => OctoRef.Instance.Navigation.CurrentScene != null);
|
||||
|
||||
SyncDebugNavigation();
|
||||
SubscribeToSceneEvents();
|
||||
StartCoroutine(InitWhenReady());
|
||||
SceneManager.sceneLoaded += OnUnitySceneLoaded;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
DisableActions();
|
||||
UnsubscribeFromSceneEvents();
|
||||
SceneManager.sceneLoaded -= OnUnitySceneLoaded;
|
||||
}
|
||||
private void OnDestroy() => DisposeActions();
|
||||
private void Update() => TickHoldTimer();
|
||||
private void OnDestroy() => DisposeActions();
|
||||
|
||||
// ── Build ────────────────────────────────────────────────────────────
|
||||
|
||||
private void BuildInputActions()
|
||||
{
|
||||
// Keyboard unlock toggle
|
||||
// Keyboard unlock : backquote (² AZERTY / ~ QWERTY)
|
||||
_keyboardUnlockAction = new InputAction("DebugUnlockKeyboard", InputActionType.Button);
|
||||
_keyboardUnlockAction.AddBinding("<Keyboard>/backquote");
|
||||
_keyboardUnlockAction.performed += _ => ToggleDebugMenu(false);
|
||||
|
||||
// Gamepad L2 / R2
|
||||
_gamepadL2Action = new InputAction("DebugL2", InputActionType.Button);
|
||||
_gamepadL2Action.AddBinding("<Gamepad>/leftTrigger")
|
||||
.WithProcessor("AxisDeadzone(min=0.5,max=1)");
|
||||
_gamepadL2Action.performed += _ => OnL2Down();
|
||||
_gamepadL2Action.canceled += _ => OnL2Up();
|
||||
// Gamepad unlock : L3 + R3 simultaneously
|
||||
_gamepadUnlockAction = new InputAction("DebugUnlockGamepad", InputActionType.Button);
|
||||
_gamepadUnlockAction.AddCompositeBinding("ButtonWithOneModifier")
|
||||
.With("Modifier", "<Gamepad>/leftStickPress")
|
||||
.With("Button", "<Gamepad>/rightStickPress");
|
||||
_gamepadUnlockAction.performed += _ => ToggleDebugMenu(true);
|
||||
|
||||
_gamepadR2Action = new InputAction("DebugR2", InputActionType.Button);
|
||||
_gamepadR2Action.AddBinding("<Gamepad>/rightTrigger")
|
||||
// Gamepad navigation : L2 / R2
|
||||
_gamepadPreviousAction = new InputAction("DebugPrevGamepad", InputActionType.Button);
|
||||
_gamepadPreviousAction.AddBinding("<Gamepad>/leftTrigger")
|
||||
.WithProcessor("AxisDeadzone(min=0.5,max=1)");
|
||||
_gamepadR2Action.performed += _ => OnR2Down();
|
||||
_gamepadR2Action.canceled += _ => OnR2Up();
|
||||
_gamepadPreviousAction.performed += _ => TryPrevious();
|
||||
|
||||
// Keyboard navigation
|
||||
_gamepadNextAction = new InputAction("DebugNextGamepad", InputActionType.Button);
|
||||
_gamepadNextAction.AddBinding("<Gamepad>/rightTrigger")
|
||||
.WithProcessor("AxisDeadzone(min=0.5,max=1)");
|
||||
_gamepadNextAction.performed += _ => TryNext();
|
||||
|
||||
// Keyboard navigation : A / E
|
||||
_keyboardPreviousAction = new InputAction("DebugPrevKeyboard", InputActionType.Button);
|
||||
_keyboardPreviousAction.AddBinding("<Keyboard>/leftArrow");
|
||||
_keyboardPreviousAction.AddBinding("<Keyboard>/q");
|
||||
_keyboardPreviousAction.performed += _ => TryPrevious();
|
||||
|
||||
_keyboardNextAction = new InputAction("DebugNextKeyboard", InputActionType.Button);
|
||||
_keyboardNextAction.AddBinding("<Keyboard>/rightArrow");
|
||||
_keyboardNextAction.AddBinding("<Keyboard>/e");
|
||||
_keyboardNextAction.performed += _ => TryNext();
|
||||
|
||||
// Device detection — wildcard bindings
|
||||
// Device detection
|
||||
_anyGamepadAction = new InputAction("AnyGamepad", InputActionType.PassThrough);
|
||||
_anyGamepadAction.AddBinding("<Gamepad>/leftStick");
|
||||
_anyGamepadAction.AddBinding("<Gamepad>/rightStick");
|
||||
@@ -124,6 +117,8 @@ namespace Unheimlich.Navigation.Debuging
|
||||
_anyGamepadAction.AddBinding("<Gamepad>/buttonWest");
|
||||
_anyGamepadAction.AddBinding("<Gamepad>/leftShoulder");
|
||||
_anyGamepadAction.AddBinding("<Gamepad>/rightShoulder");
|
||||
_anyGamepadAction.AddBinding("<Gamepad>/leftTrigger");
|
||||
_anyGamepadAction.AddBinding("<Gamepad>/rightTrigger");
|
||||
_anyGamepadAction.AddBinding("<Gamepad>/start");
|
||||
_anyGamepadAction.AddBinding("<Gamepad>/select");
|
||||
_anyGamepadAction.AddBinding("<Gamepad>/dpad");
|
||||
@@ -140,8 +135,9 @@ namespace Unheimlich.Navigation.Debuging
|
||||
private void EnableActions()
|
||||
{
|
||||
_keyboardUnlockAction?.Enable();
|
||||
_gamepadL2Action?.Enable();
|
||||
_gamepadR2Action?.Enable();
|
||||
_gamepadUnlockAction?.Enable();
|
||||
_gamepadPreviousAction?.Enable();
|
||||
_gamepadNextAction?.Enable();
|
||||
_keyboardPreviousAction?.Enable();
|
||||
_keyboardNextAction?.Enable();
|
||||
_anyGamepadAction?.Enable();
|
||||
@@ -151,8 +147,9 @@ namespace Unheimlich.Navigation.Debuging
|
||||
private void DisableActions()
|
||||
{
|
||||
_keyboardUnlockAction?.Disable();
|
||||
_gamepadL2Action?.Disable();
|
||||
_gamepadR2Action?.Disable();
|
||||
_gamepadUnlockAction?.Disable();
|
||||
_gamepadPreviousAction?.Disable();
|
||||
_gamepadNextAction?.Disable();
|
||||
_keyboardPreviousAction?.Disable();
|
||||
_keyboardNextAction?.Disable();
|
||||
_anyGamepadAction?.Disable();
|
||||
@@ -162,75 +159,49 @@ namespace Unheimlich.Navigation.Debuging
|
||||
private void DisposeActions()
|
||||
{
|
||||
_keyboardUnlockAction?.Dispose();
|
||||
_gamepadL2Action?.Dispose();
|
||||
_gamepadR2Action?.Dispose();
|
||||
_gamepadUnlockAction?.Dispose();
|
||||
_gamepadPreviousAction?.Dispose();
|
||||
_gamepadNextAction?.Dispose();
|
||||
_keyboardPreviousAction?.Dispose();
|
||||
_keyboardNextAction?.Dispose();
|
||||
_anyGamepadAction?.Dispose();
|
||||
_anyKeyboardAction?.Dispose();
|
||||
}
|
||||
|
||||
// ── L2 / R2 hold logic ───────────────────────────────────────────────
|
||||
// ── Init ─────────────────────────────────────────────────────────────
|
||||
|
||||
private void OnL2Down()
|
||||
private IEnumerator InitWhenReady()
|
||||
{
|
||||
_isL2Held = true;
|
||||
if (_isR2Held) StartHold();
|
||||
yield return new WaitUntil(() => OctoRef.Instance != null);
|
||||
yield return new WaitUntil(() => OctoRef.Instance.Navigation.CurrentScene != null);
|
||||
|
||||
SyncDebugNavigation();
|
||||
SubscribeToSceneEvents();
|
||||
}
|
||||
|
||||
private void OnL2Up()
|
||||
// ── Scene events ─────────────────────────────────────────────────────
|
||||
|
||||
private void SubscribeToSceneEvents()
|
||||
{
|
||||
// Short press navigation — only if hold didn't fire
|
||||
if (_isUnlocked && !_holdFired && !_isR2Held)
|
||||
TryPrevious();
|
||||
|
||||
_isL2Held = false;
|
||||
|
||||
// Reset hold only when both triggers are released
|
||||
if (!_isR2Held) ResetHold();
|
||||
if (OctoRef.Instance == null) return;
|
||||
OctoRef.Instance.Navigation.OnSceneLoadCompleted += OnSceneLoadCompleted;
|
||||
}
|
||||
|
||||
private void OnR2Down()
|
||||
private void UnsubscribeFromSceneEvents()
|
||||
{
|
||||
_isR2Held = true;
|
||||
if (_isL2Held) StartHold();
|
||||
if (OctoRef.Instance == null) return;
|
||||
OctoRef.Instance.Navigation.OnSceneLoadCompleted -= OnSceneLoadCompleted;
|
||||
}
|
||||
|
||||
private void OnR2Up()
|
||||
private void OnUnitySceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
// Short press navigation — only if hold didn't fire
|
||||
if (_isUnlocked && !_holdFired && !_isL2Held)
|
||||
TryNext();
|
||||
|
||||
_isR2Held = false;
|
||||
|
||||
// Reset hold only when both triggers are released
|
||||
if (!_isL2Held) ResetHold();
|
||||
UnsubscribeFromSceneEvents();
|
||||
SubscribeToSceneEvents();
|
||||
}
|
||||
|
||||
private void StartHold()
|
||||
private void OnSceneLoadCompleted(OctoCore.Navigation.Data.OctoSceneData sceneData)
|
||||
{
|
||||
_holdTimer = 0f;
|
||||
_holdFired = false;
|
||||
}
|
||||
|
||||
private void ResetHold()
|
||||
{
|
||||
_holdTimer = 0f;
|
||||
_holdFired = false;
|
||||
}
|
||||
|
||||
private void TickHoldTimer()
|
||||
{
|
||||
if (!_isL2Held || !_isR2Held || _holdFired) return;
|
||||
|
||||
_holdTimer += Time.unscaledDeltaTime;
|
||||
|
||||
if (_holdTimer >= _holdDuration)
|
||||
{
|
||||
_holdFired = true;
|
||||
ToggleDebugMenu(true);
|
||||
}
|
||||
_debugNavigation?.SyncWithCurrentScene(sceneData);
|
||||
}
|
||||
|
||||
// ── Device switch ────────────────────────────────────────────────────
|
||||
@@ -251,23 +222,6 @@ namespace Unheimlich.Navigation.Debuging
|
||||
|
||||
// ── Logic ────────────────────────────────────────────────────────────
|
||||
|
||||
private void SubscribeToSceneEvents()
|
||||
{
|
||||
if (OctoRef.Instance == null) return;
|
||||
OctoRef.Instance.Navigation.OnSceneLoadCompleted += OnSceneLoadCompleted;
|
||||
}
|
||||
|
||||
private void UnsubscribeFromSceneEvents()
|
||||
{
|
||||
if (OctoRef.Instance == null) return;
|
||||
OctoRef.Instance.Navigation.OnSceneLoadCompleted -= OnSceneLoadCompleted;
|
||||
}
|
||||
|
||||
private void OnSceneLoadCompleted(OctoCore.Navigation.Data.OctoSceneData sceneData)
|
||||
{
|
||||
_debugNavigation?.SyncWithCurrentScene(sceneData);
|
||||
}
|
||||
|
||||
private void SyncDebugNavigation()
|
||||
{
|
||||
if (_debugNavigation == null || OctoRef.Instance == null) return;
|
||||
|
||||
Reference in New Issue
Block a user