/// <summary> /// Initializes the room api. /// </summary> void InitRoomApi() { // If we have a room, we'll join the first room we see. // If we are the user with the lowest user ID, we will create the room. // Otherwise we will wait for the room to be created. if (roomManager.GetRoomCount() == 0) { if (LocalUserHasLowestUserId() && Time.frameCount > 1500) { Debug.Log("Creating room "); // Keep the room open even when all users have left the shared session. // This will allow us to persist an anchor in the same room on the sharing service. currentRoom = roomManager.CreateRoom(new HoloToolkit.Sharing.XString("DefaultRoom"), roomID, true); CurrentState = ImportExportState.InitialAnchorRequired; } } else { Debug.Log("Joining room "); currentRoom = roomManager.GetRoom(0); roomManager.JoinRoom(currentRoom); CurrentState = ImportExportState.RoomApiInitialized; } if (currentRoom != null) { Debug.Log("In room :" + roomManager.GetCurrentRoom().GetName().GetString()); } }
/// <summary> /// Initializes the room api. /// </summary> private void InitRoomApi() { // First check if there is a current room currentRoom = roomManager.GetCurrentRoom(); if (currentRoom == null) { // If we have a room, we'll join the first room we see. // If we are the user with the lowest user ID, we will create the room. // Otherwise we will wait for the room to be created. if (roomManager.GetRoomCount() == 0) { if (ShouldLocalUserCreateRoom()) { Debug.Log("Creating room " + RoomName); // To keep anchors alive even if all users have left the session ... // Pass in true instead of false in CreateRoom. currentRoom = roomManager.CreateRoom(new XString(RoomName), roomID, KeepRoomAlive); } } else { // Look through the existing rooms and join the one that matches the room name provided. int roomCount = roomManager.GetRoomCount(); for (int i = 0; i < roomCount; i++) { Room room = roomManager.GetRoom(i); if (room.GetName().GetString().Equals(RoomName, StringComparison.OrdinalIgnoreCase)) { currentRoom = room; roomManager.JoinRoom(currentRoom); Debug.Log("Joining room " + room.GetName().GetString()); break; } } if (currentRoom == null) { // Couldn't locate a matching room, just join the first one. currentRoom = roomManager.GetRoom(0); roomManager.JoinRoom(currentRoom); RoomName = currentRoom.GetName().GetString(); } currentState = ImportExportState.RoomApiInitialized; } } if (currentRoom.GetAnchorCount() == 0) { // If the room has no anchors, request the initial anchor currentState = ImportExportState.InitialAnchorRequired; } else { // Room already has anchors currentState = ImportExportState.RoomApiInitialized; } if (currentRoom != null) { Debug.LogFormat("In room : {0} with ID {1} and state {2}", roomManager.GetCurrentRoom().GetName().GetString(), roomManager.GetCurrentRoom().GetID(), currentState); } }
/// <summary> /// Initializes the room api. /// </summary> private IEnumerator InitRoomApi() { currentState = ImportExportState.RoomApiInitializing; // First check if there is a current room currentRoom = roomManager.GetCurrentRoom(); while (currentRoom == null) { // If we have a room, we'll join the first room we see. // If we are the user with the lowest user ID, we will create the room. // Otherwise we will wait for the room to be created. yield return(new WaitForEndOfFrame()); if (roomManager.GetRoomCount() == 0) { // Put the master/slave checker here if (ShouldLocalUserCreateRoom) { if (SharingStage.Instance.ShowDetailedLogs) { Debug.Log("Anchor Manager: Creating room " + RoomName); } if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nCreating room " + RoomName); } // To keep anchors alive even if all users have left the session ... // Pass in true instead of false in CreateRoom. currentRoom = roomManager.CreateRoom(new XString(RoomName), roomID, KeepRoomAlive); } } else { // Look through the existing rooms and join the one that matches the room name provided. int roomCount = roomManager.GetRoomCount(); for (int i = 0; i < roomCount; i++) { Room room = roomManager.GetRoom(i); if (room.GetName().GetString().Equals(RoomName, StringComparison.OrdinalIgnoreCase)) { currentRoom = room; roomManager.JoinRoom(currentRoom); if (SharingStage.Instance.ShowDetailedLogs) { Debug.Log("Anchor Manager: Joining room " + room.GetName().GetString()); } if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nJoining room " + room.GetName().GetString()); } break; } } if (currentRoom == null) { // Couldn't locate a matching room, just join the first one. currentRoom = roomManager.GetRoom(0); roomManager.JoinRoom(currentRoom); RoomName = currentRoom.GetName().GetString(); } currentState = ImportExportState.RoomApiInitialized; } yield return(new WaitForEndOfFrame()); } if (currentRoom.GetAnchorCount() == 0) { #if UNITY_WSA && !UNITY_EDITOR // If the room has no anchors, request the initial anchor currentState = ImportExportState.InitialAnchorRequired; #else currentState = ImportExportState.RoomApiInitialized; #endif } else { // Room already has anchors currentState = ImportExportState.RoomApiInitialized; } if (SharingStage.Instance.ShowDetailedLogs) { Debug.LogFormat("Anchor Manager: In room {0} with ID {1}", roomManager.GetCurrentRoom().GetName().GetString(), roomManager.GetCurrentRoom().GetID().ToString()); } if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nIn room {0} with ID {1}", roomManager.GetCurrentRoom().GetName().GetString(), roomManager.GetCurrentRoom().GetID().ToString()); } yield return(null); }