示例#1
0
    // UITouchWrapper handlers
    public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
    {
        base.onTouchBegan( touch, touchPos );

        if( onlyFireStartAndEndEvents && onActivationStarted != null )
            onActivationStarted( this );
    }
示例#2
0
    // UITouchWrapper handlers
    public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
    {
        base.onTouchBegan( touch, touchPos );

        _zoomInAnimation.restartStartToCurrent();
        UI.instance.StartCoroutine( _zoomInAnimation.animate() );
    }
示例#3
0
    public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
    {
        base.onTouchEnded( touch, touchPos, touchWasInsideTouchFrame );

        if( onlyFireStartAndEndEvents && onActivationEnded != null )
            onActivationEnded( this );
    }
示例#4
0
 public void resetWithTouch( UITouchWrapper touch )
 {
     // Initialize the detectionState only with the swipe types we want to listen for
     swipeDetectionState = swipesToDetect;
     startPoint = touch.position;
     startTime = Time.time;
     swipeDetectionStatus = SwipeDetectionStatus.Waiting;
 }
示例#5
0
    public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
    {
        if( touchInfoArray[touch.fingerId] == null )
            touchInfoArray[touch.fingerId] = new TouchInfo( swipesToDetect );

        // Reset the TouchInfo with the current touch
        touchInfoArray[touch.fingerId].resetWithTouch( touch );
    }
示例#6
0
    public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
    {
        base.onTouchEnded( touch, touchPos, touchWasInsideTouchFrame );

        _zoomInAnimation.stop();
        _zoomOutAnimation.restartStartToCurrent();
        UI.instance.StartCoroutine( _zoomOutAnimation.animate() );
    }
示例#7
0
    // UITouchWrapper handlers
    public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
    {
        highlighted = true;

        Color oldColor = colorPicked;
        Vector2 textureCoord = getTouchTextureCoords( touchPos );
        colorPicked = getColorForPixel( (int)textureCoord.x, (int)textureCoord.y );

        if( onColorChangeBegan != null )
            onColorChangeBegan( this, colorPicked, oldColor );
    }
    public override void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
    {
        // increment deltaTouch so we can pass on the touch if necessary
        _deltaTouch += touch.deltaPosition.x;
        _lastTouch = touch;

        // once we move too far unhighlight and stop tracking the touchable
        if( _activeTouchable != null && Mathf.Abs( _deltaTouch ) > TOUCH_MAX_DELTA_FOR_ACTIVATION )
        {
            _activeTouchable.onTouchEnded( touch, touchPos, true );
            _activeTouchable = null;
        }

        var newOffset = _scrollPosition + touch.deltaPosition.x;

        // are we dragging above/below the scrollables boundaries?
        _isDraggingPastExtents = ( newOffset > 0 || newOffset < _minEdgeInset.x );

        // if we are dragging past our extents dragging is no longer 1:1. we apply an exponential falloff
        if( _isDraggingPastExtents )
        {
            // how far from the top/bottom are we?
            var distanceFromSource = 0f;

            if( newOffset > 0 ) // stretching down
                distanceFromSource = newOffset;
            else
                distanceFromSource = Mathf.Abs( _contentWidth + newOffset - width );

            // we need to know the percentage we are from the source
            var percentFromSource = distanceFromSource / width;

            // apply exponential falloff so that the further we are from source the less 1 pixel drag actually goes
            newOffset = _scrollPosition + ( touch.deltaPosition.x * Mathf.Pow( 0.04f, percentFromSource ) );
        }

        _scrollPosition = newOffset;
        layoutChildren();

        // pop any extra velocities and push the current velocity onto the stack
        if( _velocities.Count == TOTAL_VELOCITY_SAMPLE_COUNT )
            _velocities.Dequeue();
        _velocities.Enqueue( touch.deltaPosition.x / Time.deltaTime );
    }
