Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4KB

  1. using UnityEngine;
  2. namespace Svelto.Ticker
  3. {
  4. internal class UnityTicker: ITicker
  5. {
  6. public UnityTicker()
  7. {
  8. _ticker = GameObject.FindObjectOfType<TickBehaviour>();
  9. if (_ticker == null)
  10. {
  11. GameObject go = new GameObject("SveltoTicker");
  12. _ticker = go.AddComponent<TickBehaviour>();
  13. }
  14. }
  15. public void Add(ITickableBase tickable)
  16. {
  17. if (tickable is ITickable)
  18. _ticker.Add(tickable as ITickable);
  19. if (tickable is IPhysicallyTickable)
  20. _ticker.AddPhysic(tickable as IPhysicallyTickable);
  21. if (tickable is ILateTickable)
  22. _ticker.AddLate(tickable as ILateTickable);
  23. if (tickable is IIntervaledTickable)
  24. _ticker.AddIntervaled(tickable as IIntervaledTickable);
  25. }
  26. public void Remove(ITickableBase tickable)
  27. {
  28. if (tickable is ITickable)
  29. _ticker.Remove(tickable as ITickable);
  30. if (tickable is IPhysicallyTickable)
  31. _ticker.RemovePhysic(tickable as IPhysicallyTickable);
  32. if (tickable is ILateTickable)
  33. _ticker.RemoveLate(tickable as ILateTickable);
  34. if (tickable is IIntervaledTickable)
  35. _ticker.RemoveIntervaled(tickable as IIntervaledTickable);
  36. }
  37. private TickBehaviour _ticker;
  38. }
  39. }