This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/Scripts/Player/PlayerAnimationController.cs

120 lines
3.9 KiB
C#

using UnityEngine;
namespace Player
{
public class PlayerAnimationController : MonoBehaviour
{
[SerializeField] private Animator animController;
[SerializeField] private string runningParameter;
[SerializeField] private string runningSpeedParameter;
[SerializeField] private string sideStepSpeedParameter;
//private bool movementInterrupt = false;
[SerializeField] private PlayerInteractionHandler interactionHandler;
[SerializeField] private PlayerMovementController movement;
//private float verticalAiming = 0;
[SerializeField] private Camera hiddenCam;
private bool isRunning;
private float runningSpeed;
private float sideStepSpeed;
// Start is called before the first frame update
private void Start()
{
}
// Update is called once per frame
private void Update()
{
animController.SetBool("IsCarrying", interactionHandler.IsCarrying);
animController.SetBool("HasGun", interactionHandler.GunEnabled);
if (interactionHandler.GunEnabled && !interactionHandler.isDead && movement.AllowRotation)
{
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);
}
}
else
{
animController.SetLayerWeight(2, Mathf.Lerp(animController.GetLayerWeight(2), 0, Time.deltaTime * 10));
animController.SetLayerWeight(3, Mathf.Lerp(animController.GetLayerWeight(3), 0, Time.deltaTime * 10));
}
//print("carrying:" + interactionHandler.IsCarrying + " running:"+animController.GetBool(runningParameter)+" running speed:" + animController.GetFloat(runningSpeedParameter));
}
public void Animate(Vector2 movement, bool jump, bool isMoving)
{
animController.SetFloat(runningSpeedParameter, movement.magnitude);
animController.SetBool(runningParameter, isMoving);
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);
}
}
public void Animate(PlayerQuickAnimationType animation)
{
switch (animation)
{
case PlayerQuickAnimationType.Grab:
print("grabbing...");
break;
case PlayerQuickAnimationType.Shoot:
print("shooting...");
break;
}
}
public void Hit(bool isDead)
{
animController.SetTrigger("WasHit");
animController.SetBool("IsDead", isDead);
}
}
public enum PlayerAnimationType
{
Movement,
Action
}
public enum PlayerQuickAnimationType
{
Grab,
Shoot
}
}