using System; using System.Linq; using UnityEditor; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.UIElements; using NodeCanvas; using NodeCanvas.Framework; using ParadoxNotion; using Reset; using Reset.Units; using Sirenix.OdinInspector; using Unity.Cinemachine; using Object = UnityEngine.Object; public class PlayerControls : MonoBehaviour{ // References private Player thisPlayer; private PlayerInput input; private SignalDefinition inputSignal; private SignalDefinition blockSignal; // TODO: Turn these into accessors public Vector2 rawMoveInput; public Vector2 rawLookInput; public GraphOwner graph; void Awake(){ try { inputSignal = Resources.Load("InputSignal"); } catch (Exception e) { Debug.LogError($"Error finding the Input Signal defintion: {e.Message}"); throw; } try { blockSignal = Resources.Load("BlockInputSignal"); } catch (Exception e) { Debug.LogError($"Error finding the Input Signal defintion: {e.Message}"); throw; } thisPlayer = GetComponent(); graph = GetComponent(); input = GetComponent(); // Remove all devices from this user input.user.UnpairDevices(); // Add the delegates for each method foreach (InputAction action in input.actions) { action.started += SendInputSignal; action.canceled += SendInputSignal; action.performed += SendInputSignal; } } // Remove the delegates for each method void OnDisable(){ foreach (InputAction action in input.actions) { action.started -= SendInputSignal; action.canceled -= SendInputSignal; action.performed -= SendInputSignal; } } // This will call the SignalInvoke for this type of Signal Defintion. CheckInput is the recieving end. public void SendInputSignal(InputAction.CallbackContext ctx){ inputSignal.Invoke(transform, transform, false, new object[]{ ctx.action, ctx.phase }); } public void SendInputBlock(string actionName){ Debug.Log($"Sending block request..."); blockSignal.Invoke(transform, transform, false, new object[]{actionName}); } public void OnMove(InputValue value){ rawMoveInput.x = value.Get().x; rawMoveInput.y = value.Get().y; } public void OnLook(InputValue value){ rawLookInput.x = value.Get().x; rawLookInput.y = value.Get().y; // GameManager.Camera.transform.Find("Cinemachine").GetComponent().Controllers[0].InputValue = rawLookInput.x * 200; // GameManager.Camera.transform.Find("Cinemachine").GetComponent().Controllers[1].InputValue = rawLookInput.y * 100; } public void OnSprint(){ graph.SendEvent("InputEvent", "Sprint", null); } public void OnJump(){ graph.SendEvent("InputEvent", "Jump", null); } public void OnLockOn(){ GetComponent().ChangeLockOnTarget(); graph.SendEvent("InputEvent", "LockOn", null); } public void OnCancelLockOn(){ GetComponent().RemoveMainTarget(); graph.SendEvent("InputEvent", "CancelLockOn", null); } // public void OnGrapple(InputInteractionContext context){ // if (context.control.IsPressed()) { // graph.SendEvent("InputEvent", "GrappleDown", null); // } else { // graph.SendEvent("InputEvent", "GrappleUp", null); // } // } }