Example #1
0
        /// <summary>
        /// MonoBehaviour Start
        /// </summary>
        protected override void Start()
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            if (Application.platform == RuntimePlatform.Android)
            {
                try
                {
                    using (var systemClass = new AndroidJavaClass("java.lang.System"))
                    {
                        systemClass.CallStatic("loadLibrary", "arcore_sdk_c");
                    }
                    arcoreLoaded = true;
                }
                catch (AndroidJavaException) { }
            }
#endif
            if (UpdateCalibrationOnStart && Application.platform == RuntimePlatform.Android)
            {
                // NOTE:
                // This downloader instance will return asynchronously. Latest calibration may not be used in the first time.
                // You can setup the download procedure in your own code if latest calibration usage is desired before tracking start.
                var downloader = new CalibrationDownloader();
                downloader.download(EasyARController.Scheduler, (status, error) =>
                {
                    switch (status)
                    {
                    case CalibrationDownloadStatus.Successful:
                        Debug.Log("Calibration file has been updated.");
                        break;

                    case CalibrationDownloadStatus.NotModified:
                        Debug.Log("Calibration file is up to date.");
                        break;

                    default:
                        Debug.LogError("Error download calibration file, " + status + ": " + error);
                        break;
                    }
                    downloader.Dispose();
                });
            }

            switch (DeviceStrategy)
            {
            case DeviceChooseStrategy.SystemVIOFirst:
                var arcoreFail = CheckARCore();
                if (!MotionTrackerCameraDevice.isAvailable() && !ARKitCameraDevice.isAvailable() && !ARCoreCameraDevice.isAvailable())
                {
                    throw new UIPopupException("VIOCameraDevice not available");
                }
                if (!ARKitCameraDevice.isAvailable() && !ARCoreCameraDevice.isAvailable() && MotionTrackerCameraDevice.isAvailable() && MotionTrackerCameraDevice.getQualityLevel() < DesiredMotionTrackerParameters.MinQualityLevel)
                {
                    throw new UIPopupException("VIOCameraDevice available but disabled with quality level (" + MotionTrackerCameraDevice.getQualityLevel() + "), min level is set to " + DesiredMotionTrackerParameters.MinQualityLevel);
                }
                if (arcoreFail)
                {
                    GUIPopup.EnqueueMessage(typeof(MotionTrackerCameraDevice) + " selected", 3);
                }
                break;

            case DeviceChooseStrategy.EasyARMotionTrackerFirst:
                if (!MotionTrackerCameraDevice.isAvailable())
                {
                    CheckARCore();
                }
                if (!MotionTrackerCameraDevice.isAvailable() && !ARKitCameraDevice.isAvailable() && !ARCoreCameraDevice.isAvailable())
                {
                    throw new UIPopupException("VIOCameraDevice not available");
                }
                if (MotionTrackerCameraDevice.isAvailable() && MotionTrackerCameraDevice.getQualityLevel() < DesiredMotionTrackerParameters.MinQualityLevel)
                {
                    throw new UIPopupException("VIOCameraDevice available but disabled with quality level (" + MotionTrackerCameraDevice.getQualityLevel() + "), min level is set to " + DesiredMotionTrackerParameters.MinQualityLevel);
                }
                break;

            case DeviceChooseStrategy.SystemVIOOnly:
                CheckARCore();
                if (!ARKitCameraDevice.isAvailable() && Application.platform == RuntimePlatform.IPhonePlayer)
                {
                    throw new UIPopupException(typeof(ARKitCameraDevice) + " not available");
                }
                else if (!ARCoreCameraDevice.isAvailable() && Application.platform == RuntimePlatform.Android)
                {
                    throw new UIPopupException(typeof(ARCoreCameraDevice) + " not available");
                }
                else if (!ARKitCameraDevice.isAvailable() && !ARCoreCameraDevice.isAvailable())
                {
                    throw new UIPopupException("System VIO not available");
                }
                break;

            case DeviceChooseStrategy.EasyARMotionTrackerOnly:
                if (!MotionTrackerCameraDevice.isAvailable())
                {
                    throw new UIPopupException(typeof(MotionTrackerCameraDevice) + " not available");
                }
                if (MotionTrackerCameraDevice.getQualityLevel() < DesiredMotionTrackerParameters.MinQualityLevel)
                {
                    throw new UIPopupException(typeof(MotionTrackerCameraDevice) + " available but disabled with quality level (" + MotionTrackerCameraDevice.getQualityLevel() + "), min level is set to " + DesiredMotionTrackerParameters.MinQualityLevel);
                }
                break;

            default:
                break;
            }

            base.Start();
        }