81 lines
2.5 KiB
C#
81 lines
2.5 KiB
C#
using System;
|
|
|
|
namespace SHADE.Test
|
|
{
|
|
public class AnimTest : Script
|
|
{
|
|
#region Serialized Fields
|
|
[SerializeField]
|
|
private AnimationClipAsset fullClip;
|
|
[SerializeField]
|
|
private AnimationClipAsset idleClip;
|
|
[SerializeField]
|
|
private AnimationClipAsset runClip;
|
|
[SerializeField]
|
|
private AnimationClipAsset pickUpClip;
|
|
[SerializeField]
|
|
private bool controlAniSys = false;
|
|
#endregion
|
|
|
|
#region Components
|
|
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
|
|
if (Input.GetKeyUp(Input.KeyCode.Equals))
|
|
{
|
|
if (fullClip)
|
|
playFunc(fullClip);
|
|
}
|
|
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);
|
|
}
|
|
|
|
// 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
|
|
}
|
|
}
|