예제 #1
0
 /// <summary>
 /// If the Privileges API is running, stop it.
 /// </summary>
 void OnDestroy()
 {
     if (MLPrivileges.IsStarted)
     {
         MLPrivileges.Stop();
     }
 }
예제 #2
0
        private void StartCapture()
        {
#if PLATFORM_LUMIN
            MLPrivileges.RequestPrivileges(MLPrivileges.Id.CameraCapture);
            MLMRCamera.Connect(this.inputContext);
            MLMRCamera.StartCapture();
#endif
        }
 /// <summary>
 /// If the Privileges API is running, stop it.
 /// </summary>
 void OnDestroy()
 {
     #if PLATFORM_LUMIN
     if (MLPrivileges.IsStarted)
     {
         MLPrivileges.Stop();
     }
     #endif
 }
        void OnDestroy()
        {
            if (_state != PrivilegeState.Off && _state != PrivilegeState.StartFailed)
            {
                MLPrivileges.Stop();

                _state = PrivilegeState.Off;
                _privilegesGranted.Clear();
                _privilegesToRequest.Clear();
            }
        }
        private void StartCapture()
        {
#if PLATFORM_LUMIN
            if (!isCapturing)
            {
                MLPrivileges.RequestPrivileges(MLPrivileges.Id.CameraCapture);
                MLCamera.Connect();
                MLCamera.PrepareCapture(MLCamera.CaptureType.VideoRaw, ref this.captureSettings);
                MLCamera.OnRawVideoFrameAvailableYUV_NativeCallbackThread += OnMLCameraFrameYUV;
                MLCamera.StartRawVideoCapture();
                isCapturing = true;
            }
#endif
        }
예제 #6
0
        /// <summary>
        /// Handles the application pause callback.
        /// </summary>
        /// <param name="pause"> True if the app is paused.</param>
        protected override void OnApplicationPause(bool pause)
        {
            if (!pause)
            {
                MLPrivileges.RequestPrivilege(MLPrivileges.Id.CameraCapture);
            }

            MLResult result = pause ? Disable() : Enable();

            if (!result.IsOk)
            {
                MLPluginLog.ErrorFormat("MLImageTracker.OnApplicationPause failed to {0} the image tracker. Reason: {1}", pause ? "disable" : "enable", result);
            }
        }
예제 #7
0
        /// <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;
        }
예제 #8
0
        /// <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;
            }
        }
        void Start()
        {
            MLResult result = MLPrivileges.Start();

            if (result.IsOk)
            {
                _privilegesToRequest.AddRange(Array.ConvertAll(_privileges, tempPrivilege => (MLPrivilegeId)tempPrivilege));
                _state = PrivilegeState.Started;
            }
            else
            {
                Debug.LogError("Privilege Error: failed to startup");
                _state = PrivilegeState.StartFailed;
                OnPrivilegesDone(result);
                enabled = false;
            }
        }
예제 #10
0
        /// <summary>
        /// Initializes the image tracker.
        /// </summary>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error.
        /// </returns>
        protected override MLResult.Code StartAPI()
        {
            MLPrivileges.RequestPrivilege(MLPrivileges.Id.CameraCapture);

            this.trackerSettings = NativeBindings.MLImageTrackerSettingsNative.Create();
            MLResult.Code result = NativeBindings.MLImageTrackerInitSettings(ref this.trackerSettings);
            if (result != MLResult.Code.Ok)
            {
                MLPluginLog.ErrorFormat("MLImageTracker.Constructor failed initializing the ImageTrackerSettings. Reason: {0}", result);
            }

            this.targetList = new List <Target>();

            this.handle = MagicLeapNativeBindings.InvalidHandle;
            MLResult.Code resultCode = NativeBindings.MLImageTrackerCreate(ref this.trackerSettings, ref this.handle);

            if (!DidNativeCallSucceed(resultCode, "MLImageTrackerCreate"))
            {
                return(resultCode);
            }

            return(UpdateTrackerSettings(MLImageTracker.Settings.Create(this.trackerSettings.MaxSimultaneousTargets)).Result);
        }
