Integration of the octo input system and centralization of player values
This commit is contained in:
@@ -1,43 +1,30 @@
|
||||
using UnityEngine;
|
||||
using Unheimlich.Core;
|
||||
using Unheimlich.Data.CameraSettings;
|
||||
using Unheimlich.Gameplay.CameraControl;
|
||||
using Unheimlich.Gameplay.Player;
|
||||
using PlayerInput = Unheimlich.Managers.PlayerInputManager;
|
||||
using InputManager = Unheimlich.Managers.InputManager;
|
||||
using Unheimlich.UI.DetectiveBoard;
|
||||
|
||||
namespace Unheimlich.Gameplay.DetectiveBoard
|
||||
{
|
||||
/// <summary>
|
||||
/// Controls player interaction with the detective board in world space.
|
||||
/// Uses CameraPanController for wide-angle camera movement across the board.
|
||||
/// Activates when player is in range and looking at the board.
|
||||
/// Controls player interaction with the detective board.
|
||||
/// </summary>
|
||||
public class DetectiveBoardController : MonoBehaviour
|
||||
public class DetectiveBoardController : Singleton<DetectiveBoardController>
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private CameraPanController _cameraPanController;
|
||||
[SerializeField] private Transform _boardTransform;
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private CameraPanSettings _boardCameraPanSettings;
|
||||
[SerializeField] private float _activationRange = 2f;
|
||||
[SerializeField] private LayerMask _boardLayer;
|
||||
|
||||
private Camera _playerCamera;
|
||||
private bool _isBoardActive;
|
||||
private CameraPanSettings _originalCameraPanSettings;
|
||||
private CameraHeadBob _cameraHeadBob;
|
||||
|
||||
public bool IsBoardActive => _isBoardActive;
|
||||
|
||||
private void Awake()
|
||||
protected override void OnAwake()
|
||||
{
|
||||
_playerCamera = Camera.main;
|
||||
|
||||
if (_cameraPanController == null)
|
||||
{
|
||||
_cameraPanController = FindFirstObjectByType<CameraPanController>();
|
||||
}
|
||||
|
||||
_cameraHeadBob = FindFirstObjectByType<CameraHeadBob>();
|
||||
}
|
||||
|
||||
@@ -53,24 +40,30 @@ namespace Unheimlich.Gameplay.DetectiveBoard
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if player is looking at the board and in range to activate.
|
||||
/// </summary>
|
||||
private void CheckForBoardActivation()
|
||||
{
|
||||
if (_playerCamera == null || _boardTransform == null)
|
||||
if (PlayerController.Instance == null ||
|
||||
PlayerController.Instance.PlayerCamera == null ||
|
||||
DetectiveBoardCanvas.Instance == null)
|
||||
return;
|
||||
|
||||
float distanceToBoard = Vector3.Distance(_playerCamera.transform.position, _boardTransform.position);
|
||||
var camera = PlayerController.Instance.PlayerCamera;
|
||||
var boardTransform = DetectiveBoardCanvas.Instance.transform;
|
||||
|
||||
float distanceToBoard = Vector3.Distance(camera.transform.position, boardTransform.position);
|
||||
if (distanceToBoard > _activationRange)
|
||||
return;
|
||||
|
||||
Ray ray = new Ray(_playerCamera.transform.position, _playerCamera.transform.forward);
|
||||
Ray ray = new Ray(camera.transform.position, camera.transform.forward);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, _activationRange, _boardLayer))
|
||||
{
|
||||
if (hit.transform.IsChildOf(_boardTransform) || hit.transform == _boardTransform)
|
||||
bool isLookingAtBoard = (hit.transform == boardTransform) ||
|
||||
(boardTransform.IsChildOf(hit.transform)) ||
|
||||
(hit.transform.IsChildOf(boardTransform));
|
||||
|
||||
if (isLookingAtBoard)
|
||||
{
|
||||
var interactAction = PlayerInput.GetInteractAction();
|
||||
var interactAction = InputManager.GetInteractAction();
|
||||
if (interactAction != null && interactAction.WasPressedThisFrame())
|
||||
{
|
||||
ActivateBoard();
|
||||
@@ -79,12 +72,12 @@ namespace Unheimlich.Gameplay.DetectiveBoard
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activates the detective board, switching to pan mode with wide-angle settings.
|
||||
/// </summary>
|
||||
public void ActivateBoard()
|
||||
{
|
||||
if (_cameraPanController == null || _boardCameraPanSettings == null)
|
||||
if (_isBoardActive ||
|
||||
PlayerController.Instance?.CameraPanController == null ||
|
||||
DetectiveBoardCanvas.Instance == null ||
|
||||
_boardCameraPanSettings == null)
|
||||
{
|
||||
Debug.LogError("[DetectiveBoardController] Missing required references!");
|
||||
return;
|
||||
@@ -92,71 +85,73 @@ namespace Unheimlich.Gameplay.DetectiveBoard
|
||||
|
||||
_isBoardActive = true;
|
||||
|
||||
_originalCameraPanSettings = _cameraPanController.Settings;
|
||||
_cameraPanController.Settings = _boardCameraPanSettings;
|
||||
|
||||
_cameraPanController.SaveOriginalState();
|
||||
_cameraPanController.AlignToTarget(_boardTransform, () =>
|
||||
// Disable OctoPlayer completely to prevent ANY input processing
|
||||
if (PlayerController.Instance.Movement != null)
|
||||
{
|
||||
_cameraPanController.StartPan();
|
||||
});
|
||||
|
||||
PlayerInput.SetContext(PlayerInput.InputContext.Listening);
|
||||
|
||||
ApplyHeadBobSettings(_boardCameraPanSettings);
|
||||
|
||||
Debug.Log("[DetectiveBoardController] Detective board activated");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles board interaction while active (panning and exit).
|
||||
/// </summary>
|
||||
private void HandleBoardInteraction()
|
||||
{
|
||||
if (_cameraPanController != null)
|
||||
{
|
||||
_cameraPanController.UpdatePan();
|
||||
PlayerController.Instance.Movement.enabled = false;
|
||||
}
|
||||
|
||||
var exitAction = PlayerInput.GetExitAction();
|
||||
var cameraPan = PlayerController.Instance.CameraPanController;
|
||||
_originalCameraPanSettings = cameraPan.Settings;
|
||||
cameraPan.Settings = _boardCameraPanSettings;
|
||||
|
||||
// Save state for return (before alignment)
|
||||
cameraPan.SaveOriginalState();
|
||||
|
||||
// Align to target, then start pan AFTER alignment completes
|
||||
cameraPan.AlignToTarget(DetectiveBoardCanvas.Instance.transform, () =>
|
||||
{
|
||||
// NOW start pan using the aligned rotation as base
|
||||
cameraPan.StartPan();
|
||||
});
|
||||
|
||||
InputManager.SetContext(InputManager.InputContext.Listening);
|
||||
|
||||
ApplyHeadBobSettings(_boardCameraPanSettings);
|
||||
}
|
||||
|
||||
private void HandleBoardInteraction()
|
||||
{
|
||||
if (PlayerController.Instance?.CameraPanController != null)
|
||||
{
|
||||
PlayerController.Instance.CameraPanController.UpdatePan();
|
||||
}
|
||||
|
||||
var exitAction = InputManager.GetExitAction();
|
||||
if (exitAction != null && exitAction.WasPressedThisFrame())
|
||||
{
|
||||
DeactivateBoard();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deactivates the board and returns to normal gameplay.
|
||||
/// </summary>
|
||||
public void DeactivateBoard()
|
||||
{
|
||||
if (!_isBoardActive)
|
||||
if (!_isBoardActive || PlayerController.Instance?.CameraPanController == null)
|
||||
return;
|
||||
|
||||
_isBoardActive = false;
|
||||
|
||||
if (_cameraPanController != null)
|
||||
var cameraPan = PlayerController.Instance.CameraPanController;
|
||||
cameraPan.StopPan();
|
||||
cameraPan.ReturnToOriginalPosition(() =>
|
||||
{
|
||||
_cameraPanController.StopPan();
|
||||
_cameraPanController.ReturnToOriginalPosition(() =>
|
||||
if (_originalCameraPanSettings != null)
|
||||
{
|
||||
if (_originalCameraPanSettings != null)
|
||||
{
|
||||
_cameraPanController.Settings = _originalCameraPanSettings;
|
||||
}
|
||||
});
|
||||
}
|
||||
cameraPan.Settings = _originalCameraPanSettings;
|
||||
}
|
||||
|
||||
// Re-enable OctoPlayer AFTER the return animation completes
|
||||
if (PlayerController.Instance?.Movement != null)
|
||||
{
|
||||
PlayerController.Instance.Movement.enabled = true;
|
||||
}
|
||||
});
|
||||
|
||||
PlayerInput.SetContext(PlayerInput.InputContext.Normal);
|
||||
InputManager.SetContext(InputManager.InputContext.Normal);
|
||||
|
||||
RestoreHeadBob();
|
||||
|
||||
Debug.Log("[DetectiveBoardController] Detective board deactivated");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies head bob settings based on CameraPanSettings configuration.
|
||||
/// </summary>
|
||||
private void ApplyHeadBobSettings(CameraPanSettings settings)
|
||||
{
|
||||
if (_cameraHeadBob == null || settings == null)
|
||||
@@ -165,9 +160,6 @@ namespace Unheimlich.Gameplay.DetectiveBoard
|
||||
_cameraHeadBob.SetMode(settings.HeadBobMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores head bob to normal behavior.
|
||||
/// </summary>
|
||||
private void RestoreHeadBob()
|
||||
{
|
||||
if (_cameraHeadBob == null)
|
||||
@@ -178,11 +170,11 @@ namespace Unheimlich.Gameplay.DetectiveBoard
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (_boardTransform == null)
|
||||
if (DetectiveBoardCanvas.Instance == null)
|
||||
return;
|
||||
|
||||
Gizmos.color = _isBoardActive ? Color.green : Color.yellow;
|
||||
Gizmos.DrawWireSphere(_boardTransform.position, _activationRange);
|
||||
Gizmos.DrawWireSphere(DetectiveBoardCanvas.Instance.transform.position, _activationRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user