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.

53 lines
1.5KB

  1. #if UNITY_5 || UNITY_5_3_OR_NEWER
  2. using System.Collections;
  3. using Svelto.WeakEvents;
  4. using UnityEngine;
  5. namespace Svelto.ECS.Schedulers.Unity
  6. {
  7. //The EntityViewSubmissionScheduler has been introduced to make
  8. //the entityView submission logic platform indipendent.
  9. //Please don't be tempted to create your own submission to
  10. //adapt to your game level code design. For example,
  11. //you may be tempted to write a submission logic to submit
  12. //the entityViews immediatly just because convenient for your game
  13. //logic. This is not how it works.
  14. public class UnitySumbmissionEntityViewScheduler : EntitySubmissionScheduler
  15. {
  16. public UnitySumbmissionEntityViewScheduler()
  17. {
  18. GameObject go = new GameObject("ECSScheduler");
  19. _scheduler = go.AddComponent<Scheduler>();
  20. }
  21. public override void Schedule(WeakAction submitEntityViews)
  22. {
  23. _scheduler.OnTick = submitEntityViews;
  24. }
  25. class Scheduler : MonoBehaviour
  26. {
  27. IEnumerator Start()
  28. {
  29. while (true)
  30. {
  31. yield return _wait;
  32. if (OnTick.IsValid)
  33. OnTick.Invoke();
  34. else
  35. yield break;
  36. }
  37. }
  38. internal WeakAction OnTick;
  39. readonly WaitForEndOfFrame _wait = new WaitForEndOfFrame();
  40. }
  41. readonly Scheduler _scheduler;
  42. }
  43. }
  44. #endif