/// <summary> /// Starts up MLPersistentCoordinateFrames and registers to events. /// Defaults to visualizing pcfs (will contiously find and queue PCFs for updates). /// </summary> void Start() { #if PLATFORM_LUMIN MLResult result = MLPersistentCoordinateFrames.Start(); if (!result.IsOk) { Debug.LogErrorFormat("Error: PCFVisualizer failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result); enabled = false; return; } MLPersistentCoordinateFrames.PCF.OnStatusChange += HandlePCFStatusChange; MLPersistentCoordinateFrames.OnLocalized += HandleOnLocalized; IsVisualizing = true; #endif }
//Init: private void Awake() { //refs: _mainCamera = Camera.main.transform; //offset helper: _transformHelper = new GameObject("(TransformHelper)").transform; _transformHelper.gameObject.hideFlags = HideFlags.HideInHierarchy; //start systems: MLPersistentCoordinateFrames.Start(); StartCoroutine("PCFDiscovery"); //hooks: Transmission.Instance.events.OnPCF.AddListener(HandlePCFReceived); Transmission.Instance.events.OnSpatialAlignment.AddListener(HandleSpatialAlignmentNotification); }
/// <summary> /// Instantiates a new object with MLPCFPersistentContent. The MLPCFPersistentContent is /// responsible for restoring and saving itself. /// </summary> /// <param name="position">Position to spawn the content at.</param> /// <param name="rotation">Rotation to spawn the content at.</param> private void CreateContent(Vector3 position, Quaternion rotation) { GameObject gameObj = Instantiate(_content, position, rotation); #if PLATFORM_LUMIN MLPersistentCoordinateFrames.FindClosestPCF(position, (MLResult.Code resultCode, MLPersistentCoordinateFrames.PCF pcf) => { PersistentBall persistentContent = gameObj.GetComponent <PersistentBall>(); persistentContent.BallTransformBinding = new TransformBinding(gameObj.GetInstanceID().ToString(), "Ball"); persistentContent.BallTransformBinding.Bind(pcf, gameObj.transform); ContentTap contentTap = persistentContent.GetComponent <ContentTap>(); contentTap.OnContentTap += OnContentDestroy; ++numPersistentContentCreated; _persistentContentMap.Add(persistentContent, "Created"); }); #endif }
//Coroutines: private IEnumerator PCFDiscovery() { //query until we get PCFs: while (_localPCFs.Count == 0) { MLPersistentCoordinateFrames.FindAllPCFs(out _localPCFs, QueryCount); yield return(null); } while (true) { DiscoverPCFs(); yield return(new WaitForSeconds(QueryInterval)); yield return(null); } }
//Deinit: private void OnDestroy() { if (MLPersistentCoordinateFrames.IsStarted) { MLPersistentCoordinateFrames.Stop(); } if (MLPlanes.IsStarted) { MLPlanes.Stop(); } if (MLInput.IsStarted) { MLInput.Stop(); } }
/// <summary> /// Clean up /// </summary> void OnDestroy() { foreach (GameObject go in _pcfObjs) { Destroy(go); } if (MLPersistentStore.IsStarted) { MLPersistentStore.Stop(); } if (MLPersistentCoordinateFrames.IsStarted) { MLPersistentCoordinateFrames.Stop(); MLPersistentCoordinateFrames.OnReady -= HandleReady; } }
/// <summary> /// Helper function to add new objects and binding them to closest PCFs. /// This function shows how youc an use the underlying systems to accomplish /// game object to a PCF binding /// </summary> public void StoreReferencePointAtPosition(Vector3 position) { if (!MLPersistentCoordinateFrames.IsStarted) { return; } var returnResult = MLPersistentCoordinateFrames.FindClosestPCF(position, (MLResult result, MLPCF pcf) => { if (result.IsOk) { Debug.LogFormat("Closest PCF found. Binding {0} to PCF {1}:", referencePointName, pcf.CFUID); if (alignedBinding == null) { alignedBinding = MLContentBinder.BindToPCF(referencePointName, AlignedReferencePoint.instance.gameObject, pcf); } else { alignedBinding.PCF = pcf; alignedBinding.Update(); } _state = State.SaveRequired; //Debug.LogFormat("object: {0} - {1} {2} {3}, {4} {5} {6} {7}", //newExampleObject.GO.name, //newExampleObject.GO.transform.position.x, //newExampleObject.GO.transform.position.y, //newExampleObject.GO.transform.position.z, //newExampleObject.GO.transform.rotation.x, //newExampleObject.GO.transform.rotation.y, //newExampleObject.GO.transform.rotation.z, //newExampleObject.GO.transform.rotation.w); } else { SetProgress(FAILED_TO_FIND_CLOSEST_PCF + " Reason:" + result); } }); if (!returnResult.IsOk) { SetProgress(FAILED_TO_FIND_CLOSEST_PCF + " Result Code:" + returnResult); } }
private void HandleClosestPCFQuery(MLResult result, MLPCF pcf) { if (result.IsOk) { MLPersistentCoordinateFrames.QueueForUpdates(pcf); _closestPCF = pcf; _closestPCFGameObject = new GameObject(); _closestPCFGameObject.transform.position = _closestPCF.Position; _closestPCFGameObject.transform.rotation = _closestPCF.Orientation; Debug.Log("Found closest PCF " + _closestPCF.Position + " " + _closestPCF.CFUID); NetworkUI.GetComponent <NetworkUISync>().closestPCFGameobject = _closestPCFGameObject; if (PhotonNetwork.IsMasterClient) { pv.RPC("SyncClosestPCF", RpcTarget.OthersBuffered, _closestPCF.CFUID); } } }
public void SyncClosestPCF(CFUID id) { _closestPCFCFUID = id; Debug.Log("Trying to sync " + _closestPCFCFUID + " " + _closestPCFCFUID.ToGuid()); if (_closestPCFCFUID == null) { Debug.Log("Closest PCFID is null"); } if (_closestPCFGameObject != null) { return; } Debug.Log("List Size " + PCFList.Count); _closestPCF = PCFList.Find(x => x.CFUID == _closestPCFCFUID); MLPersistentCoordinateFrames.GetPCFPose(_closestPCF, HandleClosestPCFQuery); }
private IEnumerator Restore_Relocalize(string pcfCFUID) { MagicLeapNativeBindings.MLCoordinateFrameUID cfuid = SerializationUtilities.StringToCFUID(pcfCFUID); while (true) { MLPersistentCoordinateFrames.FindPCFByCFUID(cfuid, out pcfAnchor); if (pcfAnchor == null) { //we didn't find the pcf we needed this time: _restoreAttempt++; if (_restoreAttempt < _maxRestoreAttempts) { //retry: Debug.Log($"Previous PCF not located. Trying again. Attempt: {_restoreAttempt}/{_maxRestoreAttempts}"); yield return(new WaitForSeconds(_restoreRetryDelay)); } else { //failed: Debug.Log($"Failed to locate PCF attempt: {_restoreAttempt}/{_maxRestoreAttempts}. Creating new Playspace."); ChangeState(State.FindPCF); yield break; } yield return(null); } else { //deserialize meshes: string[] meshData = PlayerPrefs.GetString(_sessionMeshKey).Split('|'); Vector3[] wallVerts = SerializationUtilities.Deserialize <Vector3[]>(meshData[0]); int[] wallTris = SerializationUtilities.Deserialize <int[]>(meshData[1]); Vector3[] floorVerts = SerializationUtilities.Deserialize <Vector3[]>(meshData[2]); int[] floorTris = SerializationUtilities.Deserialize <int[]>(meshData[3]); Vector3[] ceilingVerts = SerializationUtilities.Deserialize <Vector3[]>(meshData[4]); BuildGeometry(wallVerts, wallTris, floorVerts, floorTris, ceilingVerts); ChangeState(State.ConfirmAreaReload); yield break; } } }
/// <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> /// 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); } } }
private IEnumerator LocalizeToSharedPCF() { _cfuid = SerializationUtilities.StringToCFUID(Transmission.GetGlobalString(_sharedPCFKey)); //find shared pcf: while (_sharedPCF == null) { //locate: MLPersistentCoordinateFrames.FindPCFByCFUID(_cfuid, out _sharedPCF); //keep looking: yield return(new WaitForSeconds(_pcfSearchTimeout)); } //we have our shared pcf! Reorient(); Localized = true; OnLocalized?.Invoke(); }
/// <summary> /// Starts APIs, registers to MLInput events, and restores content. /// </summary> void Start() { #if PLATFORM_LUMIN MLResult result = MLPersistentCoordinateFrames.Start(); if (!result.IsOk) { Debug.LogErrorFormat("Error: PCFExample failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result); enabled = false; return; } PCFVisualizer.OnFindAllPCFs += HandleOnFindAllPCFs; MLPersistentCoordinateFrames.OnLocalized += HandleOnLocalized; MLInput.OnControllerButtonDown += HandleControllerButtonDown; MLInput.OnControllerTouchpadGestureStart += HandleTouchpadGestureStart; MLInput.OnControllerTouchpadGestureContinue += HandleTouchpadGestureContinue; MLInput.OnControllerTouchpadGestureEnd += HandleTouchpadGestureEnd; #endif }
private static void OnPCFFoundHandler(MLPCF PCF) { if (PCFs.Contains(PCF)) { return; } MLPersistentCoordinateFrames.QueueForUpdates(PCF); // this doesn't work as spected for now MLUTrackedPCF trackedPCF = MLUTrackedPCF.CreateTrackedPCF(PCF); trackedPCF.InactiveOnLost = disableTrackedPCFsOnLost; PCFs.Add(PCF); trackedPCFs.Add(trackedPCF); if (OnTrackedPCFCreate != null) { OnTrackedPCFCreate(trackedPCF); } Debug.Log("MLULandscape: started tracking PCF [CFUID: " + PCF.CFUID + " | result: " + PCF.CurrentResult + "]"); }
#pragma warning restore 414 /// <summary> /// Starts the MLPersistentCoordinateFrames api and initializes bindings. /// </summary> void Start() { #if PLATFORM_LUMIN MLResult result = MLPersistentCoordinateFrames.Start(); if (!result.IsOk) { Debug.LogErrorFormat("Error: PCFVisual failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result); enabled = false; return; } MLPersistentCoordinateFrames.FindClosestPCF(transform.position, out MLPersistentCoordinateFrames.PCF pcf); _visualTransformBinding = new TransformBinding(isPersistent: false); _visualTransformBinding.Bind(pcf, transform); _visualTextBinding = new TextMeshBinding(); _visualTextBinding.Bind(pcf, _statusText); #endif }
/// <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> /// 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(); }
/// <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; } }
/// <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(); } }
/// <summary> /// Helper function to add new objects and binding them to closest PCFs. /// This function shows how youc an use the underlying systems to accomplish /// game object to a PCF binding /// </summary> void CreateObject() { Vector3 position = new Vector3(UnityEngine.Random.Range(-1.5f, 1.5f), UnityEngine.Random.Range(-1.5f, 1.5f), UnityEngine.Random.Range(1.5f, 5.0f)); ExampleObject newExampleObject = new ExampleObject(); newExampleObject.GO = Instantiate(_goPrefab, position, UnityEngine.Random.rotation); newExampleObject.GO.name = Guid.NewGuid().ToString(); _exampleObjects.Add(newExampleObject); var returnResult = MLPersistentCoordinateFrames.FindClosestPCF(position, (MLResult result, MLPCF pcf) => { if (result.IsOk) { Debug.LogFormat("Closest PCF found. Binding {0} to PCF {1}:", newExampleObject.GO.name, pcf.CFUID); newExampleObject.Binding = MLContentBinder.BindToPCF(newExampleObject.GO.name, newExampleObject.GO, pcf); _state = State.SaveRequired; Debug.LogFormat("object: {0} - {1} {2} {3}, {4} {5} {6} {7}", newExampleObject.GO.name, newExampleObject.GO.transform.position.x, newExampleObject.GO.transform.position.y, newExampleObject.GO.transform.position.z, newExampleObject.GO.transform.rotation.x, newExampleObject.GO.transform.rotation.y, newExampleObject.GO.transform.rotation.z, newExampleObject.GO.transform.rotation.w); } else { RemoveObject(newExampleObject); SetProgress(FAILED_TO_FIND_CLOSEST_PCF + " Reason:" + result); } }); if (!returnResult.IsOk) { RemoveObject(newExampleObject); SetProgress(FAILED_TO_FIND_CLOSEST_PCF + " Result Code:" + returnResult); } }
/// <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> /// Reads all stored persistent bindings. /// Each stored binding will contain a PCF object with a CFUID. /// Use that stored CFUID to see if the PCF exists in this session, if it does then the stored binding can be regained. /// If the binding is regained correctly then the persistent content will retain it's pose from the last known launch. /// </summary> private void RegainAllStoredBindings() { #if PLATFORM_LUMIN TransformBinding.storage.LoadFromFile(); List <TransformBinding> allBindings = TransformBinding.storage.Bindings; List <TransformBinding> deleteBindings = new List <TransformBinding>(); foreach (TransformBinding storedBinding in allBindings) { // Try to find the PCF with the stored CFUID. MLResult result = MLPersistentCoordinateFrames.FindPCFByCFUID(storedBinding.PCF.CFUID, (MLResult.Code resultCode, MLPersistentCoordinateFrames.PCF pcf) => { if (pcf != null && MLResult.IsOK(pcf.CurrentResultCode)) { GameObject gameObj = Instantiate(_content, Vector3.zero, Quaternion.identity); PersistentBall persistentContent = gameObj.GetComponent <PersistentBall>(); persistentContent.BallTransformBinding = storedBinding; persistentContent.BallTransformBinding.Bind(pcf, gameObj.transform, true); ContentTap contentTap = persistentContent.GetComponent <ContentTap>(); contentTap.OnContentTap += OnContentDestroy; ++numPersistentContentRegained; _persistentContentMap.Add(persistentContent, "Regained"); } else { deleteBindings.Add(storedBinding); } }); } foreach (TransformBinding storedBinding in deleteBindings) { storedBinding.UnBind(); } bindingsLoaded = true; #endif }
//Init: private IEnumerator Start() { HideGUI(); //refs: _camera = Camera.main.transform; //sets: _cachedPrimaryWallGUIScale = selectPrimaryWallGUI.transform.localScale; //features: MLPersistentCoordinateFrames.Start(); MLPlanes.Start(); MLInput.Start(); //wait for service startup: Debug.Log("Waiting for PersistentCoordinateFrames service to localize..."); while (!MLPersistentCoordinateFrames.IsLocalized) { yield return(null); } Debug.Log("PersistentCoordinateFrames service localized!"); //hooks: MLPersistentCoordinateFrames.OnLocalized += HandleOnLocalized; MLPersistentCoordinateFrames.PCF.OnStatusChange += HandlePCFChanged; //requirements: _surfaceDetails = FindObjectOfType <SurfaceDetails>(); if (_surfaceDetails == null) { _surfaceDetails = gameObject.AddComponent <SurfaceDetails>(); } if (runAtStart) { Create(); } }
/// <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(); }
/// <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> /// 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; } }
/// <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; } }
/// <summary> /// Every _secondsToRequeue, this coroutine will attempt to find all pcfs and queue them all for updates. /// </summary> private IEnumerator ContinuouslyFindAllPCFs() { // Uses a while loop so that we can catch PCFs being created during runtime. while (true) { yield return(new WaitForEndOfFrame()); if (IsVisualizing) { #if PLATFORM_LUMIN // MLPersistentCoordinateFrames.FindAllPCFs() returns the PCFs found in the current map. // Calling this function is expensive and is only called repeatedly for demonstration purposes. // This function will create new pcfs during a new headpose session. MLPersistentCoordinateFrames.FindAllPCFs((MLResult.Code resultCode, List <MLPersistentCoordinateFrames.PCF> allPCFs) => { if (!MLResult.IsOK(resultCode)) { if (resultCode == MLResult.Code.PassableWorldLowMapQuality || resultCode == MLResult.Code.PassableWorldUnableToLocalize) { Debug.LogWarningFormat("Map quality not sufficient enough for PCFVisualizer to find all pcfs. Reason: {0}", MLResult.CodeToString(resultCode)); } else { Debug.LogErrorFormat("Error: PCFVisualizer failed to find all PCFs because MLPersistentCoordinateFrames failed to get all PCFs. Reason: {0}", MLResult.CodeToString(resultCode)); } } else { OnFindAllPCFs?.Invoke(allPCFs); } }); #endif yield return(new WaitForSeconds(_secondsToRequeue)); } } }
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; } }