コード例 #1
0
 public void ChangeRoom(string newRoom, string targetDoor)
 {
     if (RoomMap.TryGetValue(newRoom, out var newRoomPrefab))
     {
         var roomToActivate = Instantiate(newRoomPrefab);
         var newDoors       = roomToActivate.GetComponentsInChildren <RoomDoor>();
         int doorToMoveTo   = -1;
         for (int i = 0; i < newDoors.Length; i++)
         {
             newDoors[i].Manager = this;
             if (newDoors[i].name.Equals(targetDoor))
             {
                 doorToMoveTo = i;
             }
         }
         if (doorToMoveTo == -1)
         {
             print("No Door Named [" + targetDoor + "] in Room {" + newRoom + "}");
             Destroy(roomToActivate);
             return;
         }
         BroadcastRoomTransition(true);
         Destroy(ActiveRoom);
         ActiveRoom  = roomToActivate;
         ActiveDoors = newDoors;
         var     DoorTransition = ActiveDoors[doorToMoveTo];
         Grid    roomGrid       = roomToActivate.GetComponent <Grid>();
         Vector3 gridSize       = roomGrid.cellSize + roomGrid.cellGap;
         var     offsetDir      = DoorTransition.GetEntryWorldOffset();
         var     offset         = new Vector3(gridSize.x * offsetDir.x, gridSize.y * offsetDir.y, 0);
         if (ActivePlayer != null)
         {
             ActivePlayer.transform.position = DoorTransition.transform.position + offset;
         }
         else
         {
             ActivePlayer = Instantiate(
                 PlayerPrefab,
                 DoorTransition.transform.position + offset,
                 Quaternion.identity
                 );
             Camera.TrackingObject = ActivePlayer;
         }
         SpawnTrasform = roomToActivate.transform.Find("Player Spawn");
         Camera.SetWorldBounds(GetBoundsOfActiveRoom());
         Camera.Track(ActivePlayer);
         ActiveRoomID = newRoom;
         SaveSystem.Savegame(this);
     }
     else
     {
         print("No Room Named {" + newRoom + "} has been mapped!");
     }
 }