示例#9
0
    public static UITouchWrapper createTouchFromInput( UIMouseState mouseState, ref Vector2? lastMousePosition )
    {
        //var self = new UITouchWrapper();
        //ValueType valueSelf = self;
        //var type = typeof( UITouchWrapper );

        var self = new UITouchWrapper();

        var currentMousePosition = new Vector2( Input.mousePosition.x, Input.mousePosition.y );

        if(lastMousePosition.HasValue)
        // if we have a lastMousePosition use it to get a delta
        if( lastMousePosition.HasValue ) self.deltaPosition = currentMousePosition - (Vector2)lastMousePosition;
            //type.GetField( "m_PositionDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, currentMousePosition - lastMousePosition );

        if( mouseState == UIMouseState.DownThisFrame ) // equivalent to touchBegan
        {
            //type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Began );
            self.phase = TouchPhase.Began;
            lastMousePosition = Input.mousePosition;
        }
        else if( mouseState == UIMouseState.UpThisFrame ) // equivalent to touchEnded
        {
            //type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Ended );
            self.phase = TouchPhase.Ended;
            lastMousePosition = null;
        }
        else // UIMouseState.HeldDown - equivalent to touchMoved/Stationary
        {
            //type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Moved );
            self.phase = TouchPhase.Moved;
            lastMousePosition = Input.mousePosition;
        }

        //type.GetField( "m_Position", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, currentMousePosition );
        self.position = currentMousePosition;

        return self;
        //return (UITouchWrapper)valueSelf;
    }
示例#10
0
    public static UITouchWrapper createTouch( int finderId, int tapCount, Vector2 position, Vector2 deltaPos, float timeDelta, TouchPhase phase )
    {
        var self = new UITouchWrapper();
        //ValueType valueSelf = self;
        //var type = typeof( UITouchWrapper );
        /*
        type.GetField( "m_FingerId", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, finderId );
        type.GetField( "m_TapCount", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, tapCount );
        type.GetField( "m_Position", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, position );
        type.GetField( "m_PositionDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, deltaPos );
        type.GetField( "m_TimeDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, timeDelta );
        type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, phase );

        return (UITouchWrapper)valueSelf;
        */

        self.fingerId = finderId;
        self.tapCount = tapCount;
        self.position = position;
        self.deltaPosition = deltaPos;
        self.deltaTime = timeDelta;
        self.phase = phase;
        return self;
    }
示例#11
0
    // UITouchWrapper handlers
    public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
    {
        highlighted = true;

        initialTouchPosition = touch.position;

        if( touchDownSound != null )
            UI.instance.playSound( touchDownSound );

        if( onTouchDown != null )
            onTouchDown( this );
    }
示例#12
0
    public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
    {
        if( touchCount == 0 )
            highlighted = false;

        if( onChange != null )
            onChange( this, _value );
    }
示例#13
0
 public override void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
 {
     this.layoutJoystick( this.inverseTranformPoint( touchPos ) );
 }
示例#14
0
    public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
    {
        // Set highlighted to avoid calling super
        highlighted = false;

        // Reset back to default state
        this.resetJoystick();
    }
示例#15
0
 public override void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
 {
     this.updateKnobForTouchPosition( touchPos );
 }
示例#16
0
    public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
    {
        highlighted = true;

        this.updateKnobForTouchPosition( touchPos );
    }
示例#17
0
    // examines a touch and sends off began, moved and ended events
    private void lookAtTouch( UITouchWrapper touch )
    {
        // tranform the touch position so the origin is in the top left
        var fixedTouchPosition = new Vector2( touch.position.x, Screen.height - touch.position.y );
        var button = getButtonForScreenPosition( fixedTouchPosition );

        bool touchEnded = ( touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled );

        if( touch.phase == TouchPhase.Began )
        {
            if( button != null )
            {
                _spriteSelected[touch.fingerId] = button;
                button.onTouchBegan( touch, fixedTouchPosition );
            }
            else
            {
                // deselect any selected sprites for this touch
                _spriteSelected[touch.fingerId] = null;
            }
        }
        else if( touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary )
        {
            if( button != null && _spriteSelected[touch.fingerId] == button )
            {
                // stationary should get touchMoved as well...I think...still testing all scenarious
                // if we have a moving touch on a sprite keep sending touchMoved
                _spriteSelected[touch.fingerId].onTouchMoved( touch, fixedTouchPosition );
            }
            else if( _spriteSelected[touch.fingerId] != null )
            {
                // If we have a button that isn't the selected button end the touch on it because we moved off of it
                _spriteSelected[touch.fingerId].onTouchEnded( touch, fixedTouchPosition, false );
                _spriteSelected[touch.fingerId] = null;
            }
            else if( button != null && _spriteSelected[touch.fingerId] == null && button.allowTouchBeganWhenMovedOver )
            {
                // this happens when we started a touch not over a button then the finger slid over the button. if the
                // allowTouchBeganWhenMovedOver property is true, we count this as a touchBegan
                _spriteSelected[touch.fingerId] = button;
                button.onTouchBegan( touch, fixedTouchPosition );
            }
        }
        else if( touchEnded )
        {
            if( button != null )
            {
                // If we are getting an exit over a previously selected button send it an onTouchEnded
                if( _spriteSelected[touch.fingerId] != button && _spriteSelected[touch.fingerId] != null )
                {
                    _spriteSelected[touch.fingerId].onTouchEnded( touch, fixedTouchPosition, false );
                }
                else if( _spriteSelected[touch.fingerId] == button )
                {
                    _spriteSelected[touch.fingerId].onTouchEnded( touch, fixedTouchPosition, true );
                }

                // Deselect the touched sprite
                _spriteSelected[touch.fingerId] = null;
            }
            else if(_spriteSelected[touch.fingerId] != null)
            {
                // If we have a button that isn't the selected button end the touch on it because we moved off of it
                // quickly enough that we never got a TouchPhase.Moved or TouchPhase.Stationary
                _spriteSelected[touch.fingerId].onTouchEnded( touch, fixedTouchPosition, false );
                _spriteSelected[touch.fingerId] = null;
            }
        }
    }
