/// <summary> /// Manually trigger a save operation for the WorldLocking state /// </summary> public void Save() { #if UNITY_WSA /// Persistence currently only supported on HoloLens WrapErrors(saveAsync()); alignmentManager.Save(); #endif // UNITY_WSA }
/// <summary> /// Manually trigger a save operation for the WorldLocking state /// </summary> public void Save() { if (shared.anchorSettings.anchorSubsystem == AnchorSettings.AnchorSubsystem.WSA) { /// Persistence currently only supported on HoloLens Legacy WrapErrors(saveAsync()); alignmentManager.Save(); } }
/// <summary> /// Save WorldLocking state in a background task /// </summary> private async Task saveAsync() { if (hasPendingLoadTask || hasPendingSaveTask) { return; } hasPendingSaveTask = true; try { // mafinc - future work might include making an incremental save, // appending deltas, rather than new file every time. if (File.Exists(stateFileNameBase + ".new")) { File.Delete(stateFileNameBase + ".new"); } await AnchorManager.SaveAnchors(); if (AnchorManager.SupportsPersistence) { alignmentManager.Save(); using (var file = File.Create(stateFileNameBase + ".new")) { using (var ps = Plugin.CreateSerializer()) { ps.IncludePersistent = true; ps.IncludeTransient = false; ps.GatherRecord(); await ps.WriteRecordToAsync(file); } } if (File.Exists(stateFileNameBase + ".old")) { File.Delete(stateFileNameBase + ".old"); } if (File.Exists(stateFileNameBase)) { File.Move(stateFileNameBase, stateFileNameBase + ".old"); } File.Move(stateFileNameBase + ".new", stateFileNameBase); lastSavingTime = Time.unscaledTime; } } finally { hasPendingSaveTask = false; } }
/// <summary> /// Manually trigger a save operation for the WorldLocking state /// </summary> public void Save() { WrapErrors(saveAsync()); alignmentManager.Save(); }
public IEnumerator SaveLoadTestSaveThenLoad() { GameObject rig = loadHelper.LoadBasicSceneRig(); WorldLockingManager wltMgr = WorldLockingManager.GetInstance(); var settings = wltMgr.Settings; settings.AutoLoad = false; settings.AutoSave = false; wltMgr.Settings = settings; IAlignmentManager alignMgr = wltMgr.AlignmentManager; alignMgr.ClearAlignmentAnchors(); alignMgr.SendAlignmentAnchors(); // Verify alignment is identity VerifyAlignmentIdentity(alignMgr, pinData); // Add pins for (int i = 0; i < pinData.Length; ++i) { pinData[i].anchorId = alignMgr.AddAlignmentAnchor(pinData[i].name, pinData[i].virtualPose, pinData[i].lockedPose); } alignMgr.SendAlignmentAnchors(); yield return(null); // Verify alignment at pins VerifyAlignment(alignMgr, pinData); // Save alignMgr.Save(); yield return(null); // Verify alignment at pins, saving should be non-destructive. VerifyAlignment(alignMgr, pinData); // Clear alignMgr.ClearAlignmentAnchors(); alignMgr.SendAlignmentAnchors(); yield return(null); // Verify alignment is identity VerifyAlignmentIdentity(alignMgr, pinData); // Load alignMgr.Load(); yield return(null); for (int i = 0; i < pinData.Length; ++i) { pinData[i].anchorId = alignMgr.RestoreAlignmentAnchor(pinData[i].name, pinData[i].virtualPose); } alignMgr.SendAlignmentAnchors(); yield return(null); // Verify alignment at pins, load should have restored them. VerifyAlignment(alignMgr, pinData); GameObject.Destroy(rig); yield return(null); }