ExposedPropertyTable.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. #if UNITY_PLAYABLE_DIRECTOR
  3. using UnityEngine;
  4. using UnityEngine.Playables;
  5. namespace Animancer
  6. {
  7. /// <summary>Sets a <see cref="PlayableDirector"/> as Animancer's <see cref="IExposedPropertyTable"/>.</summary>
  8. /// <remarks>
  9. /// This class allows Control Tracks to work properly when played in a <see cref="PlayableAssetState"/>.
  10. /// <para></para>
  11. /// <strong>Documentation:</strong>
  12. /// <see href="https://kybernetik.com.au/animancer/docs/manual/timeline#exposed-references">
  13. /// Exposed References</see>
  14. /// </remarks>
  15. /// https://kybernetik.com.au/animancer/api/Animancer/ExposedPropertyTable
  16. ///
  17. [AddComponentMenu(Strings.MenuPrefix + "Exposed Property Table")]
  18. [AnimancerHelpUrl(typeof(ExposedPropertyTable))]
  19. [DefaultExecutionOrder(-10000)]// Initialize before anything else might need to use the table.
  20. public class ExposedPropertyTable : MonoBehaviour
  21. {
  22. /************************************************************************************************************************/
  23. [SerializeField] private AnimancerComponent _Animancer;
  24. [SerializeField] private PlayableDirector _Director;
  25. /************************************************************************************************************************/
  26. /// <summary>Calls <see cref="OnValidate"/> and if no <see cref="PlayableDirector"/> was found it adds one.</summary>
  27. protected virtual void Reset()
  28. {
  29. OnValidate();
  30. if (_Director == null)
  31. _Director = gameObject.AddComponent<PlayableDirector>();
  32. _Director.enabled = false;
  33. _Director.playOnAwake = false;
  34. }
  35. /************************************************************************************************************************/
  36. /// <summary>Tries to automatically find any missing references.</summary>
  37. protected virtual void OnValidate()
  38. {
  39. gameObject.GetComponentInParentOrChildren(ref _Animancer);
  40. gameObject.GetComponentInParentOrChildren(ref _Director);
  41. }
  42. /************************************************************************************************************************/
  43. /// <summary>Sets the <see cref="PlayableDirector"/> as Animancer's <see cref="IExposedPropertyTable"/>.</summary>
  44. protected virtual void Awake()
  45. {
  46. _Animancer.Graph.PlayableGraph.SetResolver(_Director);
  47. }
  48. /************************************************************************************************************************/
  49. }
  50. }
  51. #endif