SimpleLeanComponent.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2022 Kybernetik //
  2. #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
  3. using UnityEngine;
  4. namespace Animancer.Examples.Jobs
  5. {
  6. /// <summary>
  7. /// An example component that demonstrates how to use <see cref="SimpleLean"/>.
  8. /// </summary>
  9. ///
  10. /// <remarks>
  11. /// Since <see cref="SimpleLean"/> is not a <see cref="MonoBehaviour"/> component, we need this script to
  12. /// demonstrate its use. However, in a real project you might simply integrate the contents of this class into one
  13. /// of your existing classes.
  14. /// </remarks>
  15. ///
  16. /// <example><see href="https://kybernetik.com.au/animancer/docs/examples/jobs/lean">Lean</see></example>
  17. ///
  18. /// https://kybernetik.com.au/animancer/api/Animancer.Examples.Jobs/SimpleLeanComponent
  19. ///
  20. [AddComponentMenu(Strings.ExamplesMenuPrefix + "Jobs - Simple Lean")]
  21. [HelpURL(Strings.DocsURLs.ExampleAPIDocumentation + nameof(Jobs) + "/" + nameof(SimpleLeanComponent))]
  22. public sealed class SimpleLeanComponent : MonoBehaviour
  23. {
  24. /************************************************************************************************************************/
  25. // Initialisation.
  26. /************************************************************************************************************************/
  27. [SerializeField]
  28. private AnimancerComponent _Animancer;
  29. private SimpleLean _Lean;
  30. private void Awake()
  31. {
  32. _Lean = new SimpleLean(_Animancer.Playable);
  33. }
  34. /************************************************************************************************************************/
  35. // Usage.
  36. /************************************************************************************************************************/
  37. // Set by a UI Slider.
  38. public float Angle
  39. {
  40. get => _Lean.Angle;
  41. set => _Lean.Angle = value;
  42. }
  43. /************************************************************************************************************************/
  44. [SerializeField]
  45. private Transform _Axis;
  46. private void Update()
  47. {
  48. _Lean.Axis = _Axis.forward;
  49. }
  50. /************************************************************************************************************************/
  51. }
  52. }