/// <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);
            }
        }
Exemple #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);
            }
        }