/// <summary>
        /// Creates a binding to the closest PCF
        /// </summary>
        /// <returns>Must be executed as a Coroutine</returns>
        IEnumerator TryBindingToClosestPCF()
        {
            _done = false;
            MLResult returnResult = MLPersistentCoordinateFrames.FindClosestPCF(gameObject.transform.position, (pcfPositionResult, pcfWithPosition) =>
            {
                if (pcfPositionResult.IsOk && pcfWithPosition != null && pcfWithPosition.CurrentResult == MLResultCode.Ok)
                {
                    Debug.Log("Binding to closest found PCF: " + pcfWithPosition.CFUID);
                    Binding = MLContentBinder.BindToPCF(UniqueId, gameObject, pcfWithPosition);
                    MLPersistentStore.Save(Binding);
                    NotifyChangeOfStatus(Status.BINDING_CREATED, MLResult.ResultOk);
                    RegisterPCFEventHandlers();
                    _done = true;
                }
                else
                {
                    Debug.LogErrorFormat("Error: MLPersistentBehavior failed to get PCF position. Reason: {0}", pcfPositionResult);
                    NotifyChangeOfStatus(Status.BINDING_CREATE_FAILED, pcfPositionResult);
                    _done = true;
                }
            });

            if (!returnResult.IsOk)
            {
                Debug.LogErrorFormat("Error: MLPersistentBehavior failed to attempt to find closest PCF. Reason: {0}", returnResult);
                NotifyChangeOfStatus(Status.BINDING_CREATE_FAILED, returnResult);
                _done = true;
            }

            while (!_done)
            {
                yield return(null);
            }
        }
        /// <summary>
        /// Handler when PCF bound to is lost. It tries to look for reliable PCF to bind to. If no PCF
        /// is available, try again later.
        /// </summary>
        void HandlePCFLost()
        {
            _searchForPCF = null;
            MLResult result = MLPersistentCoordinateFrames.FindClosestPCF(transform.position, (findResult, returnPCF) =>
            {
                if (findResult.IsOk && returnPCF != null && returnPCF.CurrentResult == MLResultCode.Ok)
                {
                    UnregisterPCFEventHandlers();

                    Debug.LogFormat("Rebinding to closest found PCF: {0}", returnPCF.CFUID);
                    Binding.PCF = returnPCF;
                    MLResult bindingUpdateResult = Binding.Update();
                    if (!bindingUpdateResult.IsOk)
                    {
                        MLPersistentStore.Save(Binding);
                    }

                    RegisterPCFEventHandlers();
                }
                else
                {
                    Debug.LogFormat("MLPersistentBehavior failed to rebind to closest PCF. Reason: {0}. Retrying in {1} seconds", findResult, RetryDelayInSeconds);
                    _searchForPCF = StartCoroutine(RetryFindPCFToRebind());
                }
            });

            if (!result.IsOk)
            {
                Debug.LogWarningFormat("Error: MLPersistentBehavior failed to attempt to find another closest PCF. Reason: {0}", result);
            }
        }
Пример #3
0
        /// <summary>
        /// Creates a binding to the closest PCF
        /// </summary>
        /// <returns>Must be executed as a Coroutine</returns>
        IEnumerator TryBindingToClosestPCF()
        {
            _done = false;

            MLResult returnResult = MLPersistentCoordinateFrames.FindClosestPCF(gameObject.transform.position, (result, returnPCF) =>
            {
                if (result.IsOk && returnPCF.CurrentResult == MLResultCode.Ok)
                {
                    Debug.Log("Binding to closest found PCF: " + returnPCF.CFUID);
                    Binding = MLContentBinder.BindToPCF(gameObject.name, gameObject, returnPCF);
                    MLPersistentStore.Save(Binding);
                    SetComplete(true);
                    _done = true;
                }
                else
                {
                    Debug.LogErrorFormat("Error: MLPersistentPoint failed to find closest PCF. Reason: {0}", result);
                    SetComplete(false);
                    _done = true;
                }
            });

            if (!returnResult.IsOk)
            {
                // Technically, if we reach this point, the system had a problem
                Debug.LogErrorFormat("Error: MLPersistentPoint failed to attempt to find closest PCF. Reason: {0}", returnResult);
                SetComplete(false);
                _done = true;
            }

            while (!_done)
            {
                yield return(null);
            }
        }
Пример #4
0
 public void UpdateBinding()
 {
     if (transform.hasChanged)
     {
         Binding.Update();
         MLPersistentStore.Save(Binding);
     }
 }
 /// <summary>
 /// Saves the binding if transform has changed
 /// </summary>
 public void UpdateBinding()
 {
     if (transform.hasChanged)
     {
         // Note: this does not change the PCF bound to
         Binding.Update();
         MLPersistentStore.Save(Binding);
         transform.hasChanged = false;
     }
 }
Пример #6
0
 /// <summary>
 /// Bind this gameObject to a pcf
 /// </summary>
 /// <param name="pcf">The pcf to bind to</param>
 void BindToPCF(MLPCF pcf)
 {
     UnregisterPCFEventHandlers();
     DestroyBinding();
     Binding = MLContentBinder.BindToPCF(UniqueId, gameObject, pcf);
     MLPersistentStore.Save(Binding);
     NotifyChangeOfStatus(Status.BINDING_CREATED, MLResult.ResultOk);
     RegisterPCFEventHandlers();
     _pcfLost = false;
 }
Пример #7
0
 /// <summary>
 /// Called externally to save its binding
 /// </summary>
 public void UpdateBinding()
 {
     if (transform.hasChanged)
     {
         // Note: this does not change the PCF bound to
         Binding.Update();
         MLPersistentStore.Save(Binding);
         transform.hasChanged = false;
         NotifyChangeOfStatus(Status.BINDING_UPDATED, MLResult.ResultOk);
     }
 }
Пример #8
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;
        }
Пример #9
0
 /// <summary>
 /// Called externally to save its binding
 /// </summary>
 public void UpdateBinding()
 {
     Binding.Update();
     MLPersistentStore.Save(Binding);
     NotifyChangeOfStatus(Status.BINDING_UPDATED, MLResult.ResultOk);
 }