// Update is called once per frame public void OnUpdate() { while (_ready[_currentReadyIndex].Count > 0) { int nextTaskId = _ready[_currentReadyIndex].Dequeue(); CoroutineTask task = null; if (_taskMap.ContainsKey(nextTaskId)) { task = _taskMap[nextTaskId]; } else { continue; } try{ SystemTask result = task.Run(); if (result != null) { result.task = task; result.Handle(); continue; } } catch (StopIteration e) { Exit(task); continue; } Schedule(task.taskId); } _currentReadyIndex = 1 - _currentReadyIndex; }
public void Callback(int taskId, object result) { CoroutineTask task = _taskMap[taskId]; task.sendval = result; Schedule(task.taskId); }
public int New(IEnumerator target) { CoroutineTask newTask = new CoroutineTask(target); _taskMap [newTask.taskId] = newTask; Schedule(newTask.taskId); return(newTask.taskId); }
public override void Handle() { CoroutineTask task = Singleton <CoroutineDecorator> .Instance.getCoroutineTask(_taskId); if (task != null) { task.Stop(); } Singleton <CoroutineDecorator> .Instance.Schedule(task.taskId); }
public void Exit(CoroutineTask task) { _taskMap.Remove(task.taskId); if (_exitWaiting.ContainsKey(task.taskId)) { List <int> pendingTasks = _exitWaiting [task.taskId]; _exitWaiting.Remove(task.taskId); foreach (int ataskid in pendingTasks) { CoroutineTask atask = _taskMap[ataskid]; Schedule(atask.taskId); } } }
public bool WaitForExit(CoroutineTask task, int waitId) { if (_taskMap.ContainsKey(waitId)) { if (!_exitWaiting.ContainsKey(waitId)) { _exitWaiting[waitId] = new List <int>(); } _exitWaiting[waitId].Add(task.taskId); return(true); } else { return(false); } }