/// <summary> /// Method that can be invoked if external factors (e.g. alternate input modality preemptively invoked the target) force the dwell action to prematurely end /// </summary> public virtual void CancelDwell() { DwellCanceled.Invoke(pointer); focusEnterTime = DateTime.MaxValue; CurrentDwellState = DwellStateType.None; focusExitTime = DateTime.MaxValue; FillTimer = 0; }
public void OnFocusChanged(FocusEventData eventData) { if (eventData.NewFocusedObject == gameObject && eventData.Pointer.InputSourceParent.SourceType == dwellProfile.DwellPointerType) { if (!HasFocus) { HasFocus = true; // check intent to resume if (CurrentDwellState == DwellStateType.DwellCanceled && (DateTime.UtcNow - focusExitTime) <= dwellProfile.TimeToAllowDwellResume) { // Add the time duration focus was away since this is a dwell resume and we need to account for the time that focus was lost for the target. // Assigning this the current time would restart computation for dwell progress. focusEnterTime = focusEnterTime.AddSeconds((DateTime.UtcNow - focusExitTime).TotalSeconds); CurrentDwellState = DwellStateType.DwellStarted; DwellStarted.Invoke(pointer); } // dwell state machine re-starts else if (CurrentDwellState <= DwellStateType.DwellIntended) { focusEnterTime = DateTime.UtcNow; CurrentDwellState = DwellStateType.FocusGained; pointer = eventData.Pointer; FillTimer = 0; } } pointerCount++; } else if (eventData.OldFocusedObject == gameObject && eventData.Pointer.InputSourceParent.SourceType == dwellProfile.DwellPointerType) { pointerCount--; if (pointerCount == 0) { HasFocus = false; if (CurrentDwellState == DwellStateType.DwellStarted) { DwellCanceled.Invoke(eventData.Pointer); CurrentDwellState = DwellStateType.DwellCanceled; focusExitTime = DateTime.UtcNow; } else { CurrentDwellState = DwellStateType.None; focusExitTime = DateTime.MaxValue; } } } }
public void OnFocusExit(FocusEventData eventData) { if (eventData.OldFocusedObject == gameObject && eventData.Pointer.InputSourceParent.SourceType == dwellProfile.DwellPointerType && pointer.InputSourceParent.SourceId == eventData.Pointer.InputSourceParent.SourceId) { HasFocus = false; if (CurrentDwellState == DwellStateType.DwellStarted) { DwellCanceled.Invoke(eventData.Pointer); CurrentDwellState = DwellStateType.DwellCanceled; focusExitTime = DateTime.UtcNow; } else { CurrentDwellState = DwellStateType.None; focusExitTime = DateTime.MaxValue; } } }