Пример #1
0
        /// <summary>
        /// Tries showing all PCF.
        /// </summary>
        /// <param name="pcfList">PCF list.</param>
        void TryShowingAllPCFs(List <MLPCF> pcfList)
        {
            foreach (MLPCF pcf in pcfList)
            {
                if (pcf.CurrentResult == MLResultCode.Pending)
                {
                    MLResult result = MLPersistentCoordinateFrames.GetPCFPosition(pcf, (queryResult, pcfObj) =>
                    {
                        if (queryResult.IsOk)
                        {
                            AddPCFObject(pcfObj);
                            MLPersistentCoordinateFrames.QueueForUpdates(pcfObj);
                        }
                        else
                        {
                            Debug.LogErrorFormat("PCFVisualizer failed to get position for PCF: {0}. Reason: {1}", pcfObj, queryResult);
                        }
                    });

                    if (!result.IsOk && result.Code != MLResultCode.Pending)
                    {
                        Debug.LogErrorFormat("PCFVisualizer failed to attempt to get position for PCF: {0}. Reason: {1}", pcf, result);
                    }
                }
                else
                {
                    AddPCFObject(pcf);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Coroutine to continuously query for all PCFs and their locations in debug mode.
        /// Note: Getting all PCFs is highly inefficient and ill-advised. We are only
        /// doing this for demonstration/debug purposes. Do NOT do this on production code!
        /// </summary>
        /// <returns>IEnumerator</returns>
        IEnumerator FindAllPCFs()
        {
            while (IsDebugMode)
            {
                List <MLPCF> allPCFs;
                MLResult     result = MLPersistentCoordinateFrames.GetAllPCFs(out allPCFs);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: MLPersistentCoordinateFrames failed to get all PCFs. Reason: {0}", result);
                    yield break;
                }

                // MLPersistentCoordinateFrames.GetAllPCFs() returns the PCFs stored in the device.
                // We don't have their positions yet. In fact, we don't even know if they're in the
                // same landscape as the user is loaded into.

                _ongoingQueriesCount = allPCFs.Count;
                foreach (MLPCF pcf in allPCFs)
                {
                    result = MLPersistentCoordinateFrames.GetPCFPosition(pcf, HandlePCFPositionQuery);
                    // HandlePCFPositionQuery could execute immediately (when the requested PCF has been requested before)
                    // or later (when the PCF is completely new).
                    if (!result.IsOk)
                    {
                        Debug.LogErrorFormat("Error: MLPersistentCoordinateFrames failed to get PCF position. Reason: {0}", result);
                        yield break;
                    }

                    // When MLPersistentCoordinateFrames.GetPCFPosition() successfully gets the position of the PCF,
                    // MLPCF.OnCreate() gets triggered which will call HandleCreate()
                }

                // It is possible for _ongoingQueriesCount to be 0 at this point when no new PCFs have been found.
                // Such a case would cause an infinite loop in the current frame. The following yield statement
                // prevents the infinite loop in a single frame.
                yield return(null);

                while (_ongoingQueriesCount > 0)
                {
                    yield return(null);
                }
            }
        }
Пример #3
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;
        }
Пример #4
0
 /// <summary>
 /// Tries the showing all PCF.
 /// </summary>
 /// <param name="pcfList">Pcf list.</param>
 void TryShowingAllPCFs(List <MLPCF> pcfList)
 {
     foreach (MLPCF pcf in pcfList)
     {
         if (pcf.CurrentResult == MLResultCode.Pending)
         {
             MLPersistentCoordinateFrames.GetPCFPosition(pcf, (r, p) =>
             {
                 if (r.IsOk)
                 {
                     AddPCFObject(p);
                 }
                 else
                 {
                     SetError("failed to get position for pcf : " + p);
                 }
             });
         }
         else
         {
             AddPCFObject(pcf);
         }
     }
 }
        //Private Methods:
        private void DiscoverPCFs()
        {
            //interval:
            _interval++;
            _interval = _interval % 100;

            //if previous send queue isn't finished then interrupt it:
            StopCoroutine("SendPCFs");

            //clear lists:
            _localPCFs.Clear();
            _localPCFData.Clear();
            _localPCFReferences.Clear();
            _outboundPCFs.Clear();

            //get pcfs:
            MLPersistentCoordinateFrames.GetAllPCFs(out _localPCFs, QueryCount);

            //request poses:
            foreach (var item in _localPCFs)
            {
                MLPersistentCoordinateFrames.GetPCFPosition(item, HandlePCFPoseRetrieval);
            }
        }