/// <summary> /// Tries to restore the binding from persistent storage and PCF system /// </summary> IEnumerator RestoreBinding(string objId) { _state = State.RestoreBinding; if (MLPersistentStore.Contains(objId)) { MLContentBinding binding; MLResult result = MLPersistentStore.Load(objId, out binding); if (!result.IsOk) { SetError(result); _state = State.BindingComplete; } else { Binding = binding; Debug.Log("binding result : " + Binding.PCF.CurrentResult); Binding.GameObject = this.gameObject; MLContentBinder.Restore(Binding, HandleBindingRestore); } } else { BindToAllPCFs(); } while (_state != State.BindingComplete) { yield return(null); } yield break; }
/// <summary> /// Tries to restore the binding or find closest PCF. /// </summary> void RestoreBinding(string objId) { if (MLPersistentStore.Contains(objId)) { MLContentBinding binding; MLResult result = MLPersistentStore.Load(objId, out binding); if (!result.IsOk) { SetError(new MLResult(result.Code, string.Format("Error: MLPersistentPoint failed to load binding. Reason: {0}", result))); SetComplete(false); } else { Binding = binding; Binding.GameObject = this.gameObject; MLContentBinder.Restore(Binding, HandleBindingRestore); } } else { StartCoroutine(BindToClosestPCF()); } }
/// <summary> /// Determine and perform the appropriate action /// </summary> void CreateOrRestoreBinding() { if (MLPersistentStore.Contains(UniqueId)) { RestoreBinding(); } else { // Find closest PCF and create binding to it StartCoroutine(BindToClosestPCF()); } }
/// <summary> /// Handler when MLPersistentCoordinateFrames becomes ready /// </summary> private void HandleReady() { MLPersistentCoordinateFrames.OnReady -= HandleReady; if (MLPersistentStore.Contains(UniqueId)) { RestoreBinding(); } else { // Find closest PCF and create binding to that StartCoroutine(BindToClosestPCF()); } }