2023-03-09 15:46:15 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace SHADE.Test
|
2023-03-09 15:14:30 +08:00
|
|
|
|
{
|
2023-03-09 13:35:49 +08:00
|
|
|
|
public class AnimTest : Script
|
|
|
|
|
{
|
|
|
|
|
#region Serialized Fields
|
|
|
|
|
[SerializeField]
|
2023-03-09 15:14:30 +08:00
|
|
|
|
private AnimationClipAsset fullClip;
|
|
|
|
|
[SerializeField]
|
2023-03-09 13:35:49 +08:00
|
|
|
|
private AnimationClipAsset idleClip;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private AnimationClipAsset runClip;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private AnimationClipAsset pickUpClip;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Components
|
2023-03-09 15:14:30 +08:00
|
|
|
|
public Animator Animator { get; private set; }
|
2023-03-09 13:35:49 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Lifecycle Functions
|
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
|
|
|
|
Animator = GetComponent<Animator>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void update()
|
|
|
|
|
{
|
2023-03-09 15:46:15 +08:00
|
|
|
|
// 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))
|
|
|
|
|
{
|
2023-03-10 14:11:59 +08:00
|
|
|
|
if (fullClip)
|
|
|
|
|
playFunc(fullClip);
|
2023-03-09 15:14:30 +08:00
|
|
|
|
}
|
|
|
|
|
else if (Input.GetKeyUp(Input.KeyCode.Alpha1))
|
2023-03-09 13:35:49 +08:00
|
|
|
|
{
|
2023-03-10 14:11:59 +08:00
|
|
|
|
if (idleClip)
|
|
|
|
|
playFunc(idleClip);
|
2023-03-09 13:35:49 +08:00
|
|
|
|
}
|
|
|
|
|
else if (Input.GetKeyUp(Input.KeyCode.Alpha2))
|
|
|
|
|
{
|
2023-03-10 14:11:59 +08:00
|
|
|
|
if (runClip)
|
|
|
|
|
playFunc(runClip);
|
2023-03-09 13:35:49 +08:00
|
|
|
|
}
|
|
|
|
|
else if (Input.GetKeyUp(Input.KeyCode.Alpha3))
|
|
|
|
|
{
|
2023-03-10 14:11:59 +08:00
|
|
|
|
if (pickUpClip)
|
|
|
|
|
playFunc(pickUpClip);
|
2023-03-09 13:35:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2023-03-09 15:14:30 +08:00
|
|
|
|
}
|