SHADE_Y3/Assets/Scripts/AnimTest.cs

68 lines
2.1 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>();
}
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;
}
}
#endregion
}
}