public TouchInputManager( dfInputManager manager )
 {
     this.manager = manager;
 }
            public void ProcessInput( dfInputManager manager, IInputAdapter adapter, Ray ray, dfControl control, bool retainFocusSetting )
            {

            var position = adapter.GetMousePosition();

            buttonsDown = dfMouseButtons.None;
            buttonsReleased = dfMouseButtons.None;
            buttonsPressed = dfMouseButtons.None;

            getMouseButtonInfo( adapter, ref buttonsDown, ref buttonsReleased, ref buttonsPressed );

            float scroll = adapter.GetAxis( scrollAxisName );
            if( !Mathf.Approximately( scroll, 0f ) )
            {
                // By default the mouse wheel is reported in increments of 0.1f,
                // which is just a useless number for UI, but this can be changed
                // by the user in the Unity Input Manager. We'll assume that if the
                // number reported is less than 1 then it is probably safe to
                // assume that we can massage it for UI purposes.
                scroll = Mathf.Sign( scroll ) * Mathf.Max( 1, Mathf.Abs( scroll ) );
            }

            mouseMoveDelta = position - lastPosition;
            lastPosition = position;

            #region Drag and drop

            if( dragState == dfDragDropState.Dragging )
            {

                if( buttonsReleased == dfMouseButtons.None )
                {

                    // Do nothing if the drag operation is over the source control
                    // and no buttons have been released.
                    if( control == activeControl )
                        return;

                    if( control != lastDragControl )
                    {

                        if( lastDragControl != null )
                        {
                            var dragArgs = new dfDragEventArgs( lastDragControl, dragState, dragData, ray, position );
                            lastDragControl.OnDragLeave( dragArgs );
                        }

                        if( control != null )
                        {
                            var dragArgs = new dfDragEventArgs( control, dragState, dragData, ray, position );
                            control.OnDragEnter( dragArgs );
                        }

                        lastDragControl = control;

                        return;

                    }

                    if( control != null )
                    {

                        if( mouseMoveDelta.magnitude > 1.0f )
                        {
                            var dragArgs = new dfDragEventArgs( control, dragState, dragData, ray, position );
                            control.OnDragOver( dragArgs );
                        }

                    }

                    return;

                }

                if( control != null && control != activeControl )
                {

                    var dragArgs = new dfDragEventArgs( control, dfDragDropState.Dragging, dragData, ray, position );
                    control.OnDragDrop( dragArgs );

                    // If there was no event consumer, or if the event consumer did not
                    // change the state from Dragging (which is not a valid state for
                    // a drop event) then just cancel the operation
                    if( !dragArgs.Used || dragArgs.State == dfDragDropState.Dragging )
                        dragArgs.State = dfDragDropState.Cancelled;

                    dragArgs = new dfDragEventArgs( activeControl, dragArgs.State, dragArgs.Data, ray, position );
                    dragArgs.Target = control;
                    activeControl.OnDragEnd( dragArgs );

                }
                else
                {
                    var cancelState = ( control == null ) ? dfDragDropState.CancelledNoTarget : dfDragDropState.Cancelled;
                    var dragArgs = new dfDragEventArgs( activeControl, cancelState, dragData, ray, position );
                    activeControl.OnDragEnd( dragArgs );
                }

                dragState = dfDragDropState.None;
                lastDragControl = null;
                activeControl = null;
                lastClickTime = 0f;
                lastHoverTime = 0f;
                lastPosition = position;

                return;

            }

            #endregion

            #region Mouse button pressed

            if( buttonsPressed != dfMouseButtons.None )
            {

                lastHoverTime = Time.realtimeSinceStartup + manager.hoverStartDelay;

                if( activeControl != null )
                {
                    // If a control has capture, forward all events to it
                    if( activeControl.transform.IsChildOf( manager.transform ) )
                    {
                        activeControl.OnMouseDown( new dfMouseEventArgs( activeControl, buttonsPressed, 0, ray, position, scroll ) );
                    }
                }
                else if( control == null || control.transform.IsChildOf( manager.transform ) )
                {

                    setActive( manager, control, position, ray );
                    if( control != null )
                    {
                        dfGUIManager.SetFocus( control );
                        control.OnMouseDown( new dfMouseEventArgs( control, buttonsPressed, 0, ray, position, scroll ) );
                    }
                    else if( !retainFocusSetting )
                    {
                        var focusControl = dfGUIManager.ActiveControl;
                        if( focusControl != null && focusControl.transform.IsChildOf( manager.transform ) )
                        {
                            focusControl.Unfocus();
                        }
                    }

                }

                if( buttonsReleased == dfMouseButtons.None )
                    return;

            }

            #endregion

            #region Mouse button released

            if( buttonsReleased != dfMouseButtons.None )
            {

                lastHoverTime = Time.realtimeSinceStartup + manager.hoverStartDelay;

                // Mouse up without a control having capture is ignored
                if( activeControl == null )
                {
                    setActive( manager, control, position, ray );
                    return;
                }

                // If the mouse button is released over the same control it was pressed on,
                // the Click event gets generated (in addition to MouseUp)
                if( activeControl == control && buttonsDown == dfMouseButtons.None )
                {

                    var p2u = activeControl.PixelsToUnits();
                    var startPosition = activeControlPosition / p2u;
                    var currentPosition = activeControl.transform.position / p2u;

                    // Don't fire click events if the control has been moved since the mouse was down
                    if( Vector3.Distance( startPosition, currentPosition ) <= 1 )
                    {

                        if( Time.realtimeSinceStartup - lastClickTime < DOUBLECLICK_TIME )
                        {
                            lastClickTime = 0f;
                            activeControl.OnDoubleClick( new dfMouseEventArgs( activeControl, buttonsReleased, 1, ray, position, scroll ) );
                        }
                        else
                        {
                            lastClickTime = Time.realtimeSinceStartup;
                            activeControl.OnClick( new dfMouseEventArgs( activeControl, buttonsReleased, 1, ray, position, scroll ) );
                        }

                    }

                }

                // Let the last control know that the button was released whether it was
                // released over the control or not
                activeControl.OnMouseUp( new dfMouseEventArgs( activeControl, buttonsReleased, 0, ray, position, scroll ) );

                // If all buttons are up, then we need to reset the mouse state
                if( buttonsDown == dfMouseButtons.None && activeControl != control )
                {
                    setActive( manager, null, position, ray );
                }

                return;

            }

            #endregion

            #region Doesn't matter if buttons are down or not

            if( activeControl != null && activeControl == control )
            {

                if( mouseMoveDelta.magnitude == 0 && Time.realtimeSinceStartup - lastHoverTime > manager.hoverNotifactionFrequency )
                {
                    activeControl.OnMouseHover( new dfMouseEventArgs( activeControl, buttonsDown, 0, ray, position, scroll ) );
                    lastHoverTime = Time.realtimeSinceStartup;
                }

            }

            #endregion

            #region No buttons down

            if( buttonsDown == dfMouseButtons.None )
            {

                if( scroll != 0 && control != null )
                {
                    setActive( manager, control, position, ray );
                    control.OnMouseWheel( new dfMouseEventArgs( control, buttonsDown, 0, ray, position, scroll ) );
                    return;
                }

                setActive( manager, control, position, ray );

            }

            #endregion

            #region Some buttons down

            else if( buttonsDown != dfMouseButtons.None ) // Some buttons are down
            {

                if( activeControl != null )
                {

                    // Special case: Another control with a higher RenderOrder is now under the mouse.
                    // This can happen when a control moves, such as when you click on a slider and the
                    // thumb position is updated to be under the mouse (when it wasn't previously)
                    if( control != null && control.RenderOrder > activeControl.RenderOrder )
                    {
                        // TODO: What to do about this when a control has capture?
                    }

                    // If the mouse was moved notify the control, otherwise nothing to do
                    // NOTE: This is similar to "mouse capture" on Windows Forms
                    if( mouseMoveDelta.magnitude >= DRAG_START_DELTA )
                    {

                        if( ( buttonsDown & ( dfMouseButtons.Left | dfMouseButtons.Right ) ) != 0 && dragState != dfDragDropState.Denied )
                        {
                            var dragArgs = new dfDragEventArgs( activeControl ) { Position = position };
                            activeControl.OnDragStart( dragArgs );
                            if( dragArgs.State == dfDragDropState.Dragging )
                            {
                                dragState = dfDragDropState.Dragging;
                                dragData = dragArgs.Data;
                                return;
                            }
                            else
                            {
                                dragState = dfDragDropState.Denied;
                            }
                        }

                    }

                }

            }

            #endregion

            if( activeControl != null && mouseMoveDelta.magnitude >= 1 )
            {
                var moveArgs = new dfMouseEventArgs( activeControl, buttonsDown, 0, ray, position, scroll ) { MoveDelta = mouseMoveDelta };
                activeControl.OnMouseMove( moveArgs );
            }
        }
        private void setActive( dfInputManager manager, dfControl control, Vector2 position, Ray ray )
        {
            if( activeControl != null && activeControl != control )
            {
                activeControl.OnMouseLeave( new dfMouseEventArgs( activeControl ) { Position = position, Ray = ray } );
            }

            if( control != null && control != activeControl )
            {
                lastClickTime = 0f;
                lastHoverTime = Time.realtimeSinceStartup + manager.hoverStartDelay;
                control.OnMouseEnter( new dfMouseEventArgs( control ) { Position = position, Ray = ray } );
            }

            activeControl = control;
            activeControlPosition = ( control != null ) ? control.transform.position : Vector3.one * float.MinValue;
            lastPosition = position;
            dragState = dfDragDropState.None;
        }
 public ControlTouchTracker( dfInputManager manager, dfControl control )
 {
     this.manager = manager;
     this.control = control;
     this.controlStartPosition = control.transform.position;
 }
