Ejemplo n.º 1
0
        /// <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>
 /// Handler for restoring the bindings. This is called when the content binding
 /// is restored, and if this is successful, the object is rebound to the original
 /// location it was bound to when last saved.
 /// </summary>
 /// <param name="contentBinding">Content binding.</param>
 /// <param name="resultCode">Result code.</param>
 void HandleBindingRestore(MLContentBinding contentBinding, MLResult result)
 {
     if (result.IsOk)
     {
         SetProgress(string.Format(TEXT_RESTORING_OBJECT, contentBinding.GameObject.name, "succeeded"));
         contentBinding.GameObject.SetActive(true);
         Debug.LogFormat("object: {0} - {1} {2} {3} , {4} {5} {6} {7}", contentBinding.GameObject.name,
                         contentBinding.GameObject.transform.position.x,
                         contentBinding.GameObject.transform.position.y,
                         contentBinding.GameObject.transform.position.z,
                         contentBinding.GameObject.transform.rotation.x,
                         contentBinding.GameObject.transform.rotation.y,
                         contentBinding.GameObject.transform.rotation.z,
                         contentBinding.GameObject.transform.rotation.w);
     }
     else
     {
         SetProgress(string.Format(TEXT_RESTORING_OBJECT, contentBinding.GameObject.name, "failed. Trying again"));
         //Note: Currently we try endlessly to restore. However, this can lead to a loop
         //when there's fundamental problem with the underlying system. This logic can be made smarter by
         //adding retry attempts however for sake of simplicitly we are not showing it here. It is advised
         //to do it however.
         MLContentBinder.Restore(contentBinding, HandleBindingRestore);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Handler for binding restore
 /// </summary>
 /// <param name="contentBinding">Content binding.</param>
 /// <param name="resultCode">Result code.</param>
 void HandleBindingRestore(MLContentBinding contentBinding, MLResult result)
 {
     _state = State.BindingComplete;
     Debug.Log("binding result : " + contentBinding.PCF.CurrentResult);
     if (!result.IsOk)
     {
         MLPersistentStore.DeleteBinding(contentBinding);
         Debug.LogFormat("Failed to restore : {0} - {1}. Result code:", gameObject.name, contentBinding.PCF.CFUID, result.Code);
     }
 }
        /// <summary>
        /// Helper function to add new objects and binding them to closest PCFs.
        /// This function shows how youc an use the underlying systems to accomplish
        /// game object to a PCF binding
        /// </summary>
        public void StoreReferencePointAtPosition(Vector3 position)
        {
            if (!MLPersistentCoordinateFrames.IsStarted)
            {
                return;
            }

            var returnResult = MLPersistentCoordinateFrames.FindClosestPCF(position, (MLResult result, MLPCF pcf) =>
            {
                if (result.IsOk)
                {
                    Debug.LogFormat("Closest PCF found. Binding {0} to PCF {1}:", referencePointName, pcf.CFUID);

                    if (alignedBinding == null)
                    {
                        alignedBinding = MLContentBinder.BindToPCF(referencePointName, AlignedReferencePoint.instance.gameObject, pcf);
                    }
                    else
                    {
                        alignedBinding.PCF = pcf;
                        alignedBinding.Update();
                    }

                    _state = State.SaveRequired;
                    //Debug.LogFormat("object: {0} - {1} {2} {3}, {4} {5} {6} {7}",
                    //newExampleObject.GO.name,
                    //newExampleObject.GO.transform.position.x,
                    //newExampleObject.GO.transform.position.y,
                    //newExampleObject.GO.transform.position.z,
                    //newExampleObject.GO.transform.rotation.x,
                    //newExampleObject.GO.transform.rotation.y,
                    //newExampleObject.GO.transform.rotation.z,
                    //newExampleObject.GO.transform.rotation.w);
                }
                else
                {
                    SetProgress(FAILED_TO_FIND_CLOSEST_PCF + " Reason:" + result);
                }
            });

            if (!returnResult.IsOk)
            {
                SetProgress(FAILED_TO_FIND_CLOSEST_PCF + " Result Code:" + returnResult);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Handler for restoring the bindings. This is called when the content binding
 /// is restored, and if this is successful, the object is rebound to the original
 /// location it was bound to when last saved.
 /// </summary>
 /// <param name="contentBinding">Content binding.</param>
 /// <param name="resultCode">Result code.</param>
 void HandleBindingRestore(MLContentBinding contentBinding, MLResult result)
 {
     if (result.IsOk)
     {
         SetProgress(string.Format(TEXT_RESTORING_OBJECT, contentBinding.GameObject.name, "succeeded"));
         contentBinding.GameObject.SetActive(true);
         Debug.LogFormat("object: {0} - {1} {2} {3} , {4} {5} {6} {7}", contentBinding.GameObject.name,
                         contentBinding.GameObject.transform.position.x,
                         contentBinding.GameObject.transform.position.y,
                         contentBinding.GameObject.transform.position.z,
                         contentBinding.GameObject.transform.rotation.x,
                         contentBinding.GameObject.transform.rotation.y,
                         contentBinding.GameObject.transform.rotation.z,
                         contentBinding.GameObject.transform.rotation.w);
     }
     else
     {
         SetProgress(string.Format(TEXT_RESTORING_OBJECT, contentBinding.GameObject.name, "failed"));
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Finds the closest pcf for this persistent point.
        /// </summary>
        void BindToAllPCFs()
        {
            _state = State.BindToAllPCFs;
            string suffix = "";
            int    count  = 0;

            // In the loop below we try to associate the persitent point with not only
            // the closest but all pcfs in the surrounding. This will increase the probablilty
            // of restoration on reboots. It's costly in terms of disk space so we will limit it to
            // a max
            foreach (MLPCF pcf in _allPCFs)
            {
                string objectName   = gameObject.name + suffix;
                var    returnResult = MLPersistentCoordinateFrames.GetPCFPosition(pcf, (result, returnPCF) =>
                {
                    if (result.IsOk && pcf.CurrentResult == MLResultCode.Ok)
                    {
                        Debug.Log("binding to PCF: " + pcf.CFUID);

                        Binding = MLContentBinder.BindToPCF(objectName, gameObject, pcf);
                        MLPersistentStore.Save(Binding);
                    }
                    else
                    {
                        Debug.LogWarningFormat("Failed to find the position for PCF {0}", returnPCF.CFUID);
                    }
                });
                if (!returnResult.IsOk)
                {
                    Debug.LogError("Failed to GetPCF");
                    break;
                }
                suffix = "-" + count;
                count++;
            }

            _state = State.BindingComplete;
        }