Ejemplo n.º 1
0
        private void GoToNextChargingStation()
        {
            var nextStation = FindNextRoombaStation();

            if (nextStation == null)
            {
                Debug.Log(gameObject.name + ": No roomba station found!");
                return;
            }

            navMeshAgent2D.destination = nextStation.transform.position - new Vector3(0.5f, 0);
            Debug.Log(gameObject.name + ": Go to station at " + navMeshAgent2D.destination);
            TargetStation = nextStation;
        }
Ejemplo n.º 2
0
        private RoombaStationBehaviour FindNextRoombaStation()
        {
            RoombaStationBehaviour choosenStation = null;
            var lowestDist = float.MaxValue;

            TilemapUtils.IterateTilemapWithAction(_doodadsForegroundTilemap, (tilemap, gx, gy, data) =>
            {
                var tile = tilemap.GetTile(gx, gy);
                if (tile?.paramContainer == null)
                {
                    return;
                }
                if (!tile.paramContainer.GetBoolParam("IsRoombaStation"))
                {
                    return;
                }


                var roombaStation = tilemap.GetTileObject(gx, gy).GetComponent <RoombaStationBehaviour>();
                if (!roombaStation.CanRoombaDockHere(this))
                {
                    return;
                }

                var gridWorldPos = TilemapUtils.GetGridWorldPos(
                    _doodadsForegroundTilemap,
                    gx,
                    gy);
                var transformPosition = transform.position.magnitude - gridWorldPos.magnitude;
                if (transformPosition < lowestDist)
                {
                    System.Console.WriteLine("gridWorldPos " + gridWorldPos);
                    System.Console.WriteLine("roombaStation " + roombaStation.transform);
                    choosenStation = roombaStation;
                    lowestDist     = transformPosition;
                }
            });

            return(choosenStation);
        }
Ejemplo n.º 3
0
 private void HandleDocking()
 {
     if (!navMeshAgent2D.hasPath && _currentCapacity <= 0)
     {
         if (TargetStation != null)
         {
             // I am at the station.
             TargetStation.StationaryRoomba = this;
             _waitingTicks    = 60 * 4;
             _currentCapacity = DefaultRoombaCapacity;
         }
         else
         {
             // Go to the station
             GoToNextChargingStation();
         }
     }
     else if (TargetStation)
     {
         TargetStation.StationaryRoomba = null;
         TargetStation = null;
     }
 }