Example #1
0
        IEnumerator StartGestureDetection(HandTrackingEngine engine)
        {
            if (Status == GestureStatus.Starting || Status == GestureStatus.Running || engine == null)
            {
                yield break;
            }
            yield return(engine.StartDetection(option));

            if (Status == GestureStatus.Starting || Status == GestureStatus.Running)
            {
                State.Error = GestureFailure.None;
                option.mode = State.Mode;
                frames      = 0;
            }
            if (State.Error != GestureFailure.None)
            {
                Debug.LogError(engine.GetType().Name + " start failed: " + State.Error);
            }
        }
Example #2
0
        IEnumerator Start()
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            // setup wavevr rendering
#if VIVEHANDTRACKING_WITH_WAVEVR
#if UNITY_EDITOR
            // NOTE: use reflection in unity eidtor to avoid compile breakage if wavevr package is removed
            var type = Type.GetType("WaveVR_Render");
            if (type != null)
            {
                if (transform.GetComponent(type) == null)
                {
                    Destroy(transform.GetComponent <AudioListener>());
                    Destroy(transform.GetComponent <FlareLayer>());
                    gameObject.AddComponent(type);
                    var tracker = gameObject.AddComponent(Type.GetType("WaveVR_DevicePoseTracker"));
                    type = tracker.GetType();
                    var fieldInfo = type.GetField("type");
                    fieldInfo.SetValue(tracker, Enum.ToObject(fieldInfo.FieldType, 1));
                }
            }
#else
            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
            }
#endif
            yield return(null);
#endif

            foreach (var engine in settings.Engines)
            {
                if (!engine.IsSupported())
                {
                    continue;
                }
                State.ClearState();
                engine.State = State;
                yield return(engine.Setup());

                if (State.Status == GestureStatus.Error)
                {
                    Debug.LogError(engine.GetType().Name + " setup failed");
                    continue;
                }
                // try start detection
                yield return(StartGestureDetection(engine));

                if (State.Status == GestureStatus.Error)
                {
                    engine.StopDetection();
                    Debug.LogError(engine.GetType().Name + " start failed");
                    continue;
                }
                this.engine = engine;
                EngineName  = engine.GetType().Name;
                Debug.Log("Selected " + EngineName);
                break;
            }
            if (engine == null)
            {
                Debug.LogError("No suitable engine found");
            }
        }