/// <summary> /// Sends the events for hand state changes. /// </summary> /// <param name="editorHandData">Hand data for which events should be sent.</param> private void SendHandStateEvents(EditorHandData editorHandData, float time) { // Hand moved event if (editorHandData.HandDelta.sqrMagnitude > 0) { HandMoved.RaiseEvent(this, editorHandData.HandId); } // Finger pressed/released events if (editorHandData.FingerStateChanged) { if (editorHandData.IsFingerDown) { inputManager.RaiseSourceDown(this, editorHandData.HandId); } else { inputManager.RaiseSourceUp(this, editorHandData.HandId); // Also send click event when using this hands replacement input if (time - editorHandData.FingerDownStartTime < MaxClickDuration) { // We currently only support single taps in editor inputManager.RaiseInputClicked(this, editorHandData.HandId, 1); } } } }
/// <summary> /// Sends the events for hand state changes. /// </summary> /// <param name="editorHandData">Hand data for which events should be sent.</param> private void SendHandStateEvents(EditorHandData editorHandData) { // Hand moved event if (editorHandData.HandDelta.sqrMagnitude > 0) { HandMoved.RaiseEvent(this, editorHandData.HandId); } // Finger pressed/released events if (editorHandData.FingerStateChanged) { if (editorHandData.IsFingerDown) { RaiseSourceDownEvent(editorHandData.InputSourceArgs); } else { RaiseSourceUpEvent(editorHandData.InputSourceArgs); // Also send click event when using this hands replacement input if (Time.time - editorHandData.FingerDownStartTime < MaxClickDuration) { // We currently only support single taps in editor SourceClickEventArgs args = new SourceClickEventArgs(this, editorHandData.HandId, 1); RaiseSourceClickedEvent(args); } } } }
private void Awake() { #if !UNITY_EDITOR Destroy(this); #endif manualHandControl = GetComponent <ManualHandControl>(); for (uint i = 0; i < editorHandsData.Length; i++) { editorHandsData[i] = new EditorHandData(i); } }
/// <summary> /// Gets the hand data for the specified hand source if it already exists, otherwise creates it. /// </summary> /// <param name="sourceId">Hand source for which hands data should be retrieved.</param> /// <returns>The hand data requested.</returns> private EditorHandData GetOrAddHandData(uint sourceId) { EditorHandData handData; if (!handIdToData.TryGetValue(sourceId, out handData)) { handData = new EditorHandData(sourceId); handIdToData.Add(handData.HandId, handData); newHands.Add(handData.HandId); } return(handData); }
/// <summary> /// Updates the hand positional information. /// </summary> /// <param name="handSource">Hand source to use to update the position.</param> /// <param name="editorHandData">EditorHandData structure to update.</param> private void UpdateHandState(DebugInteractionSourceState handSource, EditorHandData editorHandData, float deltaTime, float time) { // Update hand position Vector3 handPosition; if (handSource.Properties.Location.TryGetPosition(out handPosition)) { editorHandData.HandDelta = handPosition - editorHandData.HandPosition; editorHandData.HandPosition = handPosition; } // Check for finger presses if (handSource.Pressed != editorHandData.IsFingerDownPending) { editorHandData.IsFingerDownPending = handSource.Pressed; editorHandData.FingerStateUpdateTimer = FingerPressDelay; } // Finger presses are delayed to mitigate issue with hand position shifting during air tap editorHandData.FingerStateChanged = false; if (editorHandData.FingerStateUpdateTimer > 0) { editorHandData.FingerStateUpdateTimer -= deltaTime; if (editorHandData.FingerStateUpdateTimer <= 0) { editorHandData.IsFingerDown = editorHandData.IsFingerDownPending; editorHandData.FingerStateChanged = true; if (editorHandData.IsFingerDown) { editorHandData.FingerDownStartTime = time; } } } SendHandStateEvents(editorHandData, time); }
/// <summary> /// Sends the events for hand state changes. /// </summary> /// <param name="editorHandData">Hand data for which events should be sent.</param> /// <param name="time">Unscaled time of last event.</param> private void SendHandStateEvents(EditorHandData editorHandData, float time) { // Hand moved event. if (editorHandData.HandDelta.sqrMagnitude > 0) { HandMoved.RaiseEvent(this, editorHandData.HandId); } // If the finger state has just changed to be down vs up. if (editorHandData.FingerStateChanged) { // New down presses are straightforward - fire input down and be on your way. if (editorHandData.IsFingerDown) { InputManager.Instance.RaiseSourceDown(this, editorHandData.HandId); editorHandData.CumulativeDelta = Vector3.zero; } // New up presses require sending different events depending on whether it's also a click, hold, or manipulation. else { // A gesture is always either a click, a hold or a manipulation. if (editorHandData.ManipulationInProgress) { InputManager.Instance.RaiseManipulationCompleted(this, editorHandData.HandId, editorHandData.CumulativeDelta); editorHandData.ManipulationInProgress = false; } // Clicks and holds are based on time, and both are overruled by manipulations. else if (editorHandData.HoldInProgress) { InputManager.Instance.RaiseHoldCompleted(this, editorHandData.HandId); editorHandData.HoldInProgress = false; } else { // We currently only support single taps in editor. InputManager.Instance.RaiseInputClicked(this, editorHandData.HandId, 1); } InputManager.Instance.RaiseSourceUp(this, editorHandData.HandId); } } // If the finger state hasn't changed, and the finger is down, that means if calculations need to be done // nothing might change, or it might trigger a hold or a manipulation (or a hold and then a manipulation). else if (editorHandData.IsFingerDown) { editorHandData.CumulativeDelta += editorHandData.HandDelta; if (!editorHandData.ManipulationInProgress) { // Manipulations are triggered by the amount of movement since the finger was pressed down. if (editorHandData.CumulativeDelta.magnitude > manipulationStartMovementThreshold) { // Starting a manipulation will cancel an existing hold. if (editorHandData.HoldInProgress) { InputManager.Instance.RaiseHoldCanceled(this, editorHandData.HandId); editorHandData.HoldInProgress = false; } InputManager.Instance.RaiseManipulationStarted(this, editorHandData.HandId, editorHandData.CumulativeDelta); editorHandData.ManipulationInProgress = true; } // Holds are triggered by time. else if (!editorHandData.HoldInProgress && (time - editorHandData.FingerDownStartTime >= MaxClickDuration)) { InputManager.Instance.RaiseHoldStarted(this, editorHandData.HandId); editorHandData.HoldInProgress = true; } } else { InputManager.Instance.RaiseManipulationUpdated(this, editorHandData.HandId, editorHandData.CumulativeDelta); } } }
/// <summary> /// Updates the hand positional information. /// </summary> /// <param name="handSource">Hand source to use to update the position.</param> /// <param name="editorHandData">EditorHandData structure to update.</param> private void UpdateHandState(DebugInteractionSourceState handSource, EditorHandData editorHandData) { // Update hand position Vector3 handPosition; if (handSource.Properties.Location.TryGetPosition(out handPosition)) { editorHandData.HandDelta = handPosition - editorHandData.HandPosition; editorHandData.HandPosition = handPosition; } // Check for finger presses if (handSource.Pressed != editorHandData.IsFingerDownPending) { editorHandData.IsFingerDownPending = handSource.Pressed; editorHandData.FingerStateUpdateTimer = FingerPressDelay; } // Finger presses are delayed to mitigate issue with hand position shifting during air tap editorHandData.FingerStateChanged = false; if (editorHandData.FingerStateUpdateTimer > 0) { editorHandData.FingerStateUpdateTimer -= Time.deltaTime; if (editorHandData.FingerStateUpdateTimer <= 0) { editorHandData.IsFingerDown = editorHandData.IsFingerDownPending; editorHandData.FingerStateChanged = true; if (editorHandData.IsFingerDown) { editorHandData.FingerDownStartTime = Time.time; } } } SendHandStateEvents(editorHandData); }
/// <summary> /// Gets the hand data for the specified hand source if it already exists, otherwise creates it. /// </summary> /// <param name="sourceId">Hand source for which hands data should be retrieved.</param> /// <returns>The hand data requested.</returns> private EditorHandData GetOrAddHandData(uint sourceId) { EditorHandData handData; if (!handIdToData.TryGetValue(sourceId, out handData)) { handData = new EditorHandData(this, sourceId); handIdToData.Add(handData.HandId, handData); newHands.Add(handData.HandId); } return handData; }
private void Awake() { #if !UNITY_EDITOR Destroy(this); #endif manualHandControl = GetComponent<ManualHandControl>(); for (uint i = 0; i < editorHandsData.Length; i++) { editorHandsData[i] = new EditorHandData(this, i); } }