100 lines
3.5 KiB
C#
100 lines
3.5 KiB
C#
/*
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
[RequireComponent(typeof(Animator))]
|
|
public class PlayerAnimationProController : MonoBehaviour
|
|
{
|
|
private static readonly int InputHorizontal = Animator.StringToHash("InputHorizontal");
|
|
private static readonly int InputVertical = Animator.StringToHash("InputVertical");
|
|
private static readonly int InputMagnitude = Animator.StringToHash("InputMagnitude");
|
|
private static readonly int InputAngle = Animator.StringToHash("InputAngle");
|
|
private static readonly int WalkStartAngle = Animator.StringToHash("WalkStartAngle");
|
|
private static readonly int RunStartAngle = Animator.StringToHash("RunStartAngle");
|
|
|
|
public float _InputHorizontal;
|
|
public float _InputVertical;
|
|
public float _InputMagnitude;
|
|
[Space]
|
|
public float _InputAngle;
|
|
public float angle;
|
|
public float _InputAngleClamp = 90f;
|
|
public float _InputAngleSpeed = 1f;
|
|
[Space]
|
|
public float _WalkStartAngle;
|
|
public float _RunStartAngle;
|
|
|
|
private Vector3 input;
|
|
private GameControls inputActions;
|
|
private Animator animator;
|
|
|
|
private void Awake()
|
|
{
|
|
animator = GetComponent<Animator>();
|
|
inputActions = new GameControls();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
inputActions.Enable();
|
|
|
|
inputActions.Player.Move.performed += Move_performed;
|
|
inputActions.Player.Move.canceled += Move_canceled;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
inputActions.Player.Move.performed -= Move_performed;
|
|
inputActions.Player.Move.canceled -= Move_canceled;
|
|
|
|
inputActions.Disable();
|
|
}
|
|
|
|
private void Move_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
|
|
{
|
|
input = new Vector3(obj.ReadValue<Vector2>().x, 0f, obj.ReadValue<Vector2>().y);
|
|
|
|
_InputHorizontal = input.x;
|
|
_InputVertical = input.z;
|
|
_InputMagnitude = input.magnitude;
|
|
}
|
|
|
|
private void Move_canceled(UnityEngine.InputSystem.InputAction.CallbackContext obj)
|
|
{
|
|
_InputHorizontal = 0f;
|
|
_InputVertical = 0f;
|
|
_InputMagnitude = 0f;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
_WalkStartAngle = Vector3.Angle(transform.forward, input) * Mathf.Sign(input.x);
|
|
_RunStartAngle = Vector3.Angle(transform.forward, input) * Mathf.Sign(input.x);
|
|
|
|
angle = Mathf.Lerp(0f, _InputAngleClamp, Mathf.Abs(_InputHorizontal)) * Mathf.Sign(_InputHorizontal);
|
|
if (_InputVertical < 0)
|
|
{
|
|
angle = _InputAngleClamp * Mathf.Sign(_InputHorizontal);
|
|
}
|
|
_InputAngle = Mathf.LerpAngle(_InputAngle, angle, Time.deltaTime * _InputAngleSpeed);
|
|
|
|
animator.SetFloat(InputHorizontal, _InputHorizontal);
|
|
animator.SetFloat(InputVertical, _InputVertical);
|
|
animator.SetFloat(InputMagnitude, _InputMagnitude);
|
|
animator.SetFloat(InputAngle, _InputAngle);
|
|
animator.SetFloat(WalkStartAngle, _WalkStartAngle);
|
|
animator.SetFloat(RunStartAngle, _RunStartAngle);
|
|
}
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
Gizmos.DrawRay(transform.position, transform.forward);
|
|
Gizmos.DrawRay(transform.position, input);
|
|
}
|
|
}
|
|
}
|
|
*/ |