GlobalClock.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Chronos
  5. {
  6. /// <summary>
  7. /// A Clock that affects all Timeline and other global clocks configured as its children.
  8. /// </summary>
  9. [AddComponentMenu("Time/Global Clock")]
  10. [HelpURL("http://ludiq.io/chronos/documentation#GlobalClock")]
  11. public class GlobalClock : Clock
  12. {
  13. public GlobalClock()
  14. {
  15. clocks = new HashSet<Clock>();
  16. timelines = new HashSet<Timeline>();
  17. }
  18. #region Fields
  19. protected HashSet<Clock> clocks;
  20. protected HashSet<Timeline> timelines;
  21. #endregion
  22. #region Properties
  23. [SerializeField]
  24. private string _key;
  25. /// <summary>
  26. /// The unique key of the global clock.
  27. /// </summary>
  28. public string key
  29. {
  30. get { return _key; }
  31. internal set { _key = value; }
  32. }
  33. #endregion
  34. internal virtual void Register(Timeline timeline)
  35. {
  36. if (timeline == null) throw new ArgumentNullException("timeline");
  37. timelines.Add(timeline);
  38. }
  39. internal virtual void Unregister(Timeline timeline)
  40. {
  41. if (timeline == null) throw new ArgumentNullException("timeline");
  42. timelines.Remove(timeline);
  43. }
  44. internal virtual void Register(Clock clock)
  45. {
  46. if (clock == null) throw new ArgumentNullException("clock");
  47. clocks.Add(clock);
  48. }
  49. internal virtual void Unregister(Clock clock)
  50. {
  51. if (clock == null) throw new ArgumentNullException("clock");
  52. clocks.Remove(clock);
  53. }
  54. }
  55. }