/// <summary> /// Kicks off the process of creating the shared space. /// </summary> void StartAnchorProcess() { // First, are there any anchors in this room? int anchorCount = currentRoom.GetAnchorCount(); Debug.Log(anchorCount + " anchors"); // If there are anchors, we should attach to the first one. if (anchorCount > 0) { // Extract the name of the anchor. HoloToolkit.Sharing.XString storedAnchorString = currentRoom.GetAnchorName(0); string storedAnchorName = storedAnchorString.GetString(); // Attempt to attach to the anchor in our local anchor store. if (AttachToCachedAnchor(storedAnchorName) == false) { Debug.Log("Starting room download"); // If we cannot find the anchor by name, we will need the full data blob. MakeAnchorDataRequest(); } } }
/// <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); }