/// <summary> /// Tries to restore the binding or find closest PCF. Note various errors /// can be shown during this step based on the state of the low level systems. /// </summary> void Start() { SetChildrenActive(false); _lockedTransform = gameObject.transform; if (string.IsNullOrEmpty(UniqueId)) { Debug.LogWarning("Unique Id is empty will try to use game object's name. It's good to provide a unique id for virtual objects to avoid weird behavior."); if (string.IsNullOrEmpty(gameObject.name)) { SetError(new MLResult(MLResultCode.UnspecifiedFailure, "Either UniqueId or name should be non empty. Disabling component")); enabled = false; return; } UniqueId = gameObject.name; } else { gameObject.name = UniqueId; } MLResult result = MLPrivileges.Start(); if (result.IsOk) { RequestPrivilege(); } else { Debug.LogError("Privilege Error: failed to startup"); enabled = false; return; } }
/// <summary> /// If the Privileges API is running, stop it. /// </summary> void OnDestroy() { if (MLPrivileges.IsStarted) { MLPrivileges.Stop(); } }
/// <summary> /// Request privileges. /// </summary> /// <param name="privileges">An array of privileges to request.</param> public static MLResult RequestPrivileges(params MLPrivileges.Id[] privileges) { #if PLATFORM_LUMIN if (MLPrivileges.IsStarted) { foreach (MLPrivileges.Id privilege in privileges) { _result = CheckPrivilege(privilege); if (_result.Result == MLResult.Code.PrivilegeGranted) { continue; } _result = MLPrivileges.RequestPrivilege(privilege); if (_result.Result != MLResult.Code.PrivilegeGranted) { return(_result); } } } else { Debug.LogError("Error: MLPrivilegesStarterKit.RequestPrivileges failed because MLPrivileges was not started."); _result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPrivileges was not started"); } #endif return(_result); }
private static void CheckAndRequestPrivilege(MLPrivileges.Id privilegeId) { if (MLPrivileges.CheckPrivilege(privilegeId) == MLResult.Code.PrivilegeNotGranted) { Debug.LogError(MLResult.Code.PrivilegeNotGranted + ": " + privilegeId); MLPrivileges.RequestPrivilege(privilegeId); } }
/// <summary> /// Request privileges asynchronously. /// </summary> ////<param name="callback">The method to call back once a result is known. It will be called when all privileges are granted or if requesting all privileges fails.</param> /// <param name="privileges">An array of privileges to request.</param> public static MLResult RequestPrivilegesAsync(Action <MLResult> callback, params MLPrivileges.Id[] privileges) { #if PLATFORM_LUMIN int numPrivilegesToRequest = privileges.Length; for (int i = 0; i < privileges.Length; i++) { MLPrivileges.Id privilege = privileges[i]; _result = CheckPrivilege(privilege); if (_result.Result == MLResult.Code.PrivilegeGranted) { numPrivilegesToRequest--; if (numPrivilegesToRequest == 0) { callback?.Invoke(_result); } continue; } _result = MLPrivileges.RequestPrivilegeAsync(privilege, (MLResult result, MLPrivileges.Id priv) => { numPrivilegesToRequest--; if (result.Result == MLResult.Code.PrivilegeGranted) { if (numPrivilegesToRequest == 0) { callback?.Invoke(result); } } // Privilege was not granted else { numPrivilegesToRequest = 0; if (numPrivilegesToRequest == 0) { callback?.Invoke(result); } } }); if (!_result.IsOk) { return(_result); } } // Override result in case privilege was already granted. if (_result.Result == MLResult.Code.PrivilegeGranted) { _result = MLResult.Create(MLResult.Code.Ok); } #endif return(_result); }
/// <summary> /// Stops MLPrivileges. /// </summary> public static void Stop() { #if PLATFORM_LUMIN if (MLPrivileges.IsStarted) { MLPrivileges.Stop(); } #endif }
/// <summary> /// Requests privileges and calls the callback when the privilege request is /// complete. /// <param name="callback">Callback function to call when the privilege is granted </param> /// </summary> void RequestPrivilege() { Debug.Log("Requesting required privileges"); MLResult result = MLPrivileges.RequestPrivilegeAsync(MLPrivilegeId.PwFoundObjRead, HandlePrivilegeAsyncRequest); if (!result.IsOk) { Debug.LogErrorFormat("{0} Privilege Request Error: {1}", MLPrivilegeId.PwFoundObjRead, result); return; } }
/// <summary> /// Unregister callbacks and stop input API. /// </summary> void OnDestroy() { if (MLInput.IsStarted) { MLInput.OnControllerButtonDown -= HandleOnButtonDown; MLInput.Stop(); } if (_currentPrivilegeState != PrivilegeState.Off) { MLPrivileges.Stop(); } }
/// <summary> /// Shuts down the systems started in Start /// </summary> void OnDestroy() { if (MLPersistentCoordinateFrames.IsStarted) { MLPersistentCoordinateFrames.Stop(); } if (MLPersistentStore.IsStarted) { MLPersistentStore.Stop(); } MLPrivileges.Stop(); }
#pragma warning restore 649 /// <summary> /// Starts up MLPrivileges. /// </summary> public static MLResult Start() { #if PLATFORM_LUMIN _result = MLPrivileges.Start(); if (!_result.IsOk) { Debug.LogErrorFormat("Error: MLPrivilegesStarterKit failed starting MLPrivileges. Reason: {0}", _result); } #endif return(_result); }
/// <summary> /// Used to check if your privilege has already been granted. /// </summary> /// <param name="privilege">The privilege to check for.</param> public static MLResult CheckPrivilege(MLPrivileges.Id privilege) { #if PLATFORM_LUMIN _result = MLPrivileges.CheckPrivilege(privilege); if (_result.Result != MLResult.Code.PrivilegeGranted && _result.Result != MLResult.Code.PrivilegeNotGranted) { Debug.LogErrorFormat("Error: MLPrivilegesStarterKit.CheckPrivilege failed for the privilege {0}. Reason: {1}", privilege, _result); } #endif return(_result); }
#pragma warning restore 649 /// <summary> /// Starts up MLImageTracker. /// Invokes the callback after privleges have been succesfully requested and MLImageTracker is started. /// </summary> public static MLResult Start() { #if PLATFORM_LUMIN _result = MLPrivileges.RequestPrivileges(MLPrivileges.Id.CameraCapture); if (_result.Result != MLResult.Code.PrivilegeGranted) { Debug.LogErrorFormat("Error: MLImageTrackerStarterKit failed requesting privileges. Reason: {0}", _result); return(_result); } #endif return(_result); }
private void Start() { #if PLATFORM_LUMIN if (!MLMRCamera.IsStarted) { MLPrivileges.RequestPrivilege(MLPrivileges.Id.CameraCapture); if (MLMRCamera.Connect(inputContext).IsOk) { MLMRCamera.StartCapture(); } } #endif }
// Use this for initialization void Start() { // TODO turn back on for osc drawing //osc.SetAddressHandler("/date", receiveDraw); osc.SetAddressHandler("/rightR", ringSpinR); osc.SetAddressHandler("/leftR", ringSpinL); osc.SetAddressHandler("/glove", receiveGlove); osc.SetAddressHandler("/rod", rodMove); MLPrivileges.Start(); ring.maxAngularVelocity = .4f; }
/// <summary> /// Start Privilege API. /// </summary> void OnEnable() { MLResult result = MLPrivileges.Start(); if (result.IsOk) { _currentPrivilegeState = PrivilegeState.Started; } else { Debug.LogError("Privilege Error: failed to startup"); enabled = false; return; } }
/// <summary> /// Sets up the various Persistent systems and starts the object restoration /// </summary> void Start() { MLResult result = MLPrivileges.Start(); if (result.IsOk) { RequestPrivilege(); } else { Debug.LogError("Privilege Error: failed to startup"); enabled = false; return; } }
/// <summary> /// Requests privileges and calls the callback when the privilege request is /// complete. /// <param name="callback">Callback function to call when the privielege is granted.</param> /// </summary> void RequestPrivilege() { _state = State.RequestPrivilege; SetProgress(TEXT_REQUESTING_REQUIRED_PRIVILEGES); MLResult result = MLPrivileges.RequestPrivilegeAsync(MLPrivilegeId.PwFoundObjRead, HandlePrivilegeAsyncRequest); if (!result.IsOk) { _state = State.CritialError; string errorMsg = string.Format("MLPrivilegeId.PwFoundObjRead Privilege Request Error: {1}", result); SetProgress(errorMsg); Debug.LogErrorFormat(errorMsg); return; } }
/// <summary> /// Request each needed privilege. /// </summary> private void RequestPrivileges() { foreach (MLPrivilegeId priv in _privilegesNeeded) { MLResult result = MLPrivileges.RequestPrivilegeAsync(priv, HandlePrivilegeAsyncRequest); if (!result.IsOk) { Debug.LogErrorFormat("{0} Privilege Request Error: {1}", priv, result); _currentPrivilegeState = PrivilegeState.Denied; return; } } _currentPrivilegeState = PrivilegeState.Requested; }
/// <summary> /// Request each needed privilege. /// </summary> private void RequestPrivileges() { foreach (MLPrivilegeId priv in _privilegesToRequest) { MLResult result = MLPrivileges.RequestPrivilegeAsync(priv, HandlePrivilegeAsyncRequest); if (!result.IsOk) { Debug.LogErrorFormat("Error: PrivilegeRequester failed requesting {0} privilege. Reason: {1}", priv, result); _state = PrivilegeState.Failed; return; } } _state = PrivilegeState.Requested; }
void Awake() { #if PLATFORM_LUMIN MLResult result = MLPrivileges.RequestPrivileges(MLPrivileges.Id.Internet, MLPrivileges.Id.LocalAreaNetwork, MLPrivileges.Id.CameraCapture, MLPrivileges.Id.AudioCaptureMic); if (result.Result != MLResult.Code.PrivilegeGranted) { Debug.LogError("MLPrivileges failed to grant all needed privileges."); enabled = false; } videoSink = MLWebRTC.VideoSink.Create(out result); fpsTimer = new Timer(1000); videoSink.OnNewFrame += RenderWebRTCFrame; #endif }
protected virtual void Awake() { SetupSingleton(); #if PLATFORM_LUMIN && !UNITY_EDITOR _ = MLPrivileges.RequestPrivilegesAsync(MLPrivileges.Id.ComputerVision).ContinueWith((x) => { if (!x.Result.IsOk && x.Result != MLResult.Code.PrivilegeGranted) { _canRecord = false; OnSpeechStateUpdated?.Invoke(SpeechToTextStates.MicrophoneUnavailable); return; } _canRecord = true; }); #else _canRecord = true; #endif }
/// <summary> /// Start the Privileges API and set the Privilege State /// </summary> void Start() { MLResult result = MLPrivileges.Start(); if (result.IsOk) { _privilegesToRequest.AddRange(Array.ConvertAll(_privileges, tempPrivilege => (MLPrivilegeId)tempPrivilege)); _state = PrivilegeState.Started; } else { Debug.LogErrorFormat( "Error: PrivilegeRequester failed starting MLPrivileges, disabling script. Reason: {0}", result); _state = PrivilegeState.StartFailed; OnPrivilegesDone(result); enabled = false; } }
/// <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(); }
public static async UniTask RequestPrivilege(MLPrivilegeId privilege) { // Don't do privilege if app is running in neither ML device nor ZI mode if (!XRDevice.isPresent) { return; } MLPrivileges.Start().ThrowIfFail(); MLResult?result = null; MLPrivileges.RequestPrivilegeAsync(privilege, (r, _) => { result = r; }).ThrowIfFail(); await UniTask.WaitUntil(() => result.HasValue); result?.ThrowIfFail(); }
/// <summary> /// Request privileges. /// </summary> /// <param name="privileges">An array of privileges to request.</param> public static MLResult RequestPrivileges(params MLPrivileges.Id[] privileges) { #if PLATFORM_LUMIN foreach (MLPrivileges.Id privilege in privileges) { _result = CheckPrivilege(privilege); if (_result.Result == MLResult.Code.PrivilegeGranted) { continue; } _result = MLPrivileges.RequestPrivilege(privilege); if (_result.Result != MLResult.Code.PrivilegeGranted) { return(_result); } } #endif return(_result); }
/// <summary> /// Stop the camera, unregister callbacks, and stop input and privileges APIs. /// </summary> void OnDisable() { if (MLInput.IsStarted) { MLInput.OnControllerButtonDown -= OnButtonDown; MLInput.Stop(); } if (_isCameraConnected) { DisableMLCamera(); } if (_currentPrivilegeState != PrivilegeState.Off) { MLPrivileges.Stop(); _currentPrivilegeState = PrivilegeState.Off; _privilegesGranted.Clear(); } }
/// <summary> /// Used to check if your privilege has already been granted. /// </summary> /// <param name="privilege">The privilege to check for.</param> public static MLResult CheckPrivilege(MLPrivileges.Id privilege) { #if PLATFORM_LUMIN if (MLPrivileges.IsStarted) { _result = MLPrivileges.CheckPrivilege(privilege); if (_result.Result != MLResult.Code.PrivilegeGranted && _result.Result != MLResult.Code.PrivilegeNotGranted) { Debug.LogErrorFormat("Error: MLPrivilegesStarterKit.CheckPrivilege failed for the privilege {0}. Reason: {1}", privilege, _result); } } else { Debug.LogError("Error: MLPrivilegesStarterKit.CheckPrivilege failed because MLPrivileges was not started."); _result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPrivileges was not started"); } #endif return(_result); }
/// <summary> /// Stop the camera, unregister callbacks, and stop input and privileges APIs. /// </summary> void OnDisable() { if (MLInput.IsStarted) { MLInput.OnControllerButtonDown -= OnButtonDown; MLInput.Stop(); } if (_isCameraConnected) { MLCamera.OnRawImageAvailable -= OnCaptureRawImageComplete; _isCapturing = false; DisableMLCamera(); } if (_currentPrivilegeState != PrivilegeState.Off) { MLPrivileges.Stop(); _currentPrivilegeState = PrivilegeState.Off; _privilegesGranted.Clear(); } }
/// <summary> /// Assure that if the 'WorldReconstruction' privilege is missing, then it is logged for all users /// </summary> private IEnumerator LogWorldReconstructionMissingPrivilege() { yield return(new WaitUntil(() => MagicLeapDevice.IsReady())); MLResult result = MLPrivileges.Start(); if (result.IsOk) { result = MLPrivileges.CheckPrivilege(MLPrivilegeId.WorldReconstruction); if (result.Code != MLResultCode.PrivilegeGranted) { Debug.LogErrorFormat("Error: Unable to create Mesh Subsystem due to missing 'WorldReconstruction' privilege. Please add to manifest. Disabling script."); enabled = false; } MLPrivileges.Stop(); } else { Debug.LogErrorFormat("Error: MeshingExample failed starting MLPrivileges. Reason: {0}", result); } yield return(null); }
void Start() { #if PLATFORM_LUMIN MLResult result = MLPrivileges.RequestPrivileges(MLPrivileges.Id.CameraCapture); #endif }