예제 #1
0
        public void MoveToMovementGoal(bool movingTarget = false, bool useBlockedCoordinates = false)
        {
            if (Task.current.isStarting || _needResetPathFind)
            {
                _needResetPathFind = false;
                if (_preComputedPathToMovementGoal == null)
                {
                    List <Vector2> blockedCoordinates = null;

                    if (useBlockedCoordinates)
                    {
                        blockedCoordinates = GetBlockedCoordinates();
                    }

                    _pathIsFound = false;
                    //_movementCoordinator.UnlockDir();
                    _pathManager.RequestTask(
                        this,
                        _movementGoal,
                        (PathObjectPair pop) =>
                    {
                        _pathIsFound = true;
                        _path        = pop.GetPath();

                        _pathIndex = 0;
                        _aiPathFindCompleteSignal.Fire(_path);
                        //  _path.PaintPath();
                    },
                        blockedCoordinates
                        );
                    if (movingTarget)
                    {
                        StartCoroutine(ResetPathFindNeed());
                        _needResetPathFind = false;
                    }
                }
                else
                {
                    _path        = _preComputedPathToMovementGoal;
                    _pathIndex   = 0;
                    _pathIsFound = true;
                    _aiPathFindCompleteSignal.Fire(_preComputedPathToMovementGoal);
                }
            }

            if (_pathIsFound)
            {
                if (_path.GetLength() != 0)
                {
                    _pathIndex = _movementController.StepPath(_path, _pathIndex);
                    if (_pathIndex == -1)
                    {
                        Task.current.Complete(true);
                    }
                }
                else
                {
                    Task.current.Complete(false);
                }
            }
        }