DirectionalClipTransition.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. using System;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace Animancer
  6. {
  7. /// <summary>A <see cref="ClipTransition"/> which gets its clip from a <see cref="DirectionalAnimationSet"/>.</summary>
  8. ///
  9. /// <remarks>
  10. /// <para></para>
  11. /// <strong>Documentation:</strong>
  12. /// <see href="https://kybernetik.com.au/animancer/docs/manual/playing/directional-sets">
  13. /// Directional Animation Sets</see>
  14. /// <para></para>
  15. /// <strong>Example:</strong><code>
  16. /// // Leave the Clip field empty in the Inspector and assign its AnimationSet instead.
  17. /// [SerializeField] private DirectionalClipTransition _Transition;
  18. ///
  19. /// ...
  20. ///
  21. /// // Then you can just call SetDirection and Play it like any other transition.
  22. /// // All of the transition's details like Fade Duration and Events will be applied to whichever clip is plays.
  23. /// _Transition.SetDirection(Vector2.right);
  24. /// _Animancer.Play(_Transition);
  25. /// </code></remarks>
  26. ///
  27. /// https://kybernetik.com.au/animancer/api/Animancer/DirectionalClipTransition
  28. ///
  29. [Serializable]
  30. public class DirectionalClipTransition : ClipTransition,
  31. ICopyable<DirectionalClipTransition>
  32. {
  33. /************************************************************************************************************************/
  34. [SerializeField]
  35. [Tooltip("The animations which used to determine the " + nameof(Clip))]
  36. private DirectionalAnimationSet _AnimationSet;
  37. /// <summary>[<see cref="SerializeField"/>]
  38. /// The <see cref="DirectionalAnimationSet"/> used to determine the <see cref="ClipTransition.Clip"/>.
  39. /// </summary>
  40. public ref DirectionalAnimationSet AnimationSet
  41. => ref _AnimationSet;
  42. /// <inheritdoc/>
  43. public override UnityEngine.Object MainObject
  44. => _AnimationSet;
  45. /// <summary>The name of the serialized backing field of <see cref="AnimationSet"/>.</summary>
  46. public const string AnimationSetField = nameof(_AnimationSet);
  47. /************************************************************************************************************************/
  48. /// <summary>Sets the <see cref="ClipTransition.Clip"/> from the <see cref="AnimationSet"/>.</summary>
  49. public void SetDirection(Vector2 direction)
  50. => Clip = _AnimationSet.GetClip(direction);
  51. /// <summary>Sets the <see cref="ClipTransition.Clip"/> from the <see cref="AnimationSet"/>.</summary>
  52. public void SetDirection(int direction)
  53. => Clip = _AnimationSet.GetClip(direction);
  54. /// <summary>Sets the <see cref="ClipTransition.Clip"/> from the <see cref="AnimationSet"/>.</summary>
  55. public void SetDirection(DirectionalAnimationSet.Direction direction)
  56. => Clip = _AnimationSet.GetClip(direction);
  57. /// <summary>Sets the <see cref="ClipTransition.Clip"/> from the <see cref="AnimationSet"/>.</summary>
  58. public void SetDirection(DirectionalAnimationSet8.Direction direction)
  59. => Clip = _AnimationSet.GetClip((int)direction);
  60. /************************************************************************************************************************/
  61. /// <inheritdoc/>
  62. public override void GatherAnimationClips(ICollection<AnimationClip> clips)
  63. {
  64. base.GatherAnimationClips(clips);
  65. clips.GatherFromSource(_AnimationSet);
  66. }
  67. /************************************************************************************************************************/
  68. /// <inheritdoc/>
  69. public virtual void CopyFrom(DirectionalClipTransition copyFrom, CloneContext context)
  70. {
  71. base.CopyFrom(copyFrom, context);
  72. if (copyFrom == null)
  73. {
  74. _AnimationSet = default;
  75. return;
  76. }
  77. _AnimationSet = copyFrom._AnimationSet;
  78. }
  79. /************************************************************************************************************************/
  80. }
  81. }