/// <summary> /// This function waits until the current task is done before setting the new task. /// </summary> /// <param name="task"></param> /// <returns></returns> public virtual IEnumerator <YieldInstruction> WaitSetTask(GroundTask task) { yield return(new WaitWhile(() => { return Task != null && !Task.Finished(); })); Task = task; CoroutineManager.Instance.StartCoroutine(new Coroutine(runToCompletion()), true); }
/// <summary> /// Set the entity's current task to the one specified in parameters. /// Only sets the task if the current one is finished! /// </summary> /// <param name="task">New task to set as current task</param> /// <returns>Returns false if the entity is still running a task! And true if the task was properly set!</returns> public virtual bool SetTask(GroundTask task) { if (Task != null && !Task.Finished()) { return(false); } Task = task; return(true); }
/// <summary> /// Set the entity's current task to the one specified in parameters. /// Only sets the task if the current one is finished! /// </summary> /// <param name="task">New task to set as current task</param> /// <returns>Returns false if the entity is still running a task! And true if the task was properly set!</returns> public virtual bool SetTask(GroundTask task) { if (Task != null && !Task.Finished()) { return(false); } Task = task; CoroutineManager.Instance.StartCoroutine(new Coroutine(runToCompletion()), true); return(true); }
/// <summary> /// Update tasks specifically. /// </summary> public virtual void UpdateTask() { if (Task == null) { return; } if (TaskState == ETaskState.None) { CoroutineManager.Instance.StartCoroutine(runToCompletion()); } else if (TaskState == ETaskState.Complete) { TaskState = ETaskState.None; } if (Task.Finished()) { Task = null; } }
/// <summary> /// This function waits until the current task is done before setting the new task. /// </summary> /// <param name="task"></param> /// <returns></returns> public virtual IEnumerator <YieldInstruction> WaitSetTask(GroundTask task) { yield return(new WaitWhile(() => { return Task != null && !Task.Finished(); })); Task = task; }
private IEnumerator <YieldInstruction> runToCompletion() { yield return(CoroutineManager.Instance.StartCoroutine(Task.Run(this))); Task = null; }