SHADE_Y3/Assets/Scripts/AnimTest.cs

81 lines
2.5 KiB
C#
Raw Normal View History

using System;
namespace SHADE.Test
2023-03-09 15:14:30 +08:00
{
public class AnimTest : Script
{
#region Serialized Fields
[SerializeField]
2023-03-09 15:14:30 +08:00
private AnimationClipAsset fullClip;
[SerializeField]
private AnimationClipAsset idleClip;
[SerializeField]
private AnimationClipAsset runClip;
[SerializeField]
private AnimationClipAsset pickUpClip;
2023-03-10 14:55:49 +08:00
[SerializeField]
private bool controlAniSys = false;
#endregion
#region Components
2023-03-09 15:14:30 +08:00
public Animator Animator { get; private set; }
#endregion
#region Lifecycle Functions
protected override void awake()
{
Animator = GetComponent<Animator>();
Animator.OnClipStartedPlaying.RegisterAction((_) => Debug.Log("Start Playing"));
Animator.OnClipPaused.RegisterAction((_) => Debug.Log("Pause"));
Animator.OnClipFinished.RegisterAction((_) => Debug.Log("Finished"));
}
protected override void update()
{
// Play loop if shift is held
Action<AnimationClipAsset> playFunc = Input.GetKey(Input.KeyCode.LeftShift) ? (x) => Animator.Play(x)
: (x) => Animator.PlayOneShot(x);
// Play animations
2023-03-09 15:14:30 +08:00
if (Input.GetKeyUp(Input.KeyCode.Equals))
{
if (fullClip)
playFunc(fullClip);
2023-03-09 15:14:30 +08:00
}
else if (Input.GetKeyUp(Input.KeyCode.Alpha1))
{
if (idleClip)
playFunc(idleClip);
}
else if (Input.GetKeyUp(Input.KeyCode.Alpha2))
{
if (runClip)
playFunc(runClip);
}
else if (Input.GetKeyUp(Input.KeyCode.Alpha3))
{
if (pickUpClip)
playFunc(pickUpClip);
}
2023-03-10 14:55:49 +08:00
// Play and pause
if (controlAniSys && Input.GetKeyUp(Input.KeyCode.Space))
{
AnimationSystem.TimeScale = AnimationSystem.TimeScale > 0.0f ? 0.0f
: AnimationSystem.DefaultTimeScale;
}
if (Input.GetKeyUp(Input.KeyCode.P))
{
if (Animator.IsPlaying)
Animator.Pause();
else
Animator.Play();
}
}
#endregion
}
2023-03-09 15:14:30 +08:00
}