/// <summary> /// Saves the current area description, returning the area description saved. /// /// You can only save an area description while connected to the Tango Service and if you have enabled Area /// Learning mode. If you loaded an ADF before connecting, then calling this method appends any new learned /// areas to that ADF and returns the same UUID. If you did not load an ADF, this method creates a new ADF and /// a new UUID for that ADF. /// </summary> /// <returns> /// AreaDescription instance for the newly saved area description if saved successfully, <c>null</c> otherwise. /// /// See logcat for details of why the saved failed. /// </returns> public static AreaDescription SaveCurrent() { byte[] rawUUID = new byte[Common.UUID_LENGTH]; if (AreaDescriptionAPI.TangoService_saveAreaDescription(rawUUID) != Common.ErrorType.TANGO_SUCCESS) { Debug.Log("Could not save area description.\n" + Environment.StackTrace); return(null); } string uuid = Encoding.UTF8.GetString(rawUUID); return(AreaDescription.ForUUID(uuid)); }
/// <summary> /// Saves the current area description, returning the area description saved. /// /// You can only save an area description while connected to the Tango Service and if you have enabled Area /// Learning mode. If you loaded an area description before connecting, then calling this method appends any /// new learned areas to that area description and returns an area description with the same UUID. If you did /// not load an area description, this method creates a new area description and a new UUID for that area /// description. /// </summary> /// <returns> /// AreaDescription instance for the newly saved area description if saved successfully, <c>null</c> otherwise. /// /// See logcat for details of why a saved failed. /// </returns> public static AreaDescription SaveCurrent() { #if UNITY_EDITOR if (!EmulatedAreaDescriptionHelper.m_usingEmulatedDescriptionFrames) { Debug.LogError("Error in Area Description save emulation:\nNo current emulated area description."); return(null); } // If we don't have an existing UUID, this is a 'new' Area Description, so we'll have to create it. if (string.IsNullOrEmpty(EmulatedAreaDescriptionHelper.m_currentUUID)) { // Just use a .net GUID for the UUID. string uuid = Guid.NewGuid().ToString(); EmulatedAreaDescriptionHelper.m_currentUUID = uuid; try { Directory.CreateDirectory(EMULATED_ADF_SAVE_PATH); using (StreamWriter streamWriter = new StreamWriter(File.Open(EMULATED_ADF_SAVE_PATH + uuid + EMULATED_ADF_EXTENSION, FileMode.Create))) { Metadata metadata = new Metadata(); metadata.m_name = "Unnamed"; metadata.m_dateTime = DateTime.Now; metadata.m_transformationPosition = new double[3]; metadata.m_transformationRotation = new double[] { 0, 0, 0, 1 }; metadataXmlSerializer.Serialize(streamWriter, metadata); } } catch (IOException ioException) { Debug.LogError("IO error in Area Description save/load emulation:\n" + ioException.Message); return(null); } return(AreaDescription.ForUUID(uuid)); } else { // Since we don't actually save any description of the area in emulation, // if we're using an existing UUID, we don't have to do anything but return it. return(AreaDescription.ForUUID(EmulatedAreaDescriptionHelper.m_currentUUID)); } #else byte[] rawUUID = new byte[Common.UUID_LENGTH]; if (AreaDescriptionAPI.TangoService_saveAreaDescription(rawUUID) != Common.ErrorType.TANGO_SUCCESS) { Debug.Log("Could not save area description.\n" + Environment.StackTrace); return(null); } // Don't want to include the null terminator in the C# string. string uuid = Encoding.UTF8.GetString(rawUUID, 0, Common.UUID_LENGTH - 1); return(AreaDescription.ForUUID(uuid)); #endif }