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.

UnityTicker.cs 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine;
  2. namespace Svelto.Ticker
  3. {
  4. class UnityTicker : ITicker
  5. {
  6. public UnityTicker()
  7. {
  8. _ticker = Object.FindObjectOfType<TickBehaviour>();
  9. if (_ticker == null)
  10. {
  11. var 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 IEndOfFrameTickable)
  24. _ticker.AddEndOfFrame(tickable as IEndOfFrameTickable);
  25. if (tickable is IIntervaledTickable)
  26. _ticker.AddIntervaled(tickable as IIntervaledTickable);
  27. }
  28. public void Remove(ITickableBase tickable)
  29. {
  30. if (tickable is ITickable)
  31. _ticker.Remove(tickable as ITickable);
  32. if (tickable is IPhysicallyTickable)
  33. _ticker.RemovePhysic(tickable as IPhysicallyTickable);
  34. if (tickable is ILateTickable)
  35. _ticker.RemoveLate(tickable as ILateTickable);
  36. if (tickable is IEndOfFrameTickable)
  37. _ticker.RemoveEndOfFrame(tickable as IEndOfFrameTickable);
  38. if (tickable is IIntervaledTickable)
  39. _ticker.RemoveIntervaled(tickable as IIntervaledTickable);
  40. }
  41. readonly TickBehaviour _ticker;
  42. }
  43. }