예제 #11
0
        /// <summary>
        /// Provides the string value for any MLResult.Code.
        /// </summary>
        /// <param name="resultCode">The code to convert into a string value.</param>
        /// <returns>The string value of the given MLResult.Code.</returns>
        public static string CodeToString(MLResult.Code resultCode)
        {
            string codeString = string.Empty;

            switch ((CodePrefix)((int)resultCode >> 16))
            {
            case CodePrefix.MLResultGlobal:
            case CodePrefix.MLSnapshotResult:
                codeString = Marshal.PtrToStringAnsi(MagicLeapNativeBindings.MLSnapshotGetResultString(resultCode));
                break;

            case CodePrefix.MLAudioResult:
                codeString = Marshal.PtrToStringAnsi(MLAudio.GetResultString(resultCode));
                break;

            case CodePrefix.MLMediaDRMResult:
            case CodePrefix.MLMediaGenericResult:
            case CodePrefix.MLMediaPlayerResult:
            case CodePrefix.MLMediaResult:
                codeString = Marshal.PtrToStringAnsi(MLMediaPlayer.GetResultString(resultCode));
                break;

            case CodePrefix.MLDispatchResult:
                codeString = Marshal.PtrToStringAnsi(MLDispatch.GetResultString(resultCode));
                break;

            case CodePrefix.MLIdentityResult:
                codeString = Marshal.PtrToStringAnsi(MLIdentity.GetResultString(resultCode));
                break;

            case CodePrefix.MLPassableWorldResult:
                codeString = Marshal.PtrToStringAnsi(MLPersistentCoordinateFrames.GetResultString(resultCode));
                break;

            case CodePrefix.MLTokenAgentResult:
                codeString = Marshal.PtrToStringAnsi(MLTokenAgent.GetResultString(resultCode));
                break;

            case CodePrefix.MLPrivilegesResult:
                codeString = Marshal.PtrToStringAnsi(MLPrivileges.GetResultString(resultCode));
                break;

            case CodePrefix.MLContactsResult:
                codeString = Marshal.PtrToStringAnsi(MLContacts.GetResultString(resultCode));
                break;

            case CodePrefix.MLLocationResult:
                codeString = Marshal.PtrToStringAnsi(MLLocation.GetResultString(resultCode));
                break;

            case CodePrefix.MLNetworkingResult:
                codeString = Marshal.PtrToStringAnsi(MLNetworkingNativeBindings.MLNetworkingGetResultString(resultCode));
                break;

            case CodePrefix.MLMovementResult:
                codeString = Marshal.PtrToStringAnsi(MLMovement.GetResultString(resultCode));
                break;

            case CodePrefix.MLConnectionsResult:
                codeString = Marshal.PtrToStringAnsi(MLConnections.GetResultString(resultCode));
                break;

            case CodePrefix.MLSecureStorageResult:
                codeString = Marshal.PtrToStringAnsi(MLSecureStorageNativeBindings.MLSecureStorageGetResultString(resultCode));
                break;

            case CodePrefix.MLAppConnect:
                codeString = Marshal.PtrToStringAnsi(MLAppConnectNativeBindings.MLAppConnectGetResultString(resultCode));
                break;

            case CodePrefix.MLWebRTC:
                codeString = Marshal.PtrToStringAnsi(MLWebRTC.NativeBindings.MLWebRTCGetResultString(resultCode));
                break;

            case CodePrefix.MLBluetoothGattResult:
                codeString = Marshal.PtrToStringAnsi(MLBluetoothLE.NativeBindings.MLBluetoothGattGetResultString(resultCode));
                break;

            default:
                // This will catch any unknown/invalid return values.
                codeString = MagicLeapNativeBindings.MLGetResultString(resultCode);
                break;
            }

            return(codeString);
        }