IEnumerator Start()
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;

#if UNITY_ANDROID
#if VIVEHANDTRACKING_WITH_WAVEVR
            // setup wavevr rendering
            if (transform.GetComponent <WaveVR_Render>() == null)
            {
                Destroy(transform.GetComponent <AudioListener>());
                Destroy(transform.GetComponent <FlareLayer>());
                gameObject.AddComponent <WaveVR_Render>();
                var tracker = gameObject.AddComponent <WaveVR_DevicePoseTracker>();
#if VIVEHANDTRACKING_WITH_WAVEVR3
                tracker.type = WaveVR_Controller.EDeviceType.Head;
#else
                tracker.type = wvr.WVR_DeviceType.WVR_DeviceType_HMD;
#endif
            }
            yield return(WaitForReady());

            // get camera permission
            var pmInstance = WaveVR_PermissionManager.instance;
            while (!pmInstance.isInitialized())
            {
                yield return(null);
            }

            bool granting      = true;
            bool hasPermission = pmInstance.isPermissionGranted(permissionNames[0]);
            WaveVR_PermissionManager.requestCompleteCallback callback = (results) => {
                granting = false;
                if (results.Count > 0 && results[0].Granted)
                {
                    hasPermission = true;
                }
            };
            while (!hasPermission)
            {
                granting = true;
                pmInstance.requestPermissions(permissionNames, callback);
                while (granting)
                {
                    yield return(null);
                }
            }
#elif VIVEHANDTRACKING_WITH_GOOGLEVR
            // get camera permission using daydream API
            if (UnityEngine.VR.VRSettings.loadedDeviceName == "daydream")
            {
                var  permissionRequester = GvrPermissionsRequester.Instance;
                bool granting            = true;
                Action <GvrPermissionsRequester.PermissionStatus[]> callback = (results) => granting = false;
                while (!permissionRequester.IsPermissionGranted(permissionNames[0]))
                {
                    granting = true;
                    permissionRequester.RequestPermissions(permissionNames, callback);
                    while (granting)
                    {
                        yield return(null);
                    }
                }
            }
#elif UNITY_2018_3_OR_NEWER
            // Unity 2018.3 or newer adds support for android runtime permission
            while (!Permission.HasUserAuthorizedPermission(Permission.Camera))
            {
                Permission.RequestUserPermission(Permission.Camera);
                yield return(null);
            }
#else
            while (!Application.HasUserAuthorization(UserAuthorization.WebCam))
            {
                yield return(Application.RequestUserAuthorization(UserAuthorization.WebCam));
            }
#endif
#endif
            GestureInterface.UseExternalTransform(true);

            // start detection
            StartGestureDetection();
            initialized = true;
            yield break;
        }
Example #2
0
        public override IEnumerator Setup()
        {
            lastIndex = -1;
            var transform  = GestureProvider.Current.transform;
            var gameObject = GestureProvider.Current.gameObject;

#if UNITY_ANDROID && !UNITY_EDITOR
#if VIVEHANDTRACKING_WITH_WAVEVR
            // get camera permission
            var pmInstance = WaveVR_PermissionManager.instance;
            while (!pmInstance.isInitialized())
            {
                yield return(null);
            }

            bool granting      = true;
            bool hasPermission = pmInstance.isPermissionGranted(permissionNames[0]);
            WaveVR_PermissionManager.requestCompleteCallback callback = (results) => {
                granting = false;
                if (results.Count > 0 && results[0].Granted)
                {
                    hasPermission = true;
                }
            };
            while (!hasPermission)
            {
                granting = true;
                pmInstance.requestPermissions(permissionNames, callback);
                while (granting)
                {
                    yield return(null);
                }
            }
#elif VIVEHANDTRACKING_WITH_GOOGLEVR
            // get camera permission using daydream API
            if (UnityEngine.VR.VRSettings.loadedDeviceName == "daydream")
            {
                var  permissionRequester = GvrPermissionsRequester.Instance;
                bool granting            = true;
                Action <GvrPermissionsRequester.PermissionStatus[]> callback = (results) => granting = false;
                while (!permissionRequester.IsPermissionGranted(permissionNames[0]))
                {
                    granting = true;
                    permissionRequester.RequestPermissions(permissionNames, callback);
                    while (granting)
                    {
                        yield return(null);
                    }
                }
            }
#elif UNITY_2018_3_OR_NEWER
            // Unity 2018.3 or newer adds support for android runtime permission
            while (!Permission.HasUserAuthorizedPermission(Permission.Camera))
            {
                Permission.RequestUserPermission(Permission.Camera);
                yield return(null);
            }
#else
            while (!Application.HasUserAuthorization(UserAuthorization.WebCam))
            {
                yield return(Application.RequestUserAuthorization(UserAuthorization.WebCam));
            }
#endif
#endif

            GestureInterface.UseExternalTransform(true);
            yield break;
        }