Пример #1
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);
            }
        }
        /// <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);
            }
        }
Пример #3
0
        /// <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());
            }
        }
Пример #4
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;
        }
Пример #5
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;
 }
        /// <summary>
        /// Tries to restore the binding
        /// </summary>
        void RestoreBinding()
        {
            MLContentBinding binding;

            MLResult result = MLPersistentStore.Load(UniqueId, out binding);

            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: MLPersistentBehavior failed to load binding. Reason: {0}", result);
                NotifyChangeOfStatus(Status.RESTORE_FAILED, result);
            }
            else
            {
                Binding            = binding;
                Binding.GameObject = this.gameObject;
                MLContentBinder.Restore(Binding, HandleBindingRestore);
            }
        }
Пример #7
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;
        }
        /// <summary>
        /// Try to restore after a delay
        /// </summary>
        /// <returns>IEnumerator for delay</returns>
        IEnumerator TryRestore()
        {
            yield return(new WaitForSeconds(RetryDelayInSeconds));

            MLContentBinder.Restore(Binding, HandleBindingRestore);
        }