Exemple #1
0
 private void RedrawPath(List <Vector3Int> oldPath, List <Vector3Int> newPath)
 {
     if (oldPath != null)
     {
         pathDrawer?.ClearPath(oldPath.Except(newPath).ToList());// убираем весь старый путь которого нет в новом
     }
     if (newPath != null)
     {
         pathDrawer?.PrintPath(oldPath != null ? newPath.Except(oldPath).ToList() : newPath);
     }
 }
Exemple #2
0
        private void OnFingerUp(LeanFinger finger)
        {
            LeanTouch.OnFingerSet -= OnFingerSet;
            LeanTouch.OnFingerUp  -= OnFingerUp;
            var currentHoveredCell = TownTilemap.WorldToCell(finger.GetWorldPosition(10));
            var town = TownTilemap.GetTile(currentHoveredCell) as TownCell;

            if (town != null && lastTappedTownPosition != currentHoveredCell) //check if we hit a different town
            {
                if (lastPath != null && lastPath.Any())
                {
                    if (FixateRoad())
                    {
                        GetComponent <AudioManager>().PlayPop(true);
                        EstablishPath();
                        return;
                    }
                }
            }

            pathDrawer.ClearPath(lastPath); // убираем весь путь ибо не получилось зафиксировать его
            lastPath = new List <Vector3Int>();
        }
    private void Drag()
    {
        if (Input.GetMouseButtonUp(0))
        {
            ControlState = ControlStates.MOVING;

            _pathFollower.EngagePath(_path);
            _pathDrawer.ClearPath();

            return;
        }

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        Physics.Raycast(ray, out RaycastHit hit, _layerMask);
        var mousepos = hit.point;

        mousepos.z = 2;

        _path.Enqueue(mousepos);
        _pathDrawer.PushPath(Input.mousePosition);
    }
    void Update()
    {
        Cell selectedCell = GridManager.GetMouseCell();

        if (EventSystem.current == null || !EventSystem.current.IsPointerOverGameObject())
        {
            if (Input.GetButtonDown("Fire1"))
            {
                if (GridManager.GetEntityAt <Character>(selectedCell) != null)
                {
                    startCell = GridManager.GetMouseCell();
                    if (startCursorInstance != null)
                    {
                        startCursorInstance.transform.position = GridManager.GetCellPos(startCell);
                    }

                    previewPathDrawer.ClearPath();
                }
                else if (GridManager.GetEntityAt <Character>(startCell) != null)
                {
                    List <Cell> path = Pathfind.GetPathFromDijkstra(Pathfind.Dijkstra(startCell, collisionTilemap), startCell, targetCell);
                    SetPathForCell(startCell, path);
                }
            }
            if (GridManager.GetEntityAt <Character>(startCell) != null && targetCell != GridManager.GetMouseCell())
            {
                targetCell = GridManager.GetMouseCell();
                if (endCursorInstance != null)
                {
                    endCursorInstance.transform.position = GridManager.GetCellPos(targetCell);
                }
                List <Cell> path = Pathfind.GetPathFromDijkstra(Pathfind.Dijkstra(startCell, collisionTilemap), startCell, targetCell);
                previewPathDrawer.DrawPath(path);
            }
        }
    }