示例#1
0
    public bool ExecTask(Func <float>[] taskActionList, int bindID = 0)
    {
        if (_maxQueueExecTimes != 0 && _taskQueueExecTimes >= _maxQueueExecTimes)
        {
            return(false);
        }

        if (!this.gameObject.activeSelf || !this.gameObject.activeInHierarchy)
        {
            _inactiveTaskList.Add(new QueueTask()
            {
                taskActionList = taskActionList, bindID = bindID
            });
            return(true);
        }

        CheckSameBindID(bindID);

        AsyncAction action = new AsyncAction();

        action.bindID = bindID;
        action.action = () =>
        {
            _curAsyncAction     = action;
            _lastTaskEnumerator = _ExecTask(taskActionList, () =>
            {
                if (action.nextAction == null || _isCancelAll)
                {
                    var isCancelAll      = _isCancelAll;
                    _taskQueueExecTimes += 1;
                    _lastTaskEnumerator  = null;
                    _lastAction          = null;
                    _inactiveTaskList.Clear();
                    _isWaiting      = false;
                    _isCancel       = false;
                    _isCancelAll    = false;
                    _isRunning      = false;
                    _curAsyncAction = null;

                    if (isCancelAll && _onCancelAllDoneCallBack != null)
                    {
                        _onCancelAllDoneCallBack();
                        _onCancelAllDoneCallBack = null;
                    }

                    return;
                }
                action.Complete(null);
            });
            StartCoroutine(_lastTaskEnumerator);
        };

        if (_lastAction == null)
        {
            action.Action();
        }
        else
        {
            _lastAction.nextAction = action;
            _lastAction.OnCompleted((_action) =>
            {
                _action.NextAction();
            });
        }

        _lastAction = action;
        _isRunning  = true;

        return(true);
    }