public void OnGUI() { if (editorOnly && !Application.isEditor) { return; } if (input == null) { var inputManager = GetComponent <dfInputManager>(); if (inputManager == null) { Debug.LogError("No dfInputManager instance found", this); this.enabled = false; return; } if (inputManager.UseTouch) { input = inputManager.TouchInputSource; if (input == null) { Debug.LogError("No dfTouchInputSource component found", this); this.enabled = false; return; } } else { if (Application.isPlaying) { this.enabled = false; } return; } } if (showPlatformInfo) { var rect = new Rect(5, 0, 800, 25); GUI.Label(rect, "Touch Source: " + input + ", Platform: " + Application.platform); } if (showMouse && !Application.isEditor) { drawTouchIcon(Input.mousePosition); } var count = input.TouchCount; for (int i = 0; i < count; i++) { var touch = input.GetTouch(i); drawTouchIcon(touch.position); } }
public void OnGUI() { if( editorOnly && !Application.isEditor ) return; if( input == null ) { var inputManager = GetComponent<dfInputManager>(); if( inputManager == null ) { Debug.LogError( "No dfInputManager instance found", this ); this.enabled = false; return; } input = inputManager.TouchInputSource; if( input == null ) { Debug.LogError( "No dfTouchInputSource component found", this ); this.enabled = false; return; } } if( showPlatformInfo ) { var rect = new Rect( 5, 0, 800, 25 ); GUI.Label( rect, "Touch Source: " + input + ", Platform: " + Application.platform ); } if( showMouse && !Application.isEditor ) { drawTouchIcon( Input.mousePosition ); } var count = input.TouchCount; for( int i = 0; i < count; i++ ) { var touch = input.GetTouch( i ); drawTouchIcon( touch.position ); } }
internal void Process( Transform transform, Camera renderCamera, IDFTouchInputSource input, bool retainFocusSetting ) { controlUnderMouse = null; var touches = input.Touches; for( int i = 0; i < touches.Count; i++ ) { // Dereference Touch information var touch = touches[ i ]; // Keep track of the last control under the "mouse" var touchedControl = dfGUIManager.HitTestAll( touch.position ); if( touchedControl != null && touchedControl.transform.IsChildOf( manager.transform ) ) { controlUnderMouse = touchedControl; } #region Don't track touches on empty space if( controlUnderMouse == null ) { if( touch.phase == TouchPhase.Began ) { if( !retainFocusSetting && untracked.Count == 0 ) { var focusControl = dfGUIManager.ActiveControl; if( focusControl != null && focusControl.transform.IsChildOf( manager.transform ) ) { focusControl.Unfocus(); } } untracked.Add( touch.fingerId ); continue; } } if( untracked.Contains( touch.fingerId ) ) { if( touch.phase == TouchPhase.Ended ) untracked.Remove( touch.fingerId ); continue; } #endregion var ray = renderCamera.ScreenPointToRay( touch.position ); var info = new TouchRaycast( controlUnderMouse, touch, ray ); var captured = tracked.FirstOrDefault( x => x.IsTrackingFinger( info.FingerID ) ); if( captured != null ) { captured.Process( info ); continue; } var processed = false; for( int x = 0; x < tracked.Count; x++ ) { if( tracked[ x ].Process( info ) ) { processed = true; break; } } if( !processed && controlUnderMouse != null ) { if( !tracked.Any( x => x.control == controlUnderMouse ) ) { var newTracker = new ControlTouchTracker( manager, controlUnderMouse ); tracked.Add( newTracker ); newTracker.Process( info ); } } } }
private bool processTouchInput() { if( touchInputSource == null ) { // Attempt first to find an attached component that will act as the // touch input source. var inputSources = GetComponents<dfTouchInputSourceComponent>().OrderByDescending( x => x.Priority ).ToArray(); for( int i = 0; i < inputSources.Length; i++ ) { var component = inputSources[ i ]; if( !component.enabled ) continue; touchInputSource = component.Source; if( touchInputSource != null ) break; } // If still no touch input source assigned, assign default if( touchInputSource == null ) { touchInputSource = dfMobileTouchInputSource.Instance; } } touchInputSource.Update(); var touchCount = touchInputSource.TouchCount; if( touchCount == 0 ) return false; this.touchHandler.Process( this.transform, renderCamera, touchInputSource, retainFocus ); return true; }
internal void Process( Transform transform, Camera renderCamera, IDFTouchInputSource input, bool retainFocus ) { var touches = input.Touches; for( int i = 0; i < touches.Count; i++ ) { // Dereference Touch information var touch = touches[ i ]; // Raycast from touch position to find the top-most control under the touch var ray = renderCamera.ScreenPointToRay( touch.position ); var maxDistance = renderCamera.farClipPlane - renderCamera.nearClipPlane; var hits = Physics.RaycastAll( ray, maxDistance, renderCamera.cullingMask ); // Keep track of the last control under the "mouse" controlUnderMouse = clipCast( transform, hits ); #region Don't track touches on empty space if( controlUnderMouse == null ) { if( touch.phase == TouchPhase.Began ) { untracked.Add( touch.fingerId ); continue; } } if( untracked.Contains( touch.fingerId ) ) { if( touch.phase == TouchPhase.Ended ) untracked.Remove( touch.fingerId ); continue; } #endregion var info = new TouchRaycast( controlUnderMouse, touch, ray ); var captured = tracked.FirstOrDefault( x => x.IsTrackingFinger( info.FingerID ) ); if( captured != null ) { captured.Process( info ); continue; } var processed = false; for( int x = 0; x < tracked.Count; x++ ) { if( tracked[ x ].Process( info ) ) { processed = true; break; } } if( !processed && controlUnderMouse != null ) { if( !tracked.Any( x => x.control == controlUnderMouse ) ) { var newTracker = new ControlTouchTracker( manager, controlUnderMouse ); tracked.Add( newTracker ); newTracker.Process( info ); } } } }