Advertisement
Guest User

My OnRoomListUpdate functions

a guest
Feb 4th, 2019
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. public override void OnRoomListUpdate(List<RoomInfo> roomList)
  2. {
  3. Debug.Log("roomList updating, number of lobbies found: " + roomList.Count);
  4. //This is done for debugging reasons
  5. foreach (RoomInfo room in roomList)
  6. {
  7. if (room.IsOpen)
  8. {
  9. Debug.Log("room is open");
  10. }
  11. else if (room.RemovedFromList || !room.IsOpen || !room.IsVisible)
  12. {
  13. Debug.Log("Room has been removed from list");
  14. }
  15. }
  16. //UpdateRoomList(roomList);
  17. MatchMakingManager m = MatchMakingManager.singleton;
  18. m.AddMatches(roomList);
  19. }
  20.  
  21. public void AddMatches(List<RoomInfo> rooms)
  22. {
  23. SetDirtyRooms();
  24.  
  25. foreach (RoomInfo room in rooms)
  26. {
  27. RoomButton createdRoom = GetRoomFromDict(room.Name);
  28. Debug.Log(createdRoom);
  29. if (createdRoom == null)
  30. {
  31. Debug.Log("New match found");
  32. AddMatch(room);
  33. }
  34. else
  35. {
  36. Debug.Log("Match is still there");
  37. createdRoom.isValid = true;
  38. }
  39. }
  40.  
  41. ClearNonValidRooms();
  42. }
  43.  
  44. private void SetDirtyRooms()
  45. {
  46. List<RoomButton> allRooms = new List<RoomButton>();
  47. allRooms.AddRange(roomsDict.Values);
  48.  
  49. foreach (RoomButton r in allRooms)
  50. {
  51.  
  52. r.isValid = false;
  53. Debug.Log(r.roomInfo.Name + " has been set to: " + r.isValid);
  54. }
  55. }
  56.  
  57. public void AddMatch(RoomInfo roomInfo)
  58. {
  59. GameObject go = Instantiate(matchPrefab);
  60. go.transform.SetParent(matchesParent);
  61.  
  62. MatchSpawnPosition p = GetSpawnPos();
  63.  
  64. p.isUsed = true;
  65. go.transform.position = p.pos.position;
  66. go.transform.localScale = Vector3.one;
  67.  
  68. RoomButton roomButton = go.GetComponent<RoomButton>();
  69. roomButton.roomInfo = roomInfo;
  70. roomButton.isRoomCreated = true;
  71. roomButton.isValid = true;
  72.  
  73. roomButton.room = ScriptableObject.CreateInstance<Room>();
  74.  
  75. object sceneObj = null;
  76. roomInfo.CustomProperties.TryGetValue("scene", out sceneObj);
  77. string sceneName = (string)sceneObj;
  78.  
  79. roomButton.room.sceneName = sceneName;
  80. roomButton.room.roomName = roomInfo.Name;
  81.  
  82.  
  83. roomsDict.Add(roomInfo.Name, roomButton);
  84. }
  85.  
  86.  
  87. private void ClearNonValidRooms()
  88. {
  89. List<RoomButton> allRooms = new List<RoomButton>();
  90. allRooms.AddRange(roomsDict.Values);
  91.  
  92. foreach (RoomButton r in allRooms)
  93. {
  94. if (!r.isValid)
  95. {
  96. Debug.Log(r.roomInfo.Name + " is not valid");
  97. roomsDict.Remove(r.roomInfo.Name);
  98. Destroy(r.gameObject);
  99. }
  100.  
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement