コード例 #1
0
        /// <summary>
        /// Utility function set up instance and tracks successful _startCount
        /// </summary>
        /// <param name="requiresXRLoader">Flag to determine if this API requires the XR Loader being initialized.</param>
        /// <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 (MagicLeap XR Loader not loaded, no device, DLL not found, no API symbols).
        /// MLResult.Result will otherwise be return value specific API's StartAPI function.
        /// </returns>
        protected static MLResult BaseStart(bool requiresXRLoader = false)
        {
            MLResult result;

            try
            {
                // Check to see if we have already successfully initialized a valid instance
                if (startCount > 0)
                {
                    startCount++;
                    result = MLResult.Create(MLResult.Code.Ok);
                }
                else
                {
                    if (requiresXRLoader && !MLDevice.IsReady())
                    {
                        MLPluginLog.ErrorFormat("MLAPISingleton.BaseStart failed to start {0} API. Reason: MagicLeap XR Loader is not initialized. Please wait to start API until Monobehavior.Start and if issue persists make sure ProjectSettings/XR/Initialize On Startup is enabled.", typeof(T).Name);
                        return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MagicLeap XR Loader not initialized"));
                    }

                    result = Instance.StartAPI();
                    if (result.IsOk)
                    {
                        // Everything started correctly register the update and increament _startCount
                        MLDevice.RegisterUpdate(Instance.Update);
                        MLDevice.RegisterApplicationPause(Instance.OnApplicationPause);
                        startCount++;

                        Instance.perceptionHandle     = PerceptionHandle.Acquire();
                        Instance.perceptionHasStarted = true;
                    }
                    else
                    {
                        MLPluginLog.ErrorFormat("MLAPISingleton.BaseStart failed to start {0} API. Reason: {1}", typeof(T).Name, result);
                        _instance = null;
                    }
                }

                return(result);
            }
            catch (System.DllNotFoundException)
            {
                MLPluginLog.ErrorFormat(_instance.DllNotFoundError, typeof(T).Name);
                result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "Dll not found");
                MLPluginLog.ErrorFormat("MLAPISingleton.BaseStart failed to start {0} API. Reason: {1}", typeof(T).Name, result);
                _instance = null;
            }
            catch (System.EntryPointNotFoundException)
            {
                string errorMessage = string.Format("{0} API symbols not found", typeof(T).Name);
                result = MLResult.Create(MLResult.Code.UnspecifiedFailure, errorMessage);
                MLPluginLog.ErrorFormat("MLAPISingleton.BaseStart failed to start {0} API. Reason: {1}", typeof(T).Name, result);
                _instance = null;
            }

            return(result);
        }
コード例 #2
0
        private void StartInternal()
        {
            MLPluginLog.Debug($"Initializing {typeof(T).Name} API...");

            if (DidNativeCallSucceed(StartAPI(), $"{typeof(T).Name} Start"))
            {
                IsStarted = true;
                MLDevice.RegisterUpdate(instance.Update);
                MLDevice.RegisterApplicationPause(instance.OnApplicationPause);
                MLDevice.RegisterDestroy(instance.StopInternal);

                instance.perceptionHandle = PerceptionHandle.Acquire();
                MLPluginLog.Debug($"{typeof(T).Name} API initialized.");
            }
        }
コード例 #3
0
            /// <summary>
            /// Request a new page
            /// </summary>
            /// <param name="pageLength">The length of the page</param>
            /// <param name="offset">Offset into the page</param>
            /// <returns>
            /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successfully submitted
            /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if either of the parameters are invalid.
            /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if necessary privilege is missing.
            /// </returns>
            protected virtual MLResult InternalNewPage(uint pageLength, string offset)
            {
                MLResult.Code resultCode = MLContacts.GetList(pageLength, offset, out ulong handle);
                this.RequestHandle = handle;

                if (resultCode != MLResult.Code.Ok)
                {
                    this.Status = PageStatus.Failed;
                    return(MLResult.Create(resultCode));
                }

                this.Status = PageStatus.Pending;
                MLDevice.RegisterUpdate(this.Update);
                this.UnregisterUpdate = true;

                return(MLResult.Create(MLResult.Code.Ok));
            }