示例#1
0
        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);
                }
            }
        }
示例#2
0
 public AntTaskManager(bool aIsCycled = false)
 {
     _isStarted   = false;
     _isPaused    = false;
     _isCycled    = aIsCycled;
     _taskList    = new List <AntTask>();
     _currentTask = null;
     _delay       = 0.0f;
 }
示例#3
0
        public void AddUrgentTask(Func <bool> aFunc, bool aIgnoreCycle = false)
        {
            var task = new AntTask();

            task.SetProcess(aFunc);
            task.IsIgnoreCycle = aIgnoreCycle;
            Unshift(task);
            Start();
        }
示例#4
0
 public bool OnDelay(AntTask aTask, float aDelay)
 {
     _delay += aTask.DeltaTime;
     if (_delay > aDelay)
     {
         _delay = 0.0f;
         return(true);
     }
     return(false);
 }
示例#5
0
        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();
        }
示例#6
0
        protected AntTask Shift()
        {
            AntTask result = null;

            if (_taskList.Count > 0)
            {
                result = _taskList[0];
                _taskList.RemoveAt(0);
            }
            return(result);
        }
示例#7
0
        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();
        }
示例#8
0
        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();
        }
示例#9
0
        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();
        }
示例#10
0
 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);
     }
 }
示例#11
0
        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!");
                }
            }
        }
示例#12
0
 protected void Push(AntTask aTask)
 {
     _taskList.Add(aTask);
 }
示例#13
0
 public void Clear()
 {
     Stop();
     _taskList.Clear();
     _currentTask = null;
 }