using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using System.Collections.Generic; namespace Northbound { public class PlayerActionSystem : InputActionManager { [Header("Actions")] public List actionComponents = new List(); [Header("Animation")] public bool playAnimations = true; private Dictionary _actions = new Dictionary(); private Animator _animator; private void Awake() { _animator = GetComponent(); } public override void OnNetworkSpawn() { base.OnNetworkSpawn(); if (!IsOwner) return; foreach (var component in actionComponents) { if (component is IAction action) { _actions[action.GetActionName()] = action; } } } protected override void BindInputActions() { _inputActions.Player.Attack.performed += OnAttack; } protected override void UnbindInputActions() { _inputActions.Player.Attack.performed -= OnAttack; } private void OnAttack(InputAction.CallbackContext context) { ExecuteAction("Attack"); } public void ExecuteAction(string actionName) { if (_actions.TryGetValue(actionName, out IAction action)) { if (action.CanExecute(OwnerClientId)) { if (playAnimations && _animator != null) { string animTrigger = action.GetActionAnimation(); if (!string.IsNullOrEmpty(animTrigger)) { _animator.SetTrigger(animTrigger); } } action.Execute(OwnerClientId); } } } } }