public void OnEvent(IUnit unit, Vector3 position)
        {
            _commandsStorage.TerminateCommand(unit);

            Vector3[] path;
            if (_pathfinder.CalculatePath(unit.Position, position, out path))
            {
                _commandsStorage.ExecuteCommand(unit, new MoveByPath(unit, path, 5));
            }
        }
        public void OnEvent(IUnit unit, Vector3 position)
        {
            _commandsStorage.TerminateCommand(unit);

            Vector3[] path;
            if (!_pathfinder.CalculatePath(unit.Position, position, out path))
            {
                return;
            }

            Vector3[] reversePath = new Vector3[path.Length];
            Array.Copy(path, reversePath, path.Length);
            Array.Reverse(reversePath);

            var unitCmd = new SequenceCommand(
                new MoveByPath(unit, path, 5),
                new PunchUnit(unit, Vector3.one, 1.5f),
                new MoveByPath(unit, reversePath, 5)
                );

            _commandsStorage.ExecuteCommand(unit, unitCmd);
        }
Beispiel #3
0
    public void GeneratePathfindingTask()
    {
        LoadMapToPathfinder();

        if (pathStart.Equals(Vector2Int.left) || pathFinish.Equals(Vector2Int.left))
        {
            ChoosePathEndpoints();
        }

        Vector2Int[] calculatedPath = pathfinder.CalculatePath(pathStart, pathFinish);

        if (calculatedPath == null || calculatedPath.Length < 1)
        {
            DisplayCommunicate("Path not found! (" + pathStart + " => " + pathFinish + ")");
            return;
        }
        else
        {
            warningPopup.ClosePopup();
            mapDisplay.HighlightPath(calculatedPath);
        }
    }