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.

48 lines
1.4KB

  1. #if UNITY_5 || UNITY_5_3_OR_NEWER
  2. using Object = UnityEngine.Object;
  3. using UnityEngine;
  4. namespace Svelto.ECS.Schedulers.Unity
  5. {
  6. //The EntitySubmissionScheduler has been introduced to make the entity components submission logic platform independent
  7. //You can customize the scheduler if you wish
  8. public class UnityEntitiesSubmissionScheduler : EntitiesSubmissionScheduler
  9. {
  10. public UnityEntitiesSubmissionScheduler(string name)
  11. {
  12. _scheduler = new GameObject(name).AddComponent<MonoScheduler>();
  13. GameObject.DontDestroyOnLoad(_scheduler.gameObject);
  14. _scheduler.onTick = SubmitEntities;
  15. }
  16. public override void Dispose()
  17. {
  18. if (_scheduler != null && _scheduler.gameObject != null)
  19. {
  20. Object.Destroy(_scheduler.gameObject);
  21. }
  22. }
  23. public override bool paused { get; set; }
  24. void SubmitEntities()
  25. {
  26. if (paused == false)
  27. {
  28. var enumerator = _onTick.submitEntities;
  29. enumerator.MoveNext();
  30. while (enumerator.Current == true) enumerator.MoveNext();
  31. }
  32. }
  33. protected internal override EnginesRoot.EntitiesSubmitter onTick
  34. {
  35. set => _onTick = value;
  36. }
  37. readonly MonoScheduler _scheduler;
  38. EnginesRoot.EntitiesSubmitter _onTick;
  39. }
  40. }
  41. #endif