예제 #5
0
 public ControlTouchTracker( dfInputManager manager, dfControl control )
 {
     this.manager = manager;
     this.control = control;
 }
예제 #6
0
    private void CreateUI()
    {
        // Make sure other cameras already in the scene don't render the designated layer
        var sceneCameras = FindObjectsOfType(typeof(Camera)) as Camera[];

        for (int i = 0; i < sceneCameras.Length; i++)
        {
            var sceneCamera = sceneCameras[i];
            if (sceneCamera.gameObject.activeInHierarchy && sceneCamera.GetComponent <dfGUICamera>() == null)
            {
                sceneCameras[i].cullingMask &= ~(1 << layer);
                sceneCameras[i].eventMask   &= ~(1 << layer);
                EditorUtility.SetDirty(sceneCameras[i]);
            }
        }

        GameObject go = new GameObject("UI Root");

        go.transform.position = new Vector3(-100, 100, 0);
        go.layer = layer;

        GameObject cam_go = new GameObject("UI Camera");

        cam_go.transform.parent        = go.transform;
        cam_go.transform.localPosition = Vector3.zero;
        cam_go.transform.localRotation = Quaternion.identity;

        Camera cam = cam_go.AddComponent <Camera>();

        cam.depth          = getGuiCameraDepth();
        cam.farClipPlane   = 5;
        cam.clearFlags     = CameraClearFlags.Depth;
        cam.cullingMask    = (1 << layer);
        cam.isOrthoGraphic = orthographic;

        dfGUIManager guiManager = go.AddComponent <dfGUIManager>();

        guiManager.RenderCamera     = cam;
        guiManager.PixelPerfectMode = pixelPerfect;

        dfInputManager inputManager = go.GetComponent <dfInputManager>();

        inputManager.RenderCamera        = cam;
        inputManager.UseJoystick         = useJoystick;
        inputManager.JoystickClickButton = joystickClickButton;
        inputManager.HorizontalAxis      = horizontalAxis;
        inputManager.VerticalAxis        = verticalAxis;

#if WEB_PLAYER
        guiManager.FixedHeight         = PlayerSettings.defaultWebScreenHeight;
        guiManager.RenderCamera.aspect = (float)PlayerSettings.defaultWebScreenWidth / (float)PlayerSettings.defaultWebScreenHeight;
#else
        guiManager.FixedHeight         = PlayerSettings.defaultScreenHeight;
        guiManager.RenderCamera.aspect = (float)PlayerSettings.defaultScreenWidth / (float)PlayerSettings.defaultScreenHeight;
#endif

        dfEditorUtil.DelayedInvoke(() =>
        {
            Selection.activeObject = guiManager;

            var scene = SceneView.currentDrawingSceneView ?? SceneView.lastActiveSceneView;
            if (scene != null)
            {
                scene.orthographic = true;
                scene.pivot        = guiManager.transform.position;
                scene.AlignViewToObject(guiManager.transform);
            }
        });

        this.Close();
    }
예제 #7
0
 public ControlTouchTracker(dfInputManager manager, dfControl control)
 {
     this.manager = manager;
     this.control = control;
 }
예제 #8
0
 public TouchInputManager(dfInputManager manager)
 {
     this.manager = manager;
 }