122 lines
3.8 KiB
C#
122 lines
3.8 KiB
C#
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<SignalDefinition>("InputSignal");
|
|
} catch (Exception e) {
|
|
Debug.LogError($"Error finding the Input Signal defintion: {e.Message}");
|
|
throw;
|
|
}
|
|
|
|
try {
|
|
blockSignal = Resources.Load<SignalDefinition>("BlockInputSignal");
|
|
} catch (Exception e) {
|
|
Debug.LogError($"Error finding the Input Signal defintion: {e.Message}");
|
|
throw;
|
|
}
|
|
|
|
thisPlayer = GetComponent<Player>();
|
|
graph = GetComponent<GraphOwner>();
|
|
input = GetComponent<PlayerInput>();
|
|
|
|
// 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<Vector2>().x;
|
|
rawMoveInput.y = value.Get<Vector2>().y;
|
|
}
|
|
|
|
public void OnLook(InputValue value){
|
|
rawLookInput.x = value.Get<Vector2>().x;
|
|
rawLookInput.y = value.Get<Vector2>().y;
|
|
|
|
// GameManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().Controllers[0].InputValue = rawLookInput.x * 200;
|
|
// GameManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().Controllers[1].InputValue = rawLookInput.y * 100;
|
|
}
|
|
|
|
public void OnSprint(){
|
|
graph.SendEvent<string>("InputEvent", "Sprint", null);
|
|
}
|
|
|
|
public void OnJump(){
|
|
graph.SendEvent<string>("InputEvent", "Jump", null);
|
|
}
|
|
|
|
public void OnLockOn(){
|
|
GetComponent<LockOnManager>().ChangeLockOnTarget();
|
|
graph.SendEvent<string>("InputEvent", "LockOn", null);
|
|
}
|
|
|
|
public void OnCancelLockOn(){
|
|
GetComponent<LockOnManager>().RemoveMainTarget();
|
|
graph.SendEvent<string>("InputEvent", "CancelLockOn", null);
|
|
}
|
|
|
|
// public void OnGrapple(InputInteractionContext context){
|
|
// if (context.control.IsPressed()) {
|
|
// graph.SendEvent<string>("InputEvent", "GrappleDown", null);
|
|
// } else {
|
|
// graph.SendEvent<string>("InputEvent", "GrappleUp", null);
|
|
// }
|
|
// }
|
|
}
|