/// <summary>
        /// Loads the bindings from the json file
        /// </summary>
        void LoadBindings()
        {
            _state = State.RestoreInProgress;
            foreach (var exampleObject in _exampleObjects)
            {
                SetProgress(string.Format(TEXT_RESTORING_OBJECT, exampleObject.GO.name, "started"));

                if (MLPersistentStore.Contains(exampleObject.GO.name))
                {
                    MLContentBinding binding;

                    MLResult result = MLPersistentStore.Load(exampleObject.GO.name, out binding);
                    if (!result.IsOk)
                    {
                        Debug.LogError("Failed to load binding for game object " + exampleObject.GO.name);
                    }
                    else
                    {
                        binding.GameObject    = exampleObject.GO;
                        exampleObject.Binding = binding;
                        Debug.LogFormat("Binding loaded from the store: " +
                                        "Id: {0} \n" +
                                        "PCFID: {1}\n",
                                        binding.ObjectId,
                                        binding.PCF.CFUID);
                        MLContentBinder.Restore(binding, HandleBindingRestore);
                    }
                }
                else
                {
                    SetProgress(string.Format(TEXT_RESTORING_OBJECT, exampleObject.GO.name, "failed"));
                }
            }
        }
 /// <summary>
 /// Loads the bindings from the json file
 /// </summary>
 public void LoadBindings()
 {
     _state = State.RestoreInProgress;
     if (!MLPersistentStore.IsStarted)
     {
         return;
     }
     if (MLPersistentStore.Contains(referencePointName))
     {
         MLResult result = MLPersistentStore.Load(referencePointName, out alignedBinding);
         if (!result.IsOk)
         {
             Debug.LogError("Failed to load binding for reference point");
         }
         else
         {
             AlignedReferencePoint refPoint = AlignedReferencePoint.instance;
             alignedBinding.GameObject = refPoint.gameObject;
             Debug.LogFormat("Binding loaded from the store: " +
                             "Id: {0} \n" +
                             "PCFID: {1}\n",
                             alignedBinding.ObjectId,
                             alignedBinding.PCF.CFUID);
             MLContentBinder.Restore(alignedBinding, HandleBindingRestore);
         }
     }
     else
     {
         AlignedReferencePoint.instance.ActionResetXzToTransformPosition(GlobalAppMonitor.mainCamera.transform);
         //SetProgress(string.Format(TEXT_RESTORING_OBJECT, referencePointName, "failed"));
     }
 }
        /// <summary>
        /// Tries to save the existing game object ids and also calls the persistent
        /// system save call to ensure game object to the PCF bindings are saved.
        /// </summary>
        void TrySave()
        {
            if (_state == State.SaveRequired)
            {
                _state = State.Done;
                Debug.LogFormat("Saving Objects {0}", _exampleObjects.Count);
                if (!MLPersistentStore.IsStarted)
                {
                    Debug.LogError("MLPersistentStore is not started! can't save. ");
                    return;
                }
                if (_exampleObjects.Count > 0)
                {
                    ObjIds record = new ObjIds();
                    record.Ids = new string[_exampleObjects.Count];
                    int i = 0;
                    foreach (var someObj in _exampleObjects)
                    {
                        record.Ids[i++] = someObj.GO.name;
                        //Update the binding (re-store offsets) before saving
                        someObj.Binding.Update();
                        Debug.Log("saving binding for: " + someObj.Binding.GameObject.name);
                        MLPersistentStore.Save(someObj.Binding);
                    }

                    string jsonString = JsonUtility.ToJson(record);
                    File.WriteAllText(_filePath, jsonString);
                }
                SetProgress(string.Format(TEXT_SAVE_COMPLETE, _exampleObjects.Count));
            }
        }
