GolfCharacter.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
  3. using UnityEngine;
  4. namespace Animancer.Samples.Events
  5. {
  6. /// <summary>Manages a character with the ability to hit a golf ball.</summary>
  7. ///
  8. /// <remarks>
  9. /// <strong>Sample:</strong>
  10. /// <see href="https://kybernetik.com.au/animancer/docs/samples/events/golf">
  11. /// Golf Events</see>
  12. /// </remarks>
  13. ///
  14. /// https://kybernetik.com.au/animancer/api/Animancer.Samples.Events/GolfCharacter
  15. ///
  16. [AddComponentMenu(Strings.SamplesMenuPrefix + "Golf Events - Golf Character")]
  17. [AnimancerHelpUrl(typeof(GolfCharacter))]
  18. public class GolfCharacter : MonoBehaviour
  19. {
  20. /************************************************************************************************************************/
  21. private static readonly StringReference HitEventName = "Hit";
  22. [SerializeField] private AnimancerComponent _Animancer;
  23. [SerializeField] private ClipTransition _Ready;
  24. [SerializeField, EventNames] private ClipTransition _Swing;
  25. [SerializeField] private GolfBall _Ball;
  26. /************************************************************************************************************************/
  27. protected virtual void Awake()
  28. {
  29. _Swing.Events.SetCallback(HitEventName, _Ball.Hit);
  30. _Swing.Events.OnEnd = PlayReady;
  31. _Animancer.Play(_Ready);
  32. }
  33. /************************************************************************************************************************/
  34. protected virtual void Update()
  35. {
  36. if (_Ball.ReadyToHit && SampleInput.LeftMouseDown)
  37. _Animancer.Play(_Swing);
  38. }
  39. /************************************************************************************************************************/
  40. private void PlayReady()
  41. {
  42. _Animancer.Play(_Ready);
  43. }
  44. /************************************************************************************************************************/
  45. }
  46. }