Integration of the octo input system and centralization of player values
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
using UnityEngine;
|
||||
using OctoCore.Components;
|
||||
using Unheimlich.Core;
|
||||
using Unheimlich.Data;
|
||||
using Unheimlich.Managers;
|
||||
using Unheimlich.Gameplay.CameraControl;
|
||||
|
||||
namespace Unheimlich.Gameplay.Player
|
||||
{
|
||||
/// <summary>
|
||||
/// Central hub for all player systems.
|
||||
/// Exposes components and settings with zero Inspector refs needed for other scripts.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(OctoPlayer))]
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class PlayerController : Singleton<PlayerController>
|
||||
{
|
||||
// Auto-found components (exposed publicly, found once in Awake)
|
||||
public OctoPlayer Movement { get; private set; }
|
||||
public CharacterController CharController { get; private set; }
|
||||
public Camera PlayerCamera { get; private set; }
|
||||
public Transform CameraTransform { get; private set; }
|
||||
public Transform CameraPivot { get; private set; }
|
||||
public CameraEffects CameraEffects { get; private set; }
|
||||
public CameraPanController CameraPanController { get; private set; }
|
||||
public InputManager Inputs => InputManager.Instance;
|
||||
|
||||
public bool IsMoving
|
||||
{
|
||||
get
|
||||
{
|
||||
// Read directly from action instead of cached value
|
||||
var moveAction = InputManager.GetMoveAction();
|
||||
if (moveAction == null) return false;
|
||||
return moveAction.ReadValue<UnityEngine.Vector2>().magnitude > 0.1f;
|
||||
}
|
||||
}
|
||||
public bool IsRunning
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Movement == null || OctoCore.OctoCore.Instance == null) return false;
|
||||
|
||||
var actions = OctoCore.OctoCore.Instance.Inputs?.Actions;
|
||||
if (actions != null)
|
||||
{
|
||||
foreach (var actionInfo in actions)
|
||||
{
|
||||
if (actionInfo.Name == "Sprint" && actionInfo.Reference != null)
|
||||
return actionInfo.Reference.action.IsPressed();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
// Auto-find all components once
|
||||
Movement = GetComponent<OctoPlayer>();
|
||||
CharController = GetComponent<CharacterController>();
|
||||
CameraEffects = GetComponent<CameraEffects>();
|
||||
CameraPanController = GetComponent<CameraPanController>();
|
||||
PlayerCamera = GetComponentInChildren<Camera>();
|
||||
|
||||
if (PlayerCamera != null)
|
||||
{
|
||||
CameraTransform = PlayerCamera.transform;
|
||||
CameraPivot = CameraTransform.parent;
|
||||
}
|
||||
}
|
||||
|
||||
// Teleport
|
||||
public void Teleport(Vector3 position, Quaternion rotation)
|
||||
{
|
||||
Movement.Teleport(position, rotation);
|
||||
PlayerEvents.TriggerTeleport(position, rotation);
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
public Vector3 GetForward()
|
||||
{
|
||||
if (PlayerCamera == null) return transform.forward;
|
||||
|
||||
Vector3 forward = PlayerCamera.transform.forward;
|
||||
forward.y = 0;
|
||||
return forward.normalized;
|
||||
}
|
||||
|
||||
public Vector3 GetRight()
|
||||
{
|
||||
if (PlayerCamera == null) return transform.right;
|
||||
|
||||
Vector3 right = PlayerCamera.transform.right;
|
||||
right.y = 0;
|
||||
return right.normalized;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user