private HoloGazeManager() { //head instance. Head = new Misc.HoloHead(); //Gaze hit instance. GazeHit = new HoloGazeHit(); //gesture recognizer. _gestureRecognizer = new UnityEngine.VR.WSA.Input.GestureRecognizer(); //set recognizable gestures. _gestureRecognizer.SetRecognizableGestures(UnityEngine.VR.WSA.Input.GestureSettings.Tap | UnityEngine.VR.WSA.Input.GestureSettings.Hold | UnityEngine.VR.WSA.Input.GestureSettings.ManipulationTranslate | UnityEngine.VR.WSA.Input.GestureSettings.DoubleTap); //attach listeners. _gestureRecognizer.TappedEvent += OnTapEvent; _gestureRecognizer.HoldStartedEvent += OnHoldStartedEvent; _gestureRecognizer.HoldCompletedEvent += OnHoldCompletedEvent; _gestureRecognizer.ManipulationStartedEvent += OnManipulationStartedEvent; _gestureRecognizer.ManipulationUpdatedEvent += OnManipulationUpdateEvent; _gestureRecognizer.ManipulationCompletedEvent += OnManipulationEndedEvent; //start recognizing. _gestureRecognizer.StartCapturingGestures(); }
private void Start() { recognizer = new UnityEngine.VR.WSA.Input.GestureRecognizer(); recognizer.SetRecognizableGestures(UnityEngine.VR.WSA.Input.GestureSettings.Tap); recognizer.TappedEvent += Recognizer_TappedEvent; recognizer.StartCapturingGestures(); }
protected override void Awake() { base.Awake(); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// recognizer = new UnityEngine.VR.WSA.Input.GestureRecognizer(); recognizer.TappedEvent += (source, tapCount, ray) => { // Send an OnSelect message to the focused object and its ancestors. if (previousFocusObject != null) { previousFocusObject.SendMessageUpwards("OnSelect"); } }; recognizer.StartCapturingGestures(); // Add default RaycastLayers as first layerPriority if (RaycastLayerMasks == null || RaycastLayerMasks.Length == 0) { RaycastLayerMasks = new LayerMask[] { Physics.DefaultRaycastLayers }; } if (GazeTransform == null) { if (Camera.main != null) { GazeTransform = Camera.main.transform; } else { Debug.LogError("Gaze Manager was not given a GazeTransform and no main camera exists to default to."); } } }
/// <summary> /// Finds the object that is focussed on. /// if none are found focussed object will be NULL /// </summary> public void FindFocusedObject() { //create prevFocusedObject UnityEngine.GameObject prevFocusedObject = FocusedObject; //shoot ray. GazeHit.HasHit = UnityEngine.Physics.Raycast(Head.Position, Head.Direction, out GazeHit.RayHit); //Shoot ray and store result. if (GazeHit.HasHit) { this.FocusedObject = this.GazeHit.RayHit.collider.gameObject; if (this.FocusedObject.GetComponent <Unity.HoloObject>() != null) { if (this.FocusedObject.GetComponent <Unity.HoloObject>().HasFocus == false) { this.FocusedObject.GetComponent <Unity.HoloObject>().OnFocusIn(); } } } else { if (this.FocusedObject != null) { if (this.FocusedObject.GetComponent <Unity.HoloObject>() != null) { if (this.FocusedObject.GetComponent <Unity.HoloObject>().HasFocus == true) { this.FocusedObject.GetComponent <Unity.HoloObject>().OnFocusOut(); } } } this.FocusedObject = null; } // check if prev focused object is not focused object // reset the gestures and start over. if (this.FocusedObject != prevFocusedObject) { if (prevFocusedObject != null) { if (prevFocusedObject.GetComponent <Unity.HoloObject>() != null) { if (prevFocusedObject.GetComponent <Unity.HoloObject>().HasFocus == true) { prevFocusedObject.GetComponent <Unity.HoloObject>().OnFocusOut(); } } } _gestureRecognizer.CancelGestures(); _gestureRecognizer.StartCapturingGestures(); } }
/// <summary> /// Make sure the gesture recognizer is off, then start it. /// Otherwise, leave it alone because it's already in the desired state. /// </summary> public void StartGestureRecognizer() { if (gestureRecognizer != null && !gestureRecognizer.IsCapturingGestures()) { gestureRecognizer.StartCapturingGestures(); } if (navigationGestureRecognizer != null && !navigationGestureRecognizer.IsCapturingGestures()) { navigationGestureRecognizer.StartCapturingGestures(); } }
protected override void Start() { base.Start(); gestureRecognizer = new UnityEngine.VR.WSA.Input.GestureRecognizer(); gestureRecognizer.TappedEvent += OnTappedEvent; gestureRecognizer.HoldStartedEvent += OnHoldStartedEvent; gestureRecognizer.HoldCompletedEvent += OnHoldCompletedEvent; gestureRecognizer.HoldCanceledEvent += OnHoldCanceledEvent; gestureRecognizer.ManipulationStartedEvent += OnManipulationStartedEvent; gestureRecognizer.ManipulationUpdatedEvent += OnManipulationUpdatedEvent; gestureRecognizer.ManipulationCompletedEvent += OnManipulationCompletedEvent; gestureRecognizer.ManipulationCanceledEvent += OnManipulationCanceledEvent; gestureRecognizer.SetRecognizableGestures(UnityEngine.VR.WSA.Input.GestureSettings.Tap | UnityEngine.VR.WSA.Input.GestureSettings.ManipulationTranslate | UnityEngine.VR.WSA.Input.GestureSettings.Hold); // We need a separate gesture recognizer for navigation, since it isn't compatible with manipulation navigationGestureRecognizer = new UnityEngine.VR.WSA.Input.GestureRecognizer(); navigationGestureRecognizer.NavigationStartedEvent += OnNavigationStartedEvent; navigationGestureRecognizer.NavigationUpdatedEvent += OnNavigationUpdatedEvent; navigationGestureRecognizer.NavigationCompletedEvent += OnNavigationCompletedEvent; navigationGestureRecognizer.NavigationCanceledEvent += OnNavigationCanceledEvent; if (UseRailsNavigation) { navigationGestureRecognizer.SetRecognizableGestures(UnityEngine.VR.WSA.Input.GestureSettings.NavigationRailsX | UnityEngine.VR.WSA.Input.GestureSettings.NavigationRailsY | UnityEngine.VR.WSA.Input.GestureSettings.NavigationRailsZ); } else { navigationGestureRecognizer.SetRecognizableGestures(UnityEngine.VR.WSA.Input.GestureSettings.NavigationX | UnityEngine.VR.WSA.Input.GestureSettings.NavigationY | UnityEngine.VR.WSA.Input.GestureSettings.NavigationZ); } if (RecognizerStart == RecognizerStartBehavior.AutoStart) { gestureRecognizer.StartCapturingGestures(); navigationGestureRecognizer.StartCapturingGestures(); } }
// Transfer from one gesture module to another one. public void Transition(UnityEngine.VR.WSA.Input.GestureRecognizer newRecognizer) { if (newRecognizer == null) { return; } if (ActiveRecognizer != null) { if (ActiveRecognizer == newRecognizer) { return; } ActiveRecognizer.CancelGestures(); ActiveRecognizer.StopCapturingGestures(); } newRecognizer.StartCapturingGestures(); ActiveRecognizer = newRecognizer; if (ActiveRecognizer == ClickRecognizer) { IsClicking = true; } else { IsClicking = false; } if (ActiveRecognizer == SaveRecognizer) { DebugInfoManager.Instance.UpdateSavePointsStatus(true); } else { DebugInfoManager.Instance.UpdateSavePointsStatus(false); } }