示例#18
0
 protected UITouchWrapper wrapTouchInput(Touch input)
 {
     var newTouch = new UITouchWrapper();
     newTouch.deltaTime = input.deltaTime;
     newTouch.deltaPosition = input.deltaPosition;
     newTouch.position = input.position;
     newTouch.phase = input.phase;
     newTouch.fingerId = input.fingerId;
     newTouch.tapCount = input.tapCount;
     newTouch.locked = true;
     return newTouch;
 }
示例#19
0
 public virtual void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
 {
     highlighted = true;
 }
示例#20
0
 public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
 {
     highlighted = false;
 }
示例#21
0
 // UITouchWrapper handlers
 public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
 {
     highlighted = true;
 }
示例#22
0
    public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
    {
        // If someone has un-highlighted us through code we are deactivated
        // and should not fire the event
        if (!highlighted)
            return;

        highlighted = false;

        if (onTouchUp != null)
            onTouchUp(this);

        // If the touch was inside our touchFrame and we have an action, call it
        if( touchWasInsideTouchFrame && onTouchUpInside != null )
            onTouchUpInside( this );
    }
示例#23
0
    public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
    {
        if( touchWasInsideTouchFrame )
        {
            _state++;
            adjustForStateRollover( _state );
        }

        base.onTouchEnded( touch, touchPos, touchWasInsideTouchFrame );

        if( touchWasInsideTouchFrame )
        {
            setFramesForState( _state );

            // If the touch was inside our touchFrame and we have an action, call it
            if( onStateChange != null )
                onStateChange( this , _state);
        }
    }
示例#24
0
    public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
    {
        if (currentTouchId != -1)
            return;

        currentTouchId = touch.fingerId;

        touchPos.y = -touchPos.y;

        highlighted = true;

        // Re-center joystick pad
        displayJoystick(touchPos);

        this.layoutJoystick( this.inverseTranformPoint(touchPos - _joystickCenter));

        // If we have a highlightedUVframe, swap it in
        if( highlightedUVframe != UIUVRect.zero )
            _joystickSprite.uvFrame = highlightedUVframe;
    }
示例#25
0
    public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
    {
        highlighted = false;

        if( onKnobChanged != null )
            onKnobChanged( this, _value );
    }
示例#26
0
    public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
    {
        highlighted = true;

        this.layoutJoystick( this.inverseTranformPoint( touchPos ) );

        // If we have a highlightedUVframe, swap it in
        if( highlightedUVframe != UIUVRect.zero )
            _joystickSprite.uvFrame = highlightedUVframe;
    }
示例#27
0
    public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
    {
        if (touch.fingerId != currentTouchId)
            return;

        // Set highlighted to avoid calling super
        highlighted = false;

        // Reset back to default state
        this.resetJoystick();

        currentTouchId = -1;
    }
示例#28
0
 public virtual void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
 {
 }
示例#29
0
 public override void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
 {
     // dont fire this continously if we were asked to only fire start and end
     if( !onlyFireStartAndEndEvents && onTouchIsDown != null )
         onTouchIsDown( this );
 }
示例#30
0
    public override void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
    {
        if (touch.fingerId != currentTouchId)
            return;

        touchPos.y = -touchPos.y;

        this.layoutJoystick(this.inverseTranformPoint(touchPos - _joystickCenter));
    }