2023-03-14 00:59:59 +01:00
|
|
|
using UnityEngine;
|
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
namespace Player
|
2023-03-14 00:59:59 +01:00
|
|
|
{
|
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
public class PlayerAnimationController : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField] private Animator animController;
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
[SerializeField] private string runningParameter;
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
[SerializeField] private string runningSpeedParameter;
|
2023-03-14 00:59:59 +01:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
[SerializeField] private string sideStepSpeedParameter;
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
//private bool movementInterrupt = false;
|
|
|
|
[SerializeField] private PlayerInteractionHandler interactionHandler;
|
2023-05-12 02:14:49 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
[SerializeField] private PlayerMovementController movement;
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
//private float verticalAiming = 0;
|
2023-06-14 13:21:44 +02:00
|
|
|
public Camera hiddenCam;
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
private bool isRunning;
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
private float runningSpeed;
|
|
|
|
private float sideStepSpeed;
|
2023-03-14 00:59:59 +01:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
// Start is called before the first frame update
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
// Update is called once per frame
|
|
|
|
private void Update()
|
2023-06-01 17:03:48 +02:00
|
|
|
{
|
2023-06-01 20:25:46 +02:00
|
|
|
animController.SetBool("IsCarrying", interactionHandler.IsCarrying);
|
|
|
|
animController.SetBool("HasGun", interactionHandler.GunEnabled);
|
|
|
|
|
|
|
|
if (interactionHandler.GunEnabled && !interactionHandler.isDead && movement.AllowRotation)
|
2023-06-01 17:03:48 +02:00
|
|
|
{
|
2023-06-01 20:25:46 +02:00
|
|
|
if (hiddenCam.transform.localEulerAngles.x < 90)
|
|
|
|
{
|
|
|
|
//DOWN
|
|
|
|
var target = Mathf.Lerp(animController.GetLayerWeight(3), hiddenCam.transform.localEulerAngles.x / 70f,
|
|
|
|
Time.deltaTime * 10f);
|
|
|
|
animController.SetLayerWeight(3, target);
|
|
|
|
animController.SetLayerWeight(2, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//UP
|
|
|
|
animController.SetLayerWeight(3, 0);
|
|
|
|
var target = Mathf.Lerp(animController.GetLayerWeight(2),
|
|
|
|
(360f - hiddenCam.transform.localEulerAngles.x) / (360f - 300f), Time.deltaTime * 10);
|
|
|
|
animController.SetLayerWeight(2, target);
|
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-01 20:25:46 +02:00
|
|
|
animController.SetLayerWeight(2, Mathf.Lerp(animController.GetLayerWeight(2), 0, Time.deltaTime * 10));
|
|
|
|
animController.SetLayerWeight(3, Mathf.Lerp(animController.GetLayerWeight(3), 0, Time.deltaTime * 10));
|
2023-06-01 17:03:48 +02:00
|
|
|
}
|
2023-06-01 20:25:46 +02:00
|
|
|
|
|
|
|
//print("carrying:" + interactionHandler.IsCarrying + " running:"+animController.GetBool(runningParameter)+" running speed:" + animController.GetFloat(runningSpeedParameter));
|
2023-06-01 17:03:48 +02:00
|
|
|
}
|
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
public void Animate(Vector2 movement, bool jump, bool isMoving)
|
|
|
|
{
|
|
|
|
animController.SetFloat(runningSpeedParameter, movement.magnitude);
|
|
|
|
animController.SetBool(runningParameter, isMoving);
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
if (this.movement.IsAiming)
|
|
|
|
{
|
|
|
|
animController.SetFloat("StrafingSpeed", movement.x);
|
|
|
|
float dir = 0;
|
|
|
|
if (movement.x > 0)
|
|
|
|
dir = 1;
|
|
|
|
else if (movement.x < 0) dir = -1;
|
|
|
|
animController.SetFloat("StrafingDirection", dir);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
animController.SetFloat("StrafingSpeed", 0);
|
|
|
|
animController.SetFloat("StrafingDirection", 1);
|
|
|
|
}
|
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
public void Animate(PlayerQuickAnimationType animation)
|
2023-05-29 06:16:05 +02:00
|
|
|
{
|
2023-06-01 20:25:46 +02:00
|
|
|
switch (animation)
|
|
|
|
{
|
|
|
|
case PlayerQuickAnimationType.Grab:
|
|
|
|
print("grabbing...");
|
|
|
|
break;
|
|
|
|
case PlayerQuickAnimationType.Shoot:
|
|
|
|
print("shooting...");
|
|
|
|
break;
|
|
|
|
}
|
2023-05-29 06:16:05 +02:00
|
|
|
}
|
2023-06-01 20:25:46 +02:00
|
|
|
|
|
|
|
public void Hit(bool isDead)
|
2023-05-29 06:16:05 +02:00
|
|
|
{
|
2023-06-01 20:25:46 +02:00
|
|
|
animController.SetTrigger("WasHit");
|
|
|
|
animController.SetBool("IsDead", isDead);
|
2023-05-29 06:16:05 +02:00
|
|
|
}
|
2023-03-14 00:59:59 +01:00
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
public enum PlayerAnimationType
|
2023-03-14 00:59:59 +01:00
|
|
|
{
|
2023-06-01 20:25:46 +02:00
|
|
|
Movement,
|
|
|
|
Action
|
2023-03-14 00:59:59 +01:00
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-06-01 20:25:46 +02:00
|
|
|
public enum PlayerQuickAnimationType
|
2023-04-04 06:04:34 +02:00
|
|
|
{
|
2023-06-01 20:25:46 +02:00
|
|
|
Grab,
|
|
|
|
Shoot
|
2023-04-04 06:04:34 +02:00
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
}
|