twinStick/twinStickCrawler/Assets/Scripts/Creatures/Animate.cs

64 lines
1.6 KiB
C#
Raw Normal View History

using System;
2024-12-19 11:36:55 +00:00
using UnityEngine;
2024-12-19 11:36:55 +00:00
public class Animate : MonoBehaviour
{
2024-12-20 14:21:20 +00:00
private Animator _animator;
2024-12-23 17:13:28 +00:00
private RuntimeAnimatorController _animatorController;
2024-12-20 14:21:20 +00:00
public void initialize(Animator animator)
{
_animator = animator;
2024-12-23 17:13:28 +00:00
_animatorController = animator.runtimeAnimatorController;
2024-12-20 14:21:20 +00:00
}
2024-12-23 17:13:28 +00:00
2024-12-20 14:21:20 +00:00
public void AnimateState(string animVar, float animVal, float animationSpeed)
{
float t = Mathf.Clamp01(animationSpeed*Time.deltaTime);
2024-12-20 14:21:20 +00:00
float newVal = Mathf.Lerp(_animator.GetFloat(animVar), animVal, t);
_animator.SetFloat(animVar, newVal);
//animator.Play("Attack");
2024-12-20 14:21:20 +00:00
//print(animator.GetCurrentAnimatorStateInfo(1).IsName("Idle"));
}
2024-12-23 17:13:28 +00:00
public bool IsCurrentAnimation(string name)
{
return _animator.GetCurrentAnimatorStateInfo(0).IsName(name);
}
2024-12-20 14:21:20 +00:00
public void TriggerAnimation(string triggerName)
{
_animator.SetTrigger(triggerName);
}
2024-12-23 20:34:57 +00:00
public event Action OnStartDamage;
public event Action OnEndDamage;
2024-12-23 17:13:28 +00:00
public event Action OnReset;
2024-12-23 20:34:57 +00:00
public event Action OnAnimationEnd;
2024-12-23 17:13:28 +00:00
void LeftReset(AnimationEvent animationEvent)
2024-12-19 11:36:55 +00:00
{
2024-12-23 17:13:28 +00:00
OnReset?.Invoke();
}
2024-12-23 17:13:28 +00:00
void RightReset(AnimationEvent animationEvent)
{
2024-12-23 17:13:28 +00:00
OnReset?.Invoke();
2024-12-19 11:36:55 +00:00
}
2024-12-23 17:13:28 +00:00
void KickReset(AnimationEvent animationEvent)
2024-12-19 11:36:55 +00:00
{
2024-12-23 17:13:28 +00:00
OnReset?.Invoke();
2024-12-19 11:36:55 +00:00
}
2024-12-23 20:34:57 +00:00
void StartDamage(AnimationEvent animationEvent)
{
OnStartDamage?.Invoke();
}
void EndDamage(AnimationEvent animationEvent)
{
OnEndDamage?.Invoke();
}
void AnimationEnd(AnimationEvent animationEvent)
{
OnAnimationEnd?.Invoke();
}
2024-12-19 11:36:55 +00:00
}