AnimancerTransitionAssetT.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2022 Kybernetik //
  2. using UnityEngine;
  3. namespace Animancer
  4. {
  5. /// <inheritdoc/>
  6. /// https://kybernetik.com.au/animancer/api/Animancer/AnimancerTransitionAsset_1
  7. [HelpURL(Strings.DocsURLs.APIDocumentation + "/" + nameof(AnimancerTransitionAsset<ITransition>) + "_1")]
  8. public class AnimancerTransitionAsset<TTransition> : AnimancerTransitionAssetBase
  9. where TTransition : ITransition
  10. {
  11. /************************************************************************************************************************/
  12. [SerializeReference]
  13. private TTransition _Transition;
  14. /// <summary>[<see cref="SerializeReference"/>]
  15. /// The <see cref="ITransition"/> wrapped by this <see cref="ScriptableObject"/>.
  16. /// </summary>
  17. /// <remarks>
  18. /// WARNING: the <see cref="AnimancerTransition{TState}.State"/> holds the most recently played state, so
  19. /// if you are sharing this transition between multiple objects it will only remember one of them.
  20. /// Consider using an <see cref="AnimancerTransitionAssetBase.UnShared{TAsset}"/>.
  21. /// <para></para>
  22. /// You can use <see cref="AnimancerPlayable.StateDictionary.GetOrCreate(ITransition)"/> or
  23. /// <see cref="AnimancerLayer.GetOrCreateState(ITransition)"/> to get or create the state for a
  24. /// specific object.
  25. /// </remarks>
  26. public TTransition Transition
  27. {
  28. get
  29. {
  30. AssertTransition();
  31. return _Transition;
  32. }
  33. set => _Transition = value;
  34. }
  35. /// <summary>Returns the <see cref="ITransition"/> wrapped by this <see cref="ScriptableObject"/>.</summary>
  36. public override ITransition GetTransition()
  37. {
  38. AssertTransition();
  39. return _Transition;
  40. }
  41. /************************************************************************************************************************/
  42. /// <summary>Is the <see cref="Transition"/> assigned (i.e. not <c>null</c>)?</summary>
  43. public bool HasTransition => _Transition != null;
  44. /************************************************************************************************************************/
  45. /// <summary>[Assert-Conditional] Logs an error if the <see cref="Transition"/> is null.</summary>
  46. [System.Diagnostics.Conditional(Strings.Assertions)]
  47. private void AssertTransition()
  48. {
  49. if (_Transition == null)
  50. Debug.LogError($"'{name}' {nameof(Transition)} is not assigned." +
  51. $" {nameof(HasTransition)} can be used to check without triggering this error.", this);
  52. }
  53. /************************************************************************************************************************/
  54. #if UNITY_EDITOR
  55. /// <summary>[Editor-Only]
  56. /// Assigns a default <typeparamref name="TTransition"/> to the <see cref="Transition"/> field.
  57. /// </summary>
  58. protected virtual void Reset()
  59. {
  60. _Transition = Editor.TypeSelectionButton.CreateDefaultInstance<TTransition>();
  61. }
  62. #endif
  63. /************************************************************************************************************************/
  64. }
  65. }