Пример #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>
        /// Clean up
        /// </summary>
        void OnDestroy()
        {
            foreach (MLPersistentBehavior pointBehavior in _pointBehaviors)
            {
                if (pointBehavior != null)
                {
                    RemoveContentListeners(pointBehavior);
                    Destroy(pointBehavior.gameObject);
                }
            }

            if (MLPersistentCoordinateFrames.IsStarted)
            {
                MLPersistentCoordinateFrames.Stop();
            }

            if (MLPersistentStore.IsStarted)
            {
                MLPersistentStore.Stop();
            }

            MLInput.OnControllerButtonDown              -= HandleControllerButtonDown;
            MLInput.OnControllerTouchpadGestureStart    -= HandleTouchpadGestureStart;
            MLInput.OnControllerTouchpadGestureContinue -= HandleTouchpadGestureContinue;
            MLInput.OnControllerTouchpadGestureEnd      -= HandleTouchpadGestureEnd;
            MagicLeapDevice.UnregisterOnHeadTrackingMapEvent(HandleHeadTrackingMapEvent);
        }
Пример #6
0
        ///<summary>
        /// Starts the restoration process.
        /// </summary>
        void StartRestore()
        {
            MLResult result = MLPersistentStore.Start();

            if (!result.IsOk)
            {
                SetError(result);
                enabled = false;
                return;
            }

            result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                SetError(result);
                enabled = false;
                return;
            }

            result = MLPersistentCoordinateFrames.GetAllPCFs(out _allPCFs, MaxPCFsToBindTo);
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                MLPersistentCoordinateFrames.Stop();
                SetError(result);
                enabled = false;
                return;
            }

            StartCoroutine(TryRestoreBinding());
        }
Пример #7
0
        /// <summary>
        /// Handler when touchpad gesture continues
        /// </summary>
        /// <param name="controllerId">Controller ID</param>
        /// <param name="touchpadGesture">Touchpad Gesture</param>
        private void HandleTouchpadGestureContinue(byte controllerId, MLInputControllerTouchpadGesture touchpadGesture)
        {
            if (!_controller.IsControllerValid(controllerId))
            {
                return;
            }

            if (_deleteAllInitiated)
            {
                if (touchpadGesture.Type == MLInputControllerTouchpadGestureType.RadialScroll)
                {
                    ++_deleteAllSequenceFrameCount;
                    if (_deleteAllSequenceFrameCount < _deleteAllSequenceMinFrames)
                    {
                        _statusText.text = string.Format("<color=yellow>Delete All sequence {0:P} complete.</color>",
                                                         (float)(_deleteAllSequenceFrameCount) / _deleteAllSequenceMinFrames);
                    }
                    else
                    {
                        MLPersistentStore.DeleteAll();
                        foreach (var pointBehavior in _pointBehaviors)
                        {
                            Instantiate(_destroyedContentEffect, pointBehavior.transform.position, Quaternion.identity);
                            Destroy(pointBehavior.gameObject);
                        }
                        _pointBehaviors.Clear();

                        _statusText.text    = string.Format("<color=green>Delete All complete.</color>");
                        _deleteAllInitiated = false;
                    }
                }
            }
        }
        /// <summary>
        /// Clean up
        /// </summary>
        void OnDestroy()
        {
            foreach (MLPersistentBehavior pointBehavior in _pointBehaviors)
            {
                if (pointBehavior != null)
                {
                    RemoveContentListeners(pointBehavior);
                    Destroy(pointBehavior.gameObject);
                }
            }

            if (MLPersistentCoordinateFrames.IsStarted)
            {
                MLPersistentCoordinateFrames.Stop();
            }

            if (MLPersistentStore.IsStarted)
            {
                MLPersistentStore.Stop();
            }

            if (_privilegeRequester != null)
            {
                _privilegeRequester.OnPrivilegesDone -= HandlePrivilegesDone;
            }

            MLInput.OnControllerButtonDown              -= HandleControllerButtonDown;
            MLInput.OnControllerTouchpadGestureStart    -= HandleTouchpadGestureStart;
            MLInput.OnControllerTouchpadGestureContinue -= HandleTouchpadGestureContinue;
            MLInput.OnControllerTouchpadGestureEnd      -= HandleTouchpadGestureEnd;
        }
