Update
This commit is contained in:
54
Assets/Scripts/Player Controller/PlayerAnimationHandler.cs
Normal file
54
Assets/Scripts/Player Controller/PlayerAnimationHandler.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
using Fusion;
|
||||
|
||||
namespace OnlyScove.Scripts
|
||||
{
|
||||
public class PlayerAnimationHandler : NetworkBehaviour
|
||||
{
|
||||
[Header("Animator Settings")]
|
||||
[SerializeField] private string speedParamName = "Speed";
|
||||
[SerializeField] private string velocityXParamName = "Velocity X";
|
||||
[SerializeField] private string velocityZParamName = "Velocity Z";
|
||||
[SerializeField] private float animationDamping = 0.2f;
|
||||
|
||||
private Animator anim;
|
||||
private int speedHash;
|
||||
private int velocityXHash;
|
||||
private int velocityZHash;
|
||||
private bool hasSpeedParam;
|
||||
private bool hasVelocityXParam;
|
||||
private bool hasVelocityZParam;
|
||||
|
||||
public void Initialize(Animator animator)
|
||||
{
|
||||
this.anim = animator;
|
||||
if (anim != null)
|
||||
{
|
||||
foreach (AnimatorControllerParameter param in anim.parameters)
|
||||
{
|
||||
if (param.name == speedParamName) hasSpeedParam = true;
|
||||
if (param.name == velocityXParamName) hasVelocityXParam = true;
|
||||
if (param.name == velocityZParamName) hasVelocityZParam = true;
|
||||
}
|
||||
}
|
||||
|
||||
speedHash = Animator.StringToHash(speedParamName);
|
||||
velocityXHash = Animator.StringToHash(velocityXParamName);
|
||||
velocityZHash = Animator.StringToHash(velocityZParamName);
|
||||
}
|
||||
|
||||
public void UpdateAnimator(float speed, Vector2 moveInput, float deltaTime)
|
||||
{
|
||||
if (anim == null) return;
|
||||
|
||||
if (hasSpeedParam) anim.SetFloat(speedHash, speed, animationDamping, deltaTime);
|
||||
if (hasVelocityXParam) anim.SetFloat(velocityXHash, moveInput.x * speed, animationDamping, deltaTime);
|
||||
if (hasVelocityZParam) anim.SetFloat(velocityZHash, moveInput.y * speed, animationDamping, deltaTime);
|
||||
}
|
||||
|
||||
public void SetSpeed(float speed)
|
||||
{
|
||||
if (anim != null && hasSpeedParam) anim.SetFloat(speedHash, speed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 965ec86f3b9695640bdc85e624d0e9e7
|
||||
75
Assets/Scripts/Player Controller/PlayerInteraction.cs
Normal file
75
Assets/Scripts/Player Controller/PlayerInteraction.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
using Fusion;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace OnlyScove.Scripts
|
||||
{
|
||||
public class PlayerInteraction : NetworkBehaviour
|
||||
{
|
||||
[Header("Interaction Settings")]
|
||||
[SerializeField] public float InteractionRange = 2f;
|
||||
[SerializeField] public LayerMask InteractionMask;
|
||||
|
||||
public event Action<IInteractable> OnInteractableTargetChanged;
|
||||
|
||||
private List<IInteractable> interactablesNearby = new List<IInteractable>();
|
||||
private int currentInteractableIndex = 0;
|
||||
private EnvironmentScanner scanner;
|
||||
|
||||
public void Initialize(EnvironmentScanner scanner)
|
||||
{
|
||||
this.scanner = scanner;
|
||||
}
|
||||
|
||||
public void UpdateInteractables()
|
||||
{
|
||||
if (scanner == null) return;
|
||||
|
||||
interactablesNearby.Clear();
|
||||
IInteractable target = scanner.ScanForInteractable(InteractionRange, InteractionMask);
|
||||
|
||||
if (target != null) interactablesNearby.Add(target);
|
||||
OnInteractableTargetChanged?.Invoke(target);
|
||||
|
||||
if (Object != null && Object.HasInputAuthority)
|
||||
{
|
||||
// UI Placeholder: Interaction UI
|
||||
// Example: UI.UIEventBus.TriggerInteractionPrompt(target?.InteractionPrompt);
|
||||
// Example: UI.UIEventBus.TriggerInteractionVisibility(target != null);
|
||||
}
|
||||
|
||||
currentInteractableIndex = 0;
|
||||
}
|
||||
|
||||
public void NextInteract()
|
||||
{
|
||||
if (interactablesNearby.Count <= 1) return;
|
||||
currentInteractableIndex = (currentInteractableIndex + 1) % interactablesNearby.Count;
|
||||
NotifyTargetChanged();
|
||||
}
|
||||
|
||||
public void PreviousInteract()
|
||||
{
|
||||
if (interactablesNearby.Count <= 1) return;
|
||||
currentInteractableIndex = (currentInteractableIndex - 1 + interactablesNearby.Count) % interactablesNearby.Count;
|
||||
NotifyTargetChanged();
|
||||
}
|
||||
|
||||
private void NotifyTargetChanged()
|
||||
{
|
||||
IInteractable target = GetInteractable();
|
||||
OnInteractableTargetChanged?.Invoke(target);
|
||||
if (Object != null && Object.HasInputAuthority)
|
||||
{
|
||||
// UI Placeholder: Update Prompt
|
||||
// Example: UI.UIEventBus.TriggerInteractionPrompt(target?.InteractionPrompt);
|
||||
}
|
||||
}
|
||||
|
||||
public IInteractable GetInteractable()
|
||||
{
|
||||
return (interactablesNearby == null || interactablesNearby.Count == 0) ? null : interactablesNearby[currentInteractableIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9dcff2851697b4f4c8c25ef8381665ba
|
||||
71
Assets/Scripts/Player Controller/PlayerMovement.cs
Normal file
71
Assets/Scripts/Player Controller/PlayerMovement.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using UnityEngine;
|
||||
using Fusion;
|
||||
|
||||
namespace OnlyScove.Scripts
|
||||
{
|
||||
public class PlayerMovement : NetworkBehaviour
|
||||
{
|
||||
[field: Header("Movement Settings")]
|
||||
[field: SerializeField] public float WalkSpeed { get; private set; } = 3f;
|
||||
[field: SerializeField] public float RunSpeed { get; private set; } = 6f;
|
||||
[field: SerializeField] public float SprintSpeed { get; private set; } = 9f;
|
||||
[field: SerializeField] public float SneakSpeed { get; private set; } = 1.5f;
|
||||
[field: SerializeField] public float DashForce { get; private set; } = 10f;
|
||||
[field: SerializeField] public float RotationSpeed { get; private set; } = 500f;
|
||||
|
||||
[field: Header("Airborne Settings")]
|
||||
[field: SerializeField] public float JumpHeight { get; private set; } = 2f;
|
||||
[field: SerializeField] public float Gravity { get; private set; } = -15f;
|
||||
[field: SerializeField] public float ThrustDownwardForce { get; private set; } = -20f;
|
||||
|
||||
[field: Header("Ground Check")]
|
||||
[field: SerializeField] public float GroundCheckRadius { get; private set; } = 0.2f;
|
||||
[field: SerializeField] public Vector3 GroundCheckOffset { get; private set; }
|
||||
[field: SerializeField] public LayerMask GroundMask { get; private set; }
|
||||
|
||||
[Networked] public bool IsGrounded { get; set; }
|
||||
[Networked] public bool WasGrounded { get; set; }
|
||||
[Networked] public float VelocityY { get; set; }
|
||||
[Networked] public Vector3 NetworkedPosition { get; set; }
|
||||
|
||||
private CharacterController controller;
|
||||
|
||||
public void Initialize(CharacterController controller)
|
||||
{
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public void CheckGround(Transform playerTransform)
|
||||
{
|
||||
if (Object == null || (!Object.HasStateAuthority && !Object.HasInputAuthority)) return;
|
||||
|
||||
WasGrounded = IsGrounded;
|
||||
IsGrounded = Physics.CheckSphere(playerTransform.TransformPoint(GroundCheckOffset), GroundCheckRadius, GroundMask);
|
||||
}
|
||||
|
||||
public void Move(CharacterController controller, Vector3 velocity, float deltaTime)
|
||||
{
|
||||
if (controller != null && controller.enabled)
|
||||
{
|
||||
controller.Move(velocity * deltaTime);
|
||||
if (Object != null && Object.HasStateAuthority)
|
||||
{
|
||||
NetworkedPosition = transform.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Rotate(Transform playerTransform, Vector3 moveDirection, float deltaTime)
|
||||
{
|
||||
if (moveDirection == Vector3.zero) return;
|
||||
Quaternion targetRot = Quaternion.LookRotation(moveDirection);
|
||||
playerTransform.rotation = Quaternion.RotateTowards(playerTransform.rotation, targetRot, RotationSpeed * deltaTime);
|
||||
}
|
||||
|
||||
public void SetGroundCheck(float radius, Vector3 offset)
|
||||
{
|
||||
GroundCheckRadius = radius;
|
||||
GroundCheckOffset = offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Player Controller/PlayerMovement.cs.meta
Normal file
2
Assets/Scripts/Player Controller/PlayerMovement.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79bbcfd4d37b7834ebe0d61bb649714d
|
||||
@@ -5,6 +5,8 @@ using Fusion;
|
||||
namespace OnlyScove.Scripts
|
||||
{
|
||||
[RequireComponent(typeof(CharacterController), typeof(InputReader), typeof(Animator))]
|
||||
[RequireComponent(typeof(PlayerStats), typeof(PlayerInteraction), typeof(PlayerMovement))]
|
||||
[RequireComponent(typeof(PlayerAnimationHandler))]
|
||||
public class PlayerStateMachine : NetworkBehaviour
|
||||
{
|
||||
[field: Header("References")]
|
||||
@@ -14,61 +16,38 @@ namespace OnlyScove.Scripts
|
||||
[field: SerializeField] public EnvironmentScanner Scanner { get; private set; }
|
||||
public CameraController Cam { get; private set; }
|
||||
|
||||
[field: Header("Animator Settings")]
|
||||
[SerializeField] private string speedParamName = "Speed";
|
||||
[SerializeField] private string velocityXParamName = "Velocity X";
|
||||
[SerializeField] private string velocityZParamName = "Velocity Z";
|
||||
|
||||
private int speedHash;
|
||||
private int velocityXHash;
|
||||
private int velocityZHash;
|
||||
|
||||
[field: Header("Movement Settings")]
|
||||
[field: SerializeField] public float WalkSpeed { get; private set; } = 3f;
|
||||
[field: SerializeField] public float RunSpeed { get; private set; } = 6f;
|
||||
[field: SerializeField] public float SprintSpeed { get; private set; } = 9f;
|
||||
[field: SerializeField] public float SneakSpeed { get; private set; } = 1.5f;
|
||||
[field: SerializeField] public float DashForce { get; private set; } = 10f;
|
||||
[field: SerializeField] public float RotationSpeed { get; private set; } = 500f;
|
||||
[field: SerializeField] public float AnimationDamping { get; private set; } = 0.2f;
|
||||
|
||||
[field: Header("Airborne Settings")]
|
||||
[field: SerializeField] public float JumpHeight { get; private set; } = 2f;
|
||||
[field: SerializeField] public float Gravity { get; private set; } = -15f;
|
||||
[field: SerializeField] public float ThrustDownwardForce { get; private set; } = -20f;
|
||||
|
||||
[field: Header("Ground Check")]
|
||||
[field: SerializeField] public float GroundCheckRadius { get; private set; } = 0.2f;
|
||||
[field: SerializeField] public Vector3 GroundCheckOffset { get; private set; }
|
||||
[field: SerializeField] public LayerMask GroundMask { get; private set; }
|
||||
|
||||
[field: Header("Interaction")]
|
||||
[field: SerializeField] public float InteractionRange { get; private set; } = 2f;
|
||||
[field: SerializeField] public LayerMask InteractionMask { get; private set; }
|
||||
[Header("Modules")]
|
||||
public PlayerStats Stats;
|
||||
public PlayerInteraction Interaction;
|
||||
public PlayerMovement Movement;
|
||||
public PlayerAnimationHandler AnimationHandler;
|
||||
|
||||
[Networked] public Quaternion NetworkedCameraRotation { get; set; }
|
||||
[Networked] public Vector2 NetworkedMoveInput { get; set; }
|
||||
[Networked] public float NetworkedSpeed { get; set; }
|
||||
[Networked] public Vector3 NetworkedPosition { get; set; }
|
||||
|
||||
[Header("Player Stats")]
|
||||
[Networked, OnChangedRender(nameof(OnHealthChangedRender))] public float Health { get; set; } = 100f;
|
||||
[Networked, OnChangedRender(nameof(OnStaminaChangedRender))] public float Stamina { get; set; } = 100f;
|
||||
[Networked, OnChangedRender(nameof(OnNoiseLevelChangedRender))] public float NoiseLevel { get; set; } = 0f;
|
||||
|
||||
public event System.Action<float> OnHealthChanged;
|
||||
public event System.Action<float> OnStaminaChanged;
|
||||
public event System.Action<float> OnNoiseLevelChanged;
|
||||
public event System.Action<IInteractable> OnInteractableTargetChanged;
|
||||
|
||||
// Pass-through properties for State Compatibility
|
||||
public Vector2 MoveInput { get; private set; }
|
||||
public bool IsSprintHeld { get; private set; }
|
||||
public float VelocityY { get; set; }
|
||||
public bool IsGrounded { get; private set; }
|
||||
public bool WasGrounded { get; private set; }
|
||||
public string CurrentStateName => currentState != null ? currentState.GetType().Name : "None";
|
||||
public static PlayerStateMachine Local { get; private set; }
|
||||
public float VelocityY { get => Movement.VelocityY; set => Movement.VelocityY = value; }
|
||||
public bool IsGrounded => Movement.IsGrounded;
|
||||
public bool WasGrounded => Movement.WasGrounded;
|
||||
|
||||
public float WalkSpeed => Movement.WalkSpeed;
|
||||
public float RunSpeed => Movement.RunSpeed;
|
||||
public float SprintSpeed => Movement.SprintSpeed;
|
||||
public float SneakSpeed => Movement.SneakSpeed;
|
||||
public float DashForce => Movement.DashForce;
|
||||
public float JumpHeight => Movement.JumpHeight;
|
||||
public float ThrustDownwardForce => Movement.ThrustDownwardForce;
|
||||
public float Gravity => Movement.Gravity;
|
||||
|
||||
public float InteractionRange => Interaction.InteractionRange;
|
||||
public LayerMask InteractionMask => Interaction.InteractionMask;
|
||||
|
||||
public static PlayerStateMachine Local { get; private set; }
|
||||
public string CurrentStateName => currentState != null ? currentState.GetType().Name : "None";
|
||||
|
||||
public Quaternion CameraRotation
|
||||
{
|
||||
get
|
||||
@@ -80,11 +59,6 @@ namespace OnlyScove.Scripts
|
||||
|
||||
private PlayerBaseState currentState;
|
||||
private bool hasControl = true;
|
||||
private bool hasSpeedParam;
|
||||
private bool hasVelocityXParam;
|
||||
private bool hasVelocityZParam;
|
||||
private List<IInteractable> interactablesNearby = new List<IInteractable>();
|
||||
private int currentInteractableIndex = 0;
|
||||
private float localAnimatorSpeed;
|
||||
|
||||
protected virtual void Awake()
|
||||
@@ -93,20 +67,15 @@ namespace OnlyScove.Scripts
|
||||
Input = GetComponent<InputReader>();
|
||||
Anim = GetComponentInChildren<Animator>();
|
||||
Scanner = GetComponent<EnvironmentScanner>();
|
||||
|
||||
Stats = GetComponent<PlayerStats>();
|
||||
Interaction = GetComponent<PlayerInteraction>();
|
||||
Movement = GetComponent<PlayerMovement>();
|
||||
AnimationHandler = GetComponent<PlayerAnimationHandler>();
|
||||
|
||||
if (Anim != null)
|
||||
{
|
||||
foreach (AnimatorControllerParameter param in Anim.parameters)
|
||||
{
|
||||
if (param.name == speedParamName) hasSpeedParam = true;
|
||||
if (param.name == velocityXParamName) hasVelocityXParam = true;
|
||||
if (param.name == velocityZParamName) hasVelocityZParam = true;
|
||||
}
|
||||
}
|
||||
|
||||
speedHash = Animator.StringToHash(speedParamName);
|
||||
velocityXHash = Animator.StringToHash(velocityXParamName);
|
||||
velocityZHash = Animator.StringToHash(velocityZParamName);
|
||||
AnimationHandler.Initialize(Anim);
|
||||
Movement.Initialize(Controller);
|
||||
Interaction.Initialize(Scanner);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@@ -123,10 +92,6 @@ namespace OnlyScove.Scripts
|
||||
}
|
||||
}
|
||||
|
||||
void OnHealthChangedRender() => OnHealthChanged?.Invoke(Health);
|
||||
void OnStaminaChangedRender() => OnStaminaChanged?.Invoke(Stamina);
|
||||
void OnNoiseLevelChangedRender() => OnNoiseLevelChanged?.Invoke(NoiseLevel);
|
||||
|
||||
private void InitializePlayer()
|
||||
{
|
||||
if (currentState == null) SwitchState(new PlayerIdleState(this));
|
||||
@@ -142,17 +107,15 @@ namespace OnlyScove.Scripts
|
||||
Cam.followTarget = transform;
|
||||
Cam.inputReader = Input;
|
||||
}
|
||||
Input.OnNextInteractEvent += OnNextInteract;
|
||||
Input.OnPreviousInteractEvent += OnPreviousInteract;
|
||||
Input.OnNextInteractEvent += Interaction.NextInteract;
|
||||
Input.OnPreviousInteractEvent += Interaction.PreviousInteract;
|
||||
if (Controller != null) Controller.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Rotate(Vector3 moveDirection, float deltaTime)
|
||||
{
|
||||
if (moveDirection == Vector3.zero) return;
|
||||
Quaternion targetRot = Quaternion.LookRotation(moveDirection);
|
||||
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRot, RotationSpeed * deltaTime);
|
||||
Movement.Rotate(transform, moveDirection, deltaTime);
|
||||
}
|
||||
|
||||
public void Move(Vector3 velocity, float animatorSpeed, float deltaTime)
|
||||
@@ -160,12 +123,8 @@ namespace OnlyScove.Scripts
|
||||
bool canMove = (Runner == null || !Runner.IsRunning) || Object.HasInputAuthority || Runner.IsServer;
|
||||
if (!canMove) return;
|
||||
|
||||
if (Controller != null && Controller.enabled)
|
||||
{
|
||||
Controller.Move(velocity * deltaTime);
|
||||
if (Object != null && Runner != null && Runner.IsRunning) NetworkedPosition = transform.position;
|
||||
}
|
||||
|
||||
Movement.Move(Controller, velocity, deltaTime);
|
||||
|
||||
localAnimatorSpeed = animatorSpeed;
|
||||
if (Object != null && Object.HasStateAuthority)
|
||||
{
|
||||
@@ -177,13 +136,9 @@ namespace OnlyScove.Scripts
|
||||
|
||||
private void UpdateAnimator(float deltaTime)
|
||||
{
|
||||
if (Anim == null) return;
|
||||
float speedValue = (Runner == null || !Runner.IsRunning || Object.HasInputAuthority) ? localAnimatorSpeed : NetworkedSpeed;
|
||||
Vector2 inputVector = (Runner == null || !Runner.IsRunning || Object.HasInputAuthority) ? MoveInput : NetworkedMoveInput;
|
||||
|
||||
if (hasSpeedParam) Anim.SetFloat(speedHash, speedValue, AnimationDamping, deltaTime);
|
||||
if (hasVelocityXParam) Anim.SetFloat(velocityXHash, inputVector.x * speedValue, AnimationDamping, deltaTime);
|
||||
if (hasVelocityZParam) Anim.SetFloat(velocityZHash, inputVector.y * speedValue, AnimationDamping, deltaTime);
|
||||
AnimationHandler.UpdateAnimator(speedValue, inputVector, deltaTime);
|
||||
}
|
||||
|
||||
public override void FixedUpdateNetwork()
|
||||
@@ -191,10 +146,11 @@ namespace OnlyScove.Scripts
|
||||
bool isRunning = Runner != null && Runner.IsRunning;
|
||||
if (Object == null && isRunning) return;
|
||||
|
||||
if (isRunning && NetworkedPosition != Vector3.zero && !Object.HasInputAuthority)
|
||||
// Proxy Sync
|
||||
if (isRunning && Movement.NetworkedPosition != Vector3.zero && !Object.HasInputAuthority)
|
||||
{
|
||||
Controller.enabled = false;
|
||||
transform.position = NetworkedPosition;
|
||||
transform.position = Movement.NetworkedPosition;
|
||||
Controller.enabled = true;
|
||||
}
|
||||
|
||||
@@ -209,19 +165,13 @@ namespace OnlyScove.Scripts
|
||||
MoveInput = new Vector2(UnityEngine.Input.GetAxisRaw("Horizontal"), UnityEngine.Input.GetAxisRaw("Vertical"));
|
||||
IsSprintHeld = UnityEngine.Input.GetKey(KeyCode.LeftShift);
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveInput = Vector2.zero;
|
||||
IsSprintHeld = false;
|
||||
}
|
||||
|
||||
if (!isRunning || Object.HasInputAuthority || Runner.IsServer)
|
||||
{
|
||||
if (hasControl)
|
||||
{
|
||||
WasGrounded = IsGrounded;
|
||||
CheckGround();
|
||||
UpdateInteractablesList();
|
||||
Movement.CheckGround(transform);
|
||||
Interaction.UpdateInteractables();
|
||||
currentState?.Tick(isRunning ? Runner.DeltaTime : Time.fixedDeltaTime);
|
||||
}
|
||||
}
|
||||
@@ -236,34 +186,8 @@ namespace OnlyScove.Scripts
|
||||
if (Runner == null || !Runner.IsRunning) FixedUpdateNetwork();
|
||||
}
|
||||
|
||||
private void CheckGround() => IsGrounded = Physics.CheckSphere(transform.TransformPoint(GroundCheckOffset), GroundCheckRadius, GroundMask);
|
||||
|
||||
private void UpdateInteractablesList()
|
||||
{
|
||||
interactablesNearby.Clear();
|
||||
IInteractable target = Scanner.ScanForInteractable(InteractionRange, InteractionMask);
|
||||
if (target != null) interactablesNearby.Add(target);
|
||||
OnInteractableTargetChanged?.Invoke(target);
|
||||
currentInteractableIndex = 0;
|
||||
}
|
||||
|
||||
private void OnNextInteract()
|
||||
{
|
||||
if (interactablesNearby.Count <= 1) return;
|
||||
currentInteractableIndex = (currentInteractableIndex + 1) % interactablesNearby.Count;
|
||||
OnInteractableTargetChanged?.Invoke(GetInteractable());
|
||||
}
|
||||
|
||||
private void OnPreviousInteract()
|
||||
{
|
||||
if (interactablesNearby.Count <= 1) return;
|
||||
currentInteractableIndex = (currentInteractableIndex - 1 + interactablesNearby.Count) % interactablesNearby.Count;
|
||||
OnInteractableTargetChanged?.Invoke(GetInteractable());
|
||||
}
|
||||
|
||||
public IInteractable GetInteractable() => interactablesNearby.Count == 0 ? null : interactablesNearby[currentInteractableIndex];
|
||||
|
||||
public void SetGroundCheck(float radius, Vector3 offset) { GroundCheckRadius = radius; GroundCheckOffset = offset; }
|
||||
public IInteractable GetInteractable() => Interaction.GetInteractable();
|
||||
public void SetGroundCheck(float radius, Vector3 offset) => Movement.SetGroundCheck(radius, offset);
|
||||
|
||||
public void SwitchState(PlayerBaseState newState)
|
||||
{
|
||||
@@ -276,13 +200,14 @@ namespace OnlyScove.Scripts
|
||||
{
|
||||
hasControl = control;
|
||||
if (Controller != null) Controller.enabled = control;
|
||||
if (!control && Anim != null) Anim.SetFloat(speedHash, 0f);
|
||||
if (!control) AnimationHandler.SetSpeed(0f);
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (Movement == null) return;
|
||||
Gizmos.color = new Color(0, 1, 0, 0.5f);
|
||||
Gizmos.DrawSphere(transform.TransformPoint(GroundCheckOffset), GroundCheckRadius);
|
||||
Gizmos.DrawSphere(transform.TransformPoint(Movement.GroundCheckOffset), Movement.GroundCheckRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
58
Assets/Scripts/Player Controller/PlayerStats.cs
Normal file
58
Assets/Scripts/Player Controller/PlayerStats.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using UnityEngine;
|
||||
using Fusion;
|
||||
using System;
|
||||
|
||||
namespace OnlyScove.Scripts
|
||||
{
|
||||
public class PlayerStats : NetworkBehaviour
|
||||
{
|
||||
[Header("Player Stats")]
|
||||
[Networked, OnChangedRender(nameof(OnHealthChangedRender))] public float Health { get; set; } = 100f;
|
||||
[Networked, OnChangedRender(nameof(OnStaminaChangedRender))] public float Stamina { get; set; } = 100f;
|
||||
[Networked, OnChangedRender(nameof(OnNoiseLevelChangedRender))] public float NoiseLevel { get; set; } = 0f;
|
||||
|
||||
public event Action<float> OnHealthChanged;
|
||||
public event Action<float> OnStaminaChanged;
|
||||
public event Action<float> OnNoiseLevelChanged;
|
||||
|
||||
public override void Spawned()
|
||||
{
|
||||
// Initial UI sync placeholder
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
void OnHealthChangedRender()
|
||||
{
|
||||
OnHealthChanged?.Invoke(Health);
|
||||
if (Object.HasInputAuthority)
|
||||
{
|
||||
// UI Placeholder: Trigger Health UI Change
|
||||
// Example: UI.UIEventBus.TriggerHealthChange(Health / 100f);
|
||||
}
|
||||
}
|
||||
|
||||
void OnStaminaChangedRender()
|
||||
{
|
||||
OnStaminaChanged?.Invoke(Stamina);
|
||||
if (Object.HasInputAuthority)
|
||||
{
|
||||
// UI Placeholder: Trigger Stamina UI Change
|
||||
// Example: UI.UIEventBus.TriggerStaminaChange(Stamina / 100f);
|
||||
}
|
||||
}
|
||||
|
||||
void OnNoiseLevelChangedRender()
|
||||
{
|
||||
OnNoiseLevelChanged?.Invoke(NoiseLevel);
|
||||
}
|
||||
|
||||
private void UpdateUI()
|
||||
{
|
||||
if (Object.HasInputAuthority)
|
||||
{
|
||||
OnHealthChangedRender();
|
||||
OnStaminaChangedRender();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Player Controller/PlayerStats.cs.meta
Normal file
2
Assets/Scripts/Player Controller/PlayerStats.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1494b79b59fcdf4d9f7956dde31bc42
|
||||
Reference in New Issue
Block a user