12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
- using UnityEngine;
- namespace Animancer.Examples.Basics
- {
-
-
-
-
-
-
- [AddComponentMenu(Strings.ExamplesMenuPrefix + "Basics - Basic Character Animations")]
- [HelpURL(Strings.DocsURLs.ExampleAPIDocumentation + nameof(Basics) + "/" + nameof(BasicCharacterAnimations))]
- public sealed class BasicCharacterAnimations : MonoBehaviour
- {
-
- [SerializeField] private AnimancerComponent _Animancer;
- [SerializeField] private ClipTransition _Idle;
- [SerializeField] private ClipTransition _Move;
- [SerializeField] private ClipTransition _Action;
- private enum State
- {
-
- NotActing,
-
- Acting,
- }
- private State _CurrentState;
-
- private void Awake()
- {
- _Action.Events.OnEnd = OnActionEnd;
- }
-
- private void OnActionEnd()
- {
- _CurrentState = State.NotActing;
- UpdateMovement();
- }
-
- private void Update()
- {
- switch (_CurrentState)
- {
- case State.NotActing:
- UpdateMovement();
- UpdateAction();
- break;
- case State.Acting:
- UpdateAction();
- break;
- }
- }
-
- private void UpdateMovement()
- {
- float forward = ExampleInput.WASD.y;
- if (forward > 0)
- {
- _Animancer.Play(_Move);
- }
- else
- {
- _Animancer.Play(_Idle);
- }
- }
-
- private void UpdateAction()
- {
- if (ExampleInput.LeftMouseUp)
- {
- _CurrentState = State.Acting;
- _Animancer.Play(_Action);
- }
- }
-
- }
- }
|