Пример #9
0
    private void OnDestroy()
    {
        if (_findAllPCFs != null)
        {
            StopCoroutine(_findAllPCFs);
        }
        foreach (GameObject go in _pcfObjs)
        {
            if (go != null)
            {
                Destroy(go);
            }
        }

        MLPCF.OnCreate -= OnNewPCFCreated;
        if (MLPersistentStore.IsStarted)
        {
            MLPersistentStore.Stop();
        }
        if (MLPersistentCoordinateFrames.IsStarted)
        {
            MLPersistentCoordinateFrames.Stop();
        }

        if (_privilegeRequester != null)
        {
            _privilegeRequester.OnPrivilegesDone -= HandlePrivilegesDone;
        }
    }
Пример #10
0
        /// <summary>
        /// Starts the persistence systems, MLPersistentStore and MLPersistentCoordinateFrames
        /// </summary>
        IEnumerator StartPersistenceSystems()
        {
            if (!MLPersistentStore.IsStarted)
            {
                MLResult result = MLPersistentStore.Start();
                if (!result.IsOk)
                {
                    SetProgress(TEXT_FAILED_TO_START_PERSISTENT_STORE);
                    _state = State.CritialError;
                }
                else
                {
                    while (true)
                    {
                        result = MLPersistentCoordinateFrames.Start();

                        if ((MLPassableWorldResult)result.Code == MLPassableWorldResult.LowMapQuality ||
                            (MLPassableWorldResult)result.Code == MLPassableWorldResult.UnableToLocalize)
                        {
                            SetProgress(string.Format(TEXT_RETRY_PCF, result, _retryIntervalInSeconds));
                            yield return(new WaitForSeconds(_retryIntervalInSeconds));
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            OnStartPersistentSystemComplete();
        }
Пример #11
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>
        /// Responds to privilege requester result.
        /// </summary>
        /// <param name="result">MLResult of the privilege request</param>
        void HandlePrivilegesDone(MLResult result)
        {
            _privilegeRequester.OnPrivilegesDone -= HandlePrivilegesDone;
            if (!result.IsOk)
            {
                if (result.Code == MLResultCode.PrivilegeDenied)
                {
                    Instantiate(Resources.Load("PrivilegeDeniedError"));
                }

                Debug.LogErrorFormat("Error: PersistenceExample failed to get requested privileges, disabling script. Reason: {0}", result);
                _statusText.text = "<color=red>Failed to acquire necessary privileges</color>";
                enabled          = false;
                return;
            }
            _statusText.text = "Status: Starting up Systems";

            result = MLPersistentStore.Start();
            if (!result.IsOk)
            {
                if (result.Code == MLResultCode.PrivilegeDenied)
                {
                    Instantiate(Resources.Load("PrivilegeDeniedError"));
                }

                Debug.LogErrorFormat("Error: PersistenceExample failed starting MLPersistentStore, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                if (result.Code == MLResultCode.PrivilegeDenied)
                {
                    Instantiate(Resources.Load("PrivilegeDeniedError"));
                }

                MLPersistentStore.Stop();
                Debug.LogErrorFormat("Error: PersistenceExample failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            if (MLPersistentCoordinateFrames.IsReady)
            {
                PerformStartup();
            }
            else
            {
                MLPersistentCoordinateFrames.OnInitialized += HandleInitialized;
            }
        }
Пример #13
0
        /// <summary>
        /// Shuts down the systems started in Start
        /// </summary>
        void OnDestroy()
        {
            if (MLPersistentCoordinateFrames.IsStarted)
            {
                MLPersistentCoordinateFrames.Stop();
            }
            if (MLPersistentStore.IsStarted)
            {
                MLPersistentStore.Stop();
            }

            MLPrivileges.Stop();
        }
Пример #14
0
    private void Start()
    {
        pv = GetComponent <PhotonView>();
        if (pv.IsMine)
        {
            NetworkUI = PhotonNetwork.Instantiate("UISync", transform.position, transform.rotation);
            Debug.Log("NetworkUISync object is spawned");
        }
        else
        {
            NetworkUI = GameObject.FindObjectOfType <NetworkUISync>().gameObject;
        }
        _findAllPCFs = FindAllPCFs();
        if (_PCFVizPrefab == null)
        {
            Debug.LogError("PCFVisualizer Prefab is not assigned");
            return;
        }

        MLResult result = MLPersistentStore.Start();

        if (!result.IsOk)
        {
            Debug.LogErrorFormat("Error: PCFVisualizer failed starting MLPersistentStore, disabling script. Reason: {0}", result);
            enabled = false;
            return;
        }
        else
        {
            Debug.Log("Persistent store started");
        }

        result = MLPersistentCoordinateFrames.Start();
        if (!result.IsOk)
        {
            Debug.LogErrorFormat("MLPersistentCoordinateFrames failed to start. Reason {0}", result);
            return;
        }
        else
        {
            Debug.Log("MLPersistentCoordinateFrames started");
        }

        MLPCF.OnCreate += OnNewPCFCreated;
        StartCoroutine(DelayedPCFRetreival());
        if (MLInput.IsStarted == false)
        {
            MLInput.Start();
        }
        MLInput.OnControllerButtonDown += HandleControllerButtonDown;
    }
 /// <summary>
 /// Shuts down the started systems.
 /// </summary>
 void OnDestroy()
 {
     if (MLPersistentCoordinateFrames.IsStarted)
     {
         MLPersistentCoordinateFrames.Stop();
     }
     if (MLPersistentStore.IsStarted)
     {
         MLPersistentStore.Stop();
     }
     if (_privilegeRequester != null)
     {
         _privilegeRequester.OnPrivilegesDone -= HandlePrivilegesDone;
     }
 }
Пример #16
0
        /// <summary>
        /// Clean up
        /// </summary>
        void OnDestroy()
        {
            if (MLPersistentStore.IsStarted)
            {
                MLPersistentStore.Stop();
            }
            if (MLPersistentCoordinateFrames.IsStarted)
            {
                MLPersistentCoordinateFrames.Stop();
            }

            foreach (GameObject go in _pcfObjs)
            {
                Destroy(go);
            }
        }
Пример #17
0
        /// <summary>
        /// Proceeds with further start up operations if the system successfully initialized.
        /// </summary>
        void HandleInitialized(MLResult status)
        {
            MLPersistentCoordinateFrames.OnInitialized -= HandleInitialized;

            if (status.IsOk)
            {
                PerformStartup();
            }
            else
            {
                _statusText.text = string.Format("<color=red>{0}</color>", status);
                Debug.LogErrorFormat("Error: MLPersistentCoordinateFrames failed to initialize, but will try again. Reason: {0}", status);
                MLPersistentStore.Stop();
                MLPersistentCoordinateFrames.Stop();
                Invoke("StartAPIs", 3);
            }
        }
Пример #18
0
        /// <summary>
        /// Validates variables, initializes systems, and prepares to show PCFs
        /// </summary>
        void Start()
        {
            if (_prefab == null)
            {
                Debug.LogError("Error: PCFVisualizer._representativePrefab not set, disabling script.");
                enabled = false;
                return;
            }

            if (_countText == null)
            {
                Debug.LogError("Error: PCFVisualizer._countText not set, disabling script.");
                enabled = false;
                return;
            }

            MLResult result = MLPersistentStore.Start();

            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: PCFVisualizer failed starting MLPersistentStore, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                Debug.LogErrorFormat("Error: PCFVisualizer failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            if (MLPersistentCoordinateFrames.IsReady)
            {
                TryShowingAllPCFs(GetPCFList());
            }
            else
            {
                MLPersistentCoordinateFrames.OnReady += HandleReady;
            }
        }
 /// <summary>
 /// Shuts down the started systems.
 /// </summary>
 void OnDestroy()
 {
     if (MLInput.IsStarted)
     {
         MLInput.OnControllerButtonDown -= HandleButtonDown;
         MLInput.Stop();
     }
     if (MLPersistentCoordinateFrames.IsStarted)
     {
         MLPersistentCoordinateFrames.Stop();
     }
     if (MLPersistentStore.IsStarted)
     {
         MLPersistentStore.Stop();
     }
     if (_privilegeRequester != null)
     {
         _privilegeRequester.OnPrivilegesDone -= HandlePrivilegesDone;
     }
 }
        /// <summary>
        /// Tries to save the existing game object ids and also calls the persistent
        /// system save call to ensure game object to the PCF bindings are saved.
        /// </summary>
        void TrySave()
        {
            if (_state == State.SaveRequired && alignedBinding != null)
            {
                _state = State.Done;
                //Debug.LogFormat("Saving Objects {0}", _exampleObjects.Count);
                if (!MLPersistentStore.IsStarted)
                {
                    Debug.LogError("MLPersistentStore is not started! can't save. ");
                    return;
                }

                //Update the binding (re-store offsets) before saving
                alignedBinding.Update();
                Debug.Log("saving binding for: " + referencePointName);
                MLPersistentStore.Save(alignedBinding);

                SetProgress(string.Format(TEXT_SAVE_COMPLETE, 1));
            }
        }
Пример #21
0
        /// <summary>
        /// Shuts down the started systems.
        /// </summary>
        void OnDestroy()
        {
#if !UNITY_EDITOR
            if (MLInput.IsStarted)
            {
                MLInput.OnControllerButtonDown -= HandleButtonDown;
                MLInput.Stop();
            }
#endif
            if (MLPersistentCoordinateFrames.IsStarted)
            {
                MLPersistentCoordinateFrames.Stop();
            }
            if (MLPersistentStore.IsStarted)
            {
                MLPersistentStore.Stop();
            }

            MLPrivileges.Stop();
        }
Пример #22
0
        /// <summary>
        /// Attempts to start the MLPersistentStore and MLPersistentCoordinateFrames APIs
        /// </summary>
        void StartAPIs()
        {
            _statusText.text = "Status: Starting up Systems";

            MLResult result = MLPersistentStore.Start();

            if (!result.IsOk)
            {
                if (result.Code == MLResultCode.PrivilegeDenied)
                {
                    Instantiate(Resources.Load("PrivilegeDeniedError"));
                }

                Debug.LogErrorFormat("Error: PersistenceExample failed starting MLPersistentStore, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                if (result.Code == MLResultCode.PrivilegeDenied)
                {
                    Instantiate(Resources.Load("PrivilegeDeniedError"));
                }

                MLPersistentStore.Stop();
                Debug.LogErrorFormat("Error: PersistenceExample failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            if (MLPersistentCoordinateFrames.IsReady)
            {
                PerformStartup();
            }
            else
            {
                MLPersistentCoordinateFrames.OnInitialized += HandleInitialized;
            }
        }
Пример #23
0
        /// <summary>
        /// Clean up
        /// </summary>
        void OnDestroy()
        {
            StopCoroutine(_findAllPCFs);
            foreach (GameObject go in _pcfObjs)
            {
                if (go != null)
                {
                    Destroy(go);
                }
            }

            MLPCF.OnCreate -= HandleCreate;
            if (MLPersistentStore.IsStarted)
            {
                MLPersistentStore.Stop();
            }
            if (MLPersistentCoordinateFrames.IsStarted)
            {
                MLPersistentCoordinateFrames.Stop();
            }
        }
Пример #24
0
        /// <summary>
        /// Start this instance.
        /// </summary>
        void Start()
        {
            MLResult result = MLPersistentStore.Start();

            if (!result.IsOk)
            {
                SetError("Failed to start persistent store. Disabling component");
                enabled = false;
                return;
            }
            result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                SetError("Failed to start coordinate frames system. disabling component");
                enabled = false;
                return;
            }

            if (_representativePrefab == null)
            {
                SetError("Error: _representativePrefab must be set");
                enabled = false;
                return;
            }

            List <MLPCF> pcfList;

            result = MLPersistentCoordinateFrames.GetAllPCFs(out pcfList, int.MaxValue);
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                MLPersistentCoordinateFrames.Stop();
                SetError(result.ToString());
                enabled = false;
                return;
            }

            TryShowingAllPCFs(pcfList);
        }
        /// <summary>
        /// Validates variables, initializes systems, and prepares to show PCFs
        /// </summary>
        void Start()
        {
            if (_prefab == null)
            {
                Debug.LogError("Error: PCFVisualizer._representativePrefab is not set, disabling script.");
                enabled = false;
                return;
            }

            if (_goodPCFCountText == null)
            {
                Debug.LogError("Error: PCFVisualizer._goodPCFCountText is not set, disabling script.");
                enabled = false;
                return;
            }
            _goodPCFCountText.text = "PCFs Loaded: 0";
            _goodPCFCountText.gameObject.SetActive(false);

            MLResult result = MLPersistentStore.Start();

            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: PCFVisualizer failed starting MLPersistentStore, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                Debug.LogErrorFormat("Error: PCFVisualizer failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            MLPCF.OnCreate += HandleCreate;
            _findAllPCFs    = FindAllPCFs();
        }
Пример #26
0
        /// <summary>
        /// Responds to privilege requester result.
        /// </summary>
        /// <param name="result"/>
        void HandlePrivilegesDone(MLResult result)
        {
            _privilegeRequester.OnPrivilegesDone -= HandlePrivilegesDone;
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: PersistenceExample failed to get requested privileges, disabling script. Reason: {0}", result);
                _statusText.text = "<color=red>Failed to acquire necessary privileges</color>";
                enabled          = false;
                return;
            }
            _statusText.text = "Status: Starting up Systems";

            result = MLPersistentStore.Start();
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: PersistenceExample failed starting MLPersistentStore, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                Debug.LogErrorFormat("Error: PersistenceExample failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            if (MLPersistentCoordinateFrames.IsReady)
            {
                HandleReady();
            }
            else
            {
                MLPersistentCoordinateFrames.OnReady += HandleReady;
            }
        }
Пример #27
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;
        }
Пример #28
0
        /// <summary>
        /// Responds to privilege requester result.
        /// </summary>
        /// <param name="result"/>
        void HandlePrivilegesDone(MLResult result)
        {
            _privilegeRequester.OnPrivilegesDone -= HandlePrivilegesDone;
            if (!result.IsOk)
            {
                string errorMsg = string.Format("Error: PersistenceExample failed to get requested privileges, disabling script. Reason: {0}", result);
                Debug.LogErrorFormat(errorMsg);
                SetProgress(errorMsg);
                enabled = false;
                return;
            }

            result = MLPersistentStore.Start();
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: PersistenceExample failed starting MLPersistentStore, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                Debug.LogErrorFormat("Error: PersistenceExample failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            if (MLPersistentCoordinateFrames.IsReady)
            {
                HandleReady();
            }
            else
            {
                MLPersistentCoordinateFrames.OnReady += HandleReady;
            }
        }
Пример #29
0
    void HandlePrivilegesDone(MLResult result)
    {
        PrivilegeRequester.OnPrivilegesDone -= HandlePrivilegesDone;
        if (!result.IsOk)
        {
            Debug.LogErrorFormat("Error: PersistentCoordinates failed to get requested privileges, " +
                                 "disabling script. Reason: {0}", result);
            enabled = false;
            return;
        }

        result = MLPersistentStore.Start();
        if (!result.IsOk)
        {
            Debug.LogErrorFormat("Error: PersistentCoordinates failed starting MLPersistentStore, disabling script. Reason: {0}", result);
            enabled = false;
            return;
        }

        result = MLPersistentCoordinateFrames.Start();
        if (!result.IsOk)
        {
            MLPersistentStore.Stop();
            Debug.LogErrorFormat("Error: PersistentCoordinates failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result);
            enabled = false;
            return;
        }

        if (MLPersistentCoordinateFrames.IsReady)
        {
            Inititalize();
        }
        else
        {
            MLPersistentCoordinateFrames.OnInitialized += OnPcfInitialized;
        }
    }
Пример #30
0
        /// <summary>
        /// Clean up
        /// </summary>
        void OnDestroy()
        {
            foreach (MLPersistentPoint point in _persistentPoints)
            {
                if (point != null)
                {
                    Destroy(point.gameObject);
                }
            }
            MLInput.OnControllerButtonDown -= HandleButtonDown;

            if (MLPersistentCoordinateFrames.IsStarted)
            {
                MLPersistentCoordinateFrames.Stop();
            }
            if (MLPersistentStore.IsStarted)
            {
                MLPersistentStore.Stop();
            }
            if (_privilegeRequester != null)
            {
                _privilegeRequester.OnPrivilegesDone -= HandlePrivilegesDone;
            }
        }