public void Execute() { if (_currentTask != null && _isStarted) { if (!_isPaused) { _currentTask.Update(Time.deltaTime); if (_currentTask.IsFinished) { if (_isCycled && !_currentTask.IsIgnoreCycle) { _currentTask.IsFinished = false; Push(_currentTask); } _currentTask = Shift(); } } } else { Stop(); if (EventComplete != null) { EventComplete(this); } } }
public AntTaskManager(bool aIsCycled = false) { _isStarted = false; _isPaused = false; _isCycled = aIsCycled; _taskList = new List <AntTask>(); _currentTask = null; _delay = 0.0f; }
public void AddUrgentTask(Func <bool> aFunc, bool aIgnoreCycle = false) { var task = new AntTask(); task.SetProcess(aFunc); task.IsIgnoreCycle = aIgnoreCycle; Unshift(task); Start(); }
public bool OnDelay(AntTask aTask, float aDelay) { _delay += aTask.DeltaTime; if (_delay > aDelay) { _delay = 0.0f; return(true); } return(false); }
public void AddDelay(float aDelay, bool aIgnoreCycle = false) { var task = new AntTask <AntTask, float>(); task.SetProcess(OnDelay); task.SetArguments(task, aDelay); task.IsIgnoreCycle = aIgnoreCycle; Push(task); Start(); }
protected AntTask Shift() { AntTask result = null; if (_taskList.Count > 0) { result = _taskList[0]; _taskList.RemoveAt(0); } return(result); }
public void AddUrgentTask <T1, T2, T3, T4>(Func <T1, T2, T3, T4, bool> aFunc, T1 aArg1, T2 aArg2, T3 aArg3, T4 aArg4, bool aIgnoreCycle = false) { var task = new AntTask <T1, T2, T3, T4>(); task.SetProcess(aFunc); task.SetArguments(aArg1, aArg2, aArg3, aArg4); task.IsIgnoreCycle = aIgnoreCycle; Unshift(task); Start(); }
public void AddUrgentTask <T1>(Func <T1, bool> aFunc, T1 aArg1, bool aIgnoreCycle = false) { var task = new AntTask <T1>(); task.SetProcess(aFunc); task.SetArguments(aArg1); task.IsIgnoreCycle = aIgnoreCycle; Unshift(task); Start(); }
public void AddTask <T1, T2, T3>(Func <T1, T2, T3, bool> aFunc, T1 aArg1, T2 aArg2, T3 aArg3, bool aIgnoreCycle = false) { var task = new AntTask <T1, T2, T3>(); task.SetProcess(aFunc); task.SetArguments(aArg1, aArg2, aArg3); task.IsIgnoreCycle = aIgnoreCycle; Push(task); Start(); }
protected void Unshift(AntTask aTask) { if (_currentTask != null) { int index = _taskList.IndexOf(_currentTask); if (index >= 0 && index < _taskList.Count && index + 1 < _taskList.Count) { _taskList.Insert(index + 1, aTask); } else { _taskList.Insert(0, aTask); } } else { _taskList.Insert(0, aTask); } }
protected void Start() { if (!_isStarted && _taskList.Count > 0) { if (AntEngine.Current != null) { AntEngine.Current.Add((ISystem)this); _currentTask = Shift(); _isStarted = true; _isPaused = false; if (EventStart != null) { EventStart(this); } } else { AntLog.Report("AntTaskManager", "AntEngine not initialized!"); } } }
protected void Push(AntTask aTask) { _taskList.Add(aTask); }
public void Clear() { Stop(); _taskList.Clear(); _currentTask = null; }