|
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- namespace SUISS.Scheduling
- {
- [Obsolete("If you need the SUISS.Scheduling.Scheduler for an _ingame_ courtine use Scheduler.Instance.")]
- public class SUISSScheduler : IScheduler
- {
- public SUISSScheduler(Scheduler scheduler)
- {
- this._scheduler = scheduler;
- }
-
- public SUISSScheduler(Func<Scheduler> schedulerGetter)
- {
- this._schedulerGetter = schedulerGetter;
- }
-
- public ICoroutine StartCoroutine(IEnumerator<IYieldStatement> routine)
- {
- if (this._scheduler == null)
- {
- if (this._schedulerGetter == null)
- {
- return null;
- }
- this._scheduler = this._schedulerGetter();
- if (this._scheduler == null)
- {
- UnityEngine.Debug.LogWarning("The SUISS scheduler backing this scheduler is null!");
- return null;
- }
- }
- return new SUISSScheduler.Coroutine(routine, this._scheduler);
- }
-
- private Scheduler _scheduler;
-
- private Func<Scheduler> _schedulerGetter;
-
- private class Coroutine : ICoroutine, IYieldStatement
- {
- public Coroutine(IEnumerator<IYieldStatement> routine, Scheduler scheduler)
- {
- this._scheduler = scheduler;
- if (this._scheduler != null)
- {
- this._isRunning = true;
- this._routine = this.Routine(routine);
- this._scheduler.StartRoutine(this._routine);
- }
- }
-
- public void Stop()
- {
- if (this._isRunning && this._scheduler != null)
- {
- this._scheduler.StopRoutine(this._routine);
- this._isRunning = false;
- }
- }
-
- public bool IsRunning
- {
- get
- {
- return this._isRunning;
- }
- }
-
- public object UnityYieldable()
- {
- UnityEngine.Debug.LogWarning("Coroutines started using the SUISS scheduler should not be mixed with the UnityScheduler.");
- return null;
- }
-
- public object UnityYieldable(MonoBehaviour runner)
- {
- UnityEngine.Debug.LogWarning("Coroutines started using the SUISS scheduler should not be mixed with the UnityScheduler.");
- return null;
- }
-
- public object SUISSYieldable()
- {
- return this.BusyWait();
- }
-
- private IEnumerator BusyWait()
- {
- while (this._isRunning)
- {
- yield return null;
- }
- yield break;
- }
-
- private IEnumerator Routine(IEnumerator<IYieldStatement> routine)
- {
- while (routine.MoveNext())
- {
- if (routine.Current != null)
- {
- yield return routine.Current.SUISSYieldable();
- }
- else
- {
- yield return null;
- }
- }
- this._isRunning = false;
- yield break;
- }
-
- private IEnumerator _routine;
-
- private Scheduler _scheduler;
-
- private bool _isRunning;
- }
- }
- }
|