Exemplo n.º 1
0
 public void GesturePanRecognized(TKPanRecognizer r)
 {
     if (this.OnGesturePanRecognized != null)
     {
         this.OnGesturePanRecognized(r);
     }
 }
Exemplo n.º 2
0
    public void OnPanCamera(TKPanRecognizer t)
    {
        if (lineEditMode != LineEditMode.Camera)
        {
            return;
        }

        CameraManager.main.PanCamera(-t.deltaTranslation * CameraManager.main.panSpeed);
    }
        private void OnPan(TKPanRecognizer recognizer)
        {
            var delta   = recognizer.deltaTranslation;
            var handler = OnPanHandler;

            if (handler == null)
            {
                return;
            }
            handler(delta);
        }
Exemplo n.º 4
0
    public void InitTouchControl()
    {
        var recognizer = new TKPanRecognizer();

        //recognizer.boundaryFrame = new TKRect(50f, 0,public GameObject ColorPicker;
        //public Material ColorPickerMaterial; 100f, 100f);

        // when using in conjunction with a pinch or rotation recognizer setting the min touches to 2 smoothes movement greatly
        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            recognizer.minimumNumberOfTouches = 2;
        }

        recognizer.gestureRecognizedEvent += (r) =>
        {
            //Camera.main.transform.position -= new Vector3(recognizer.deltaTranslation.x, recognizer.deltaTranslation.y) / 100;
            //Debug.Log("pan recognizer fired: " + r);
            //Debug.Log(recognizer.touchLocation());
            //Debug.Log(recognizer.state);
            if (!EventSystem.current.IsPointerOverGameObject() || true)
            {
                if (IsDrawing == false)
                {
                    clone     = (GameObject)Instantiate(LineObject);
                    clone.tag = "ARLines";
                    clone.GetComponent <LineRenderer>().material = CurrentMaterial;
                    clone.transform.parent = DrawSpace.transform;

                    line = clone.GetComponent <LineRenderer>();
                    //line.material.color = Color.white;
                    line.startWidth = LineWidth;
                    line.endWidth   = LineWidth;
                    LineDividNumber = 0;
                    IsDrawing       = true;
                }
                else
                {
                    LineDividNumber++;
                    line.positionCount = LineDividNumber;
                    Vector2 touchLocation = recognizer.touchLocation();
                    line.SetPosition(LineDividNumber - 1, TargetCamera.ScreenToWorldPoint(new Vector3(touchLocation.x, touchLocation.y, DrawOffset)));
                }
            }
        };

        // continuous gestures have a complete event so that we know when they are done recognizing
        recognizer.gestureCompleteEvent += r =>
        {
            Debug.Log("pan gesture complete");
            IsDrawing = false;
        };
        TouchKit.addGestureRecognizer(recognizer);
    }
Exemplo n.º 5
0
    void Start()
    {
        _statsDetail = FindObjectOfType <StatsDetail>();
        var recognizer = new TKPanRecognizer();

        recognizer.gestureRecognizedEvent += (r) =>
        {
            transform.Rotate(transform.up, -0.1f * recognizer.deltaTranslation.x);
            _statsDetail.transform.localScale = Vector3.zero;
        };
        TouchKit.addGestureRecognizer(recognizer);
    }
        public TouchKitInputSystem()
        {
            panRecognizer      = new TKPanRecognizer();
            pinchRecognizer    = new TKPinchRecognizer();
            rotationRecognizer = new TKRotationRecognizer();

            panRecognizer.gestureRecognizedEvent      += OnPan;
            pinchRecognizer.gestureRecognizedEvent    += OnPinch;
            rotationRecognizer.gestureRecognizedEvent += OnRotation;

            TouchKit.addGestureRecognizer(panRecognizer);
            TouchKit.addGestureRecognizer(pinchRecognizer);
            TouchKit.addGestureRecognizer(rotationRecognizer);
        }
Exemplo n.º 7
0
        protected void Awake()
        {
            this.m_unityEventSystem = base.GetComponent <EventSystem>();
            this.m_usesTouch        = this.UnityEventSystem.currentInputModule is TouchInputModule;
            float num = (Screen.dpi != 0f) ? Screen.dpi : 72f;

            this.m_unityEventSystem.pixelDragThreshold = Mathf.FloorToInt(num * 0.1f);
            this.TouchKit = base.gameObject.AddComponent <TouchKit>();
            this.TouchKit.autoScaleRectsAndDistances = true;
            this.TouchKit.shouldAutoUpdateTouches    = true;
            this.TouchKit.maxTouchesToProcess        = 1;
            this.TouchKit.drawDebugBoundaryFrames    = !ConfigApp.ProductionBuild;
            this.TouchKit.drawTouches        = !ConfigApp.ProductionBuild;
            this.TouchKit.simulateTouches    = Application.isEditor;
            this.TouchKit.simulateMultitouch = Application.isEditor;
            TKSwipeRecognizer recognizer = new TKSwipeRecognizer(0.2f);

            recognizer.gestureRecognizedEvent += delegate(TKSwipeRecognizer r) {
                if (this.InputEnabled && (PlayerView.Binder.EventBus != null))
                {
                    PlayerView.Binder.EventBus.GestureSwipeRecognized(r);
                }
            };
            TouchKit.addGestureRecognizer(recognizer);
            TKPanRecognizer recognizer2 = new TKPanRecognizer(0.05f);

            recognizer2.gestureRecognizedEvent += delegate(TKPanRecognizer r) {
                if (this.InputEnabled && (PlayerView.Binder.EventBus != null))
                {
                    PlayerView.Binder.EventBus.GesturePanRecognized(r);
                }
            };
            recognizer2.gestureCompleteEvent += delegate(TKPanRecognizer r) {
                if (this.InputEnabled && (PlayerView.Binder.EventBus != null))
                {
                    PlayerView.Binder.EventBus.GesturePanCompleted(r);
                }
            };
            TouchKit.addGestureRecognizer(recognizer2);
            TKTapRecognizer recognizer3 = new TKTapRecognizer(0.4f, 0.5f);

            recognizer3.gestureRecognizedEvent += delegate(TKTapRecognizer r) {
                if (this.InputEnabled && (PlayerView.Binder.EventBus != null))
                {
                    PlayerView.Binder.EventBus.GestureTapRecognized(r);
                }
            };
            TouchKit.addGestureRecognizer(recognizer3);
        }
Exemplo n.º 8
0
        private void OnPanComplete(TKPanRecognizer recognizer)
        {
            if (!_scrollEnabled)
            {
                return;
            }

            _isPanning = false;

            // TODO: make configurable
            var delta             = recognizer.deltaTranslation.y;
            var velocityMagnitude = Mathf.Abs(delta) < 5f ? 0f : Mathf.Clamp(delta, -50f, 50f);

            _panVelocity = Vector3.up * velocityMagnitude / VelocityScalingFactor;
        }
    void addPanGestureRecognizer()
    {
        panRecognizer = new TKPanRecognizer();
        panRecognizer.gestureRecognizedEvent += (r) =>
        {
            //print("Touch delta is " + r.deltaTranslation.y);
            //print("Touch delta cm is " + r.deltaTranslationCm);
            print("Scale" + transform.localScale.y + 0.1f * r.deltaTranslation.y);
            float yScale = Mathf.Max(transform.localScale.y + 0.1f * r.deltaTranslation.y, 1.0f);
            transform.localScale = new Vector3(transform.localScale.x, yScale, 0);
            //Debug.Log(r);
        };

        panRecognizer.gestureCompleteEvent += r =>
        {
            Debug.Log("pan gesture complete");
        };

        TouchKit.addGestureRecognizer(panRecognizer);
    }
Exemplo n.º 10
0
        private void OnPan(TKPanRecognizer recognizer)
        {
            if (!_scrollEnabled)
            {
                return;
            }

            _isPanning = true;

            _panVelocity    = Vector2.zero;
            _magnetVelocity = Vector2.zero;

            // TODO: make configurable
            const float scalingFactor = 100f;

            transform.Translate(Vector3.up * recognizer.deltaTranslation.y / scalingFactor);

            var clampedPos = Mathf.Clamp(transform.position.y, _listBottom, _listTop);

            transform.position = new Vector2(transform.position.x, clampedPos);
        }
Exemplo n.º 11
0
        private void Start()
        {
            var panRecognizer = new TKPanRecognizer();

            panRecognizer.gestureRecognizedEvent += OnPan;
            panRecognizer.gestureCompleteEvent   += OnPanComplete;
            TouchKit.addGestureRecognizer(panRecognizer);

            var tapRecognizer = new TKTapRecognizer();

            tapRecognizer.gestureRecognizedEvent += OnTap;
            TouchKit.addGestureRecognizer(tapRecognizer);

            // Start with the saved start level
            _selectedLevel = Levels.CurrentLevelNum;

            GenerateLevelsList();

            if (_levels[_selectedLevel] == null)
            {
                Debug.LogError($"Failed to start at level ({_selectedLevel})");
                return;
            }

            var puzzleState = _levels[_selectedLevel].GetComponent <PuzzleState>();
            var puzzleScale = _levels[_selectedLevel].GetComponent <PuzzleScale>();

            puzzleState.BoardEnabled = true;
            puzzleScale.PuzzleInit  += OnPuzzleInit;
            _levels[_selectedLevel].GetComponent <BoardAction>().PuzzleWin += OnPuzzleWin;
            puzzleState.LevelStateChanged += OnLevelStateChanged;

            var bounds = _levelBounds[_selectedLevel];
            var mid    = (bounds.Item1 + bounds.Item2) / 2f;

            transform.position = Vector3.up * mid;

            puzzleState.Init(_selectedLevel);
        }
Exemplo n.º 12
0
    // Start is called before the first frame update
    void Start()
    {
        _mainCamera = Camera.main;

        var recognizer = new TKPanRecognizer();

        // when using in conjunction with a pinch or rotation recognizer setting the min touches to 2 smoothes movement greatly
        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            recognizer.minimumNumberOfTouches = 2;
        }

        recognizer.gestureRecognizedEvent += (r) =>
        {
            Vector3 forward = Vector3.ProjectOnPlane(_mainCamera.transform.forward, Vector3.up) * recognizer.deltaTranslation.y;
            Vector3 right   = Vector3.ProjectOnPlane(_mainCamera.transform.right, Vector3.up) * recognizer.deltaTranslation.x;
            Vector3 newPos  = (forward + right) / 1000;
            transform.position += newPos;
        };

        TouchKit.addGestureRecognizer(recognizer);
    }
Exemplo n.º 13
0
    private Vector2 _scrollPosition;     // for the scroll view


    void OnGUI()
    {
        GUI.skin.button.padding    = new RectOffset(10, 10, 20, 20);
        GUI.skin.button.fixedWidth = 250;


        GUILayout.BeginArea(new Rect(Screen.width - GUI.skin.button.fixedWidth - 20, 0, GUI.skin.button.fixedWidth + 20, Screen.height));
        _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, GUILayout.Width(GUI.skin.button.fixedWidth + 20), GUILayout.Height(Screen.height));

        if (GUILayout.Button("Add Curve Recognizer"))
        {
            var recognizer = new TKCurveRecognizer();

            recognizer.gestureRecognizedEvent += (r) => {
                cube.Rotate(Vector3.back, recognizer.deltaRotation);
                Debug.Log("curve recognizer fired: " + r);
            };

            recognizer.gestureCompleteEvent += (r) => {
                Debug.Log("curve completed.");
            };

            TouchKit.addGestureRecognizer(recognizer);
        }

        if (GUILayout.Button("Add Tap Recognizer"))
        {
            var recognizer = new TKTapRecognizer();

            // we can limit recognition to a specific Rect, in this case the bottom-left corner of the screen
            recognizer.boundaryFrame = new TKRect(0, 0, 50f, 50f);

            // we can also set the number of touches required for the gesture
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                recognizer.numberOfTouchesRequired = 2;
            }

            recognizer.gestureRecognizedEvent += (r) =>
            {
                Debug.Log("tap recognizer fired: " + r);
            };
            TouchKit.addGestureRecognizer(recognizer);
        }


        if (GUILayout.Button("Add Long Press Recognizer"))
        {
            var recognizer = new TKLongPressRecognizer();
            recognizer.gestureRecognizedEvent += (r) =>
            {
                Debug.Log("long press recognizer fired: " + r);
            };
            recognizer.gestureCompleteEvent += (r) =>
            {
                Debug.Log("long press recognizer finished: " + r);
            };
            TouchKit.addGestureRecognizer(recognizer);
        }


        if (GUILayout.Button("Add Pan Recognizer"))
        {
            var recognizer = new TKPanRecognizer();

            // when using in conjunction with a pinch or rotation recognizer setting the min touches to 2 smoothes movement greatly
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                recognizer.minimumNumberOfTouches = 2;
            }

            recognizer.gestureRecognizedEvent += (r) =>
            {
                Camera.main.transform.position -= new Vector3(recognizer.deltaTranslation.x, recognizer.deltaTranslation.y) / 100;
                Debug.Log("pan recognizer fired: " + r);
            };

            // continuous gestures have a complete event so that we know when they are done recognizing
            recognizer.gestureCompleteEvent += r =>
            {
                Debug.Log("pan gesture complete");
            };
            TouchKit.addGestureRecognizer(recognizer);
        }


        if (GUILayout.Button("Add Horizontal Swipe Recognizer"))
        {
            var recognizer = new TKSwipeRecognizer(TKSwipeDirection.Horizontal);
            recognizer.gestureRecognizedEvent += (r) =>
            {
                Debug.Log("swipe recognizer fired: " + r);
            };
            TouchKit.addGestureRecognizer(recognizer);
        }


        if (GUILayout.Button("Add Pinch Recognizer"))
        {
            var recognizer = new TKPinchRecognizer();
            recognizer.gestureRecognizedEvent += (r) =>
            {
                cube.transform.localScale += Vector3.one * recognizer.deltaScale;
                Debug.Log("pinch recognizer fired: " + r);
            };
            TouchKit.addGestureRecognizer(recognizer);
        }


        if (GUILayout.Button("Add Rotation Recognizer"))
        {
            var recognizer = new TKRotationRecognizer();
            recognizer.gestureRecognizedEvent += (r) =>
            {
                cube.Rotate(Vector3.back, recognizer.deltaRotation);
                Debug.Log("rotation recognizer fired: " + r);
            };
            TouchKit.addGestureRecognizer(recognizer);
        }


        if (GUILayout.Button("Add Button Recognizer"))
        {
            var recognizer = new TKButtonRecognizer(new TKRect(5f, 145f, 80f, 30f), 10f);
            recognizer.zIndex           = 1;
            recognizer.onSelectedEvent += (r) =>
            {
                Debug.Log("button recognizer selected: " + r);
            };
            recognizer.onDeselectedEvent += (r) =>
            {
                Debug.Log("button recognizer deselected: " + r);
            };
            recognizer.onTouchUpInsideEvent += (r) =>
            {
                Debug.Log("button recognizer touch up inside: " + r);
            };
            TouchKit.addGestureRecognizer(recognizer);
        }


        if (GUILayout.Button("Add One Finger Rotation Recognizer"))
        {
            var recognizer = new TKOneFingerRotationRecognizer();
            recognizer.targetPosition          = Camera.main.WorldToScreenPoint(cube.position);
            recognizer.gestureRecognizedEvent += (r) =>
            {
                cube.Rotate(Vector3.back, recognizer.deltaRotation);
                Debug.Log("one finger rotation recognizer fired: " + r);
            };
            TouchKit.addGestureRecognizer(recognizer);
        }


        if (GUILayout.Button("Add Any Touch Recognizer"))
        {
            var recognizer = new TKAnyTouchRecognizer(new TKRect(10, 10, 80, 50));
            recognizer.zIndex          = 1;
            recognizer.onEnteredEvent += (r) =>
            {
                Debug.Log("any touch entered: " + r);
            };
            recognizer.onExitedEvent += (r) =>
            {
                Debug.Log("any touch exited: " + r);
            };
            TouchKit.addGestureRecognizer(recognizer);
        }


        if (GUILayout.Button("Remove All Recognizers"))
        {
            TouchKit.removeAllGestureRecognizers();
        }


        GUILayout.EndScrollView();
        GUILayout.EndArea();
    }
Exemplo n.º 14
0
    public void SetInputSystem()
    {
        TouchKit.removeAllGestureRecognizers();

        if (PlaybackManager.isPlaying == PlaybackManager.PlayStates.Playing)
        {
            return;
        }

        if (lineEditMode == LineEditMode.Camera)
        {
            //pan camera
            var panRecognizer = new TKPanRecognizer();
            panRecognizer.gestureRecognizedEvent += (r) =>
            {
                OnPanCamera(r);
            };
            TouchKit.addGestureRecognizer(panRecognizer);

            //pinch zoom
            var pinchRecognizer = new TKPinchRecognizer();
            pinchRecognizer.gestureRecognizedEvent += (r) =>
            {
                OnZoomCamera(r);
            };
            TouchKit.addGestureRecognizer(pinchRecognizer);
        }
        else if (lineEditMode == LineEditMode.Erase)
        {
            //eraser
            var tapRecognizer = new TKTapRecognizer();
            tapRecognizer.zIndex = 2;
            tapRecognizer.numberOfTapsRequired    = 1;
            tapRecognizer.gestureRecognizedEvent += (r) =>
            {
                print(r);
                Erase(r);
            };
            TouchKit.addGestureRecognizer(tapRecognizer);
        }
        else
        {
            //draw
            var drawRecognizer = new TKButtonRecognizer(new TKRect(0, 0, Screen.width, Screen.height));
            drawRecognizer.zIndex           = 0;
            drawRecognizer.onSelectedEvent += (r) =>
            {
                OnDrawLineStart(r);
            };
            drawRecognizer.onTouchUpInsideEvent += (r) =>
            {
                OnDrawLineEnd(r);
            };
            TouchKit.addGestureRecognizer(drawRecognizer);

            switch (lineEditMode)
            {
            case LineEditMode.DrawAccelerator:
                lineType = LineType.LineTypes.Accelerator;
                break;

            case LineEditMode.DrawBounce:
                lineType = LineType.LineTypes.Bounce;
                break;

            case LineEditMode.DrawBrake:
                lineType = LineType.LineTypes.Brake;
                break;

            case LineEditMode.DrawNormal:
                lineType = LineType.LineTypes.Normal;
                break;
            }
        }
    }
Exemplo n.º 15
0
    void setupGestures()
    {
        this.panner = new TKPanRecognizer();
        this.rotater = new TKRotationRecognizer();
        this.tapper = new TKTapRecognizer();

        // when using in conjunction with a pinch or rotation recognizer setting the min touches to 2 smoothes movement greatly
        if (Application.platform == RuntimePlatform.IPhonePlayer) {
          this.panner.minimumNumberOfTouches = 2;
        }

        this.panner.gestureRecognizedEvent += this.movePaddle;
        this.rotater.gestureRecognizedEvent += this.rotatePaddle;
        this.tapper.gestureRecognizedEvent += this.startBallEvent;

        TouchKit.addGestureRecognizer(this.panner);
        TouchKit.addGestureRecognizer(this.rotater);
        TouchKit.addGestureRecognizer(this.tapper);
    }
Exemplo n.º 16
0
 void movePaddle(TKPanRecognizer r)
 {
     //transform.position += new Vector3(r.deltaTranslation.x, 0) / 50;
     movePaddle(r.deltaTranslation.x / 50);
 }
Exemplo n.º 17
0
    private Vector2 _scrollPosition; // for the scroll view

    #endregion Fields

    #region Methods

    void OnGUI()
    {
        GUI.skin.button.padding = new RectOffset( 10, 10, 20, 20 );
        GUI.skin.button.fixedWidth = 250;

        GUILayout.BeginArea( new Rect( Screen.width - GUI.skin.button.fixedWidth - 20, 0, GUI.skin.button.fixedWidth + 20, Screen.height ) );
            _scrollPosition = GUILayout.BeginScrollView( _scrollPosition, GUILayout.Width( GUI.skin.button.fixedWidth + 20 ), GUILayout.Height( Screen.height ) );

        if( GUILayout.Button( "Add Tap Recognizer" ) )
        {
            var recognizer = new TKTapRecognizer();

            // we can limit recognition to a specific Rect, in this case the bottom-left corner of the screen
            recognizer.boundaryFrame = new TKRect( 0, 0, 50f, 50f );

            // we can also set the number of touches required for the gesture
            if( Application.platform == RuntimePlatform.IPhonePlayer )
                recognizer.numberOfTouchesRequired = 2;

            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                Debug.Log( "tap recognizer fired: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Long Press Recognizer" ) )
        {
            var recognizer = new TKLongPressRecognizer();
            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                Debug.Log( "long press recognizer fired: " + r );
            };
            recognizer.gestureCompleteEvent += ( r ) =>
            {
                Debug.Log( "long press recognizer finished: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Pan Recognizer" ) )
        {
            var recognizer = new TKPanRecognizer();

            // when using in conjunction with a pinch or rotation recognizer setting the min touches to 2 smoothes movement greatly
            if( Application.platform == RuntimePlatform.IPhonePlayer )
                recognizer.minimumNumberOfTouches = 2;

            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                Camera.main.transform.position -= new Vector3( recognizer.deltaTranslation.x, recognizer.deltaTranslation.y ) / 100;
                Debug.Log( "pan recognizer fired: " + r );
            };

            // continuous gestures have a complete event so that we know when they are done recognizing
            recognizer.gestureCompleteEvent += r =>
            {
                Debug.Log( "pan gesture complete" );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add TouchPad Recognizer" ) )
        {
            var recognizer = new TKTouchPadRecognizer( new TKRect( 0f, 50f, 80f, 50f ) );
            recognizer.inputCurve = touchPadInputCurve;

            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                //Camera.main.transform.position -= new Vector3( recognizer.deltaTranslation.x, recognizer.deltaTranslation.y ) / 100;
                Debug.Log( "touchpad recognizer fired: " + r );
            };

            // continuous gestures have a complete event so that we know when they are done recognizing
            recognizer.gestureCompleteEvent += r =>
            {
                Debug.Log( "touchpad gesture complete" );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Horizontal Swipe Recognizer" ) )
        {
            var recognizer = new TKSwipeRecognizer();
            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                Debug.Log( "swipe recognizer fired: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Top-Right Swipe Recognizer" ) )
        {
            var recognizer = new TKAngleSwipeRecognizer();
            recognizer.addAngleRecogizedEvents (
                (TKAngleSwipeRecognizer r) => {
                    Debug.Log( "Top-Right angle swipe fired " + r );
                }, new Vector2(1,1), 45);

            recognizer.gestureRecognizedEvent += r => {
                // You can also do ordinary event, which fires at any angle
                // Debug.Log( "angle swipe recognizer fired: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Pinch Recognizer" ) )
        {
            var recognizer = new TKPinchRecognizer();
            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                cube.transform.localScale += Vector3.one * recognizer.deltaScale;
                Debug.Log( "pinch recognizer fired: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Rotation Recognizer" ) )
        {
            var recognizer = new TKRotationRecognizer();
            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                cube.Rotate( Vector3.back, recognizer.deltaRotation );
                Debug.Log( "rotation recognizer fired: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Button Recognizer" ) )
        {
            var recognizer = new TKButtonRecognizer( new TKRect( 5f, 145f, 80f, 30f ), 10f );
            recognizer.zIndex = 1;
            recognizer.onSelectedEvent += ( r ) =>
            {
                Debug.Log( "button recognizer selected: " + r );
            };
            recognizer.onDeselectedEvent += ( r ) =>
            {
                Debug.Log( "button recognizer deselected: " + r );
            };
            recognizer.onTouchUpInsideEvent += ( r ) =>
            {
                Debug.Log( "button recognizer touch up inside: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add One Finger Rotation Recognizer" ) )
        {
            var recognizer = new TKOneFingerRotationRecognizer();
            recognizer.targetPosition = Camera.main.WorldToScreenPoint( cube.position );
            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                cube.Rotate( Vector3.back, recognizer.deltaRotation );
                Debug.Log( "one finger rotation recognizer fired: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Any Touch Recognizer" ) )
        {
            var recognizer = new TKAnyTouchRecognizer( new TKRect( 10, 10, 80, 50 ) );
            recognizer.zIndex = 1;
            recognizer.onEnteredEvent += ( r ) =>
            {
                Debug.Log( "any touch entered: " + r );
            };
            recognizer.onExitedEvent += ( r ) =>
            {
                Debug.Log( "any touch exited: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Curve Recognizer" ) )
        {
            var recognizer = new TKCurveRecognizer();

            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                cube.Rotate( Vector3.back, recognizer.deltaRotation );
                Debug.Log( "curve recognizer fired: " + r );
            };

            recognizer.gestureCompleteEvent += ( r ) =>
            {
                Debug.Log( "curve completed.");
            };

            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Remove All Recognizers" ) )
        {
            TouchKit.removeAllGestureRecognizers();
        }

            GUILayout.EndScrollView();
        GUILayout.EndArea();
    }
Exemplo n.º 18
0
    private Vector2 _scrollPosition; // for the scroll view

    #endregion Fields

    #region Methods

    void OnGUI()
    {
        //GUI.matrix = Matrix4x4.Scale( new Vector3( 1.5f, 1.5f, 1.5f ) );
        GUI.skin.button.padding = new RectOffset( 10, 10, 20, 20 );
        GUI.skin.button.fixedWidth = 250;

        GUILayout.BeginArea( new Rect( Screen.width - GUI.skin.button.fixedWidth - 20, 0, GUI.skin.button.fixedWidth + 20, Screen.height ) );
            _scrollPosition = GUILayout.BeginScrollView( _scrollPosition, GUILayout.Width( GUI.skin.button.fixedWidth + 20 ), GUILayout.Height( Screen.height ) );

        if( GUILayout.Button( "Add Tap Recognizer" ) )
        {
            var recognizer = new TKTapRecognizer();

            // we can limit recognition to a specific Rect, in this case the bottom-left corner of the screen
            recognizer.boundaryFrame = new TKRect( 50, 50, 400, 400 );

            // we can also set the number of touches required for the gesture
            if( Application.platform == RuntimePlatform.IPhonePlayer )
                recognizer.numberOfTouchesRequired = 2;

            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                Debug.Log( "tap recognizer fired: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Long Press Recognizer" ) )
        {
            var recognizer = new TKLongPressRecognizer();
            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                Debug.Log( "long press recognizer fired: " + r );
            };
            recognizer.gestureCompleteEvent += ( r ) =>
            {
                Debug.Log( "long press recognizer finished: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Pan Recognizer" ) )
        {
            var recognizer = new TKPanRecognizer();

            // when using in conjunction with a pinch or rotation recognizer setting the min touches to 2 smoothes movement greatly
            if( Application.platform == RuntimePlatform.IPhonePlayer )
                recognizer.minimumNumberOfTouches = 2;

            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                Camera.mainCamera.transform.position -= new Vector3( recognizer.deltaTranslation.x, recognizer.deltaTranslation.y ) / 100;
                Debug.Log( "pan recognizer fired: " + r );
            };

            // continuous gestures have a complete event so that we know when they are done recognizing
            recognizer.gestureCompleteEvent += r =>
            {
                Debug.Log( "pan gesture complete" );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Horizontal Swipe Recognizer" ) )
        {
            var recognizer = new TKSwipeRecognizer( TKSwipeDirection.Horizontal );
            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                Debug.Log( "swipe recognizer fired: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Pinch Recognizer" ) )
        {
            var recognizer = new TKPinchRecognizer();
            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                cube.transform.localScale += Vector3.one * recognizer.deltaScale;
                Debug.Log( "pinch recognizer fired: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Rotation Recognizer" ) )
        {
            var recognizer = new TKRotationRecognizer();
            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                cube.Rotate( Vector3.back, recognizer.deltaRotation );
                Debug.Log( "rotation recognizer fired: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add Button Recognizer" ) )
        {
            var recognizer = new TKButtonRecognizer( new TKRect( 300, 30, 278, 90 ), 20 );
            recognizer.zIndex = 1;
            recognizer.onSelectedEvent += ( r ) =>
            {
                Debug.Log( "button recognizer selected: " + r );
            };
            recognizer.onDeselectedEvent += ( r ) =>
            {
                Debug.Log( "button recognizer deselected: " + r );
            };
            recognizer.onTouchUpInsideEvent += ( r ) =>
            {
                Debug.Log( "button recognizer touch up inside: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Add One Finger Rotation Recognizer" ) )
        {
            var recognizer = new TKOneFingerRotationRecognizer();
            recognizer.targetPosition = Camera.mainCamera.WorldToScreenPoint( cube.position );
            recognizer.gestureRecognizedEvent += ( r ) =>
            {
                cube.Rotate( Vector3.back, recognizer.deltaRotation );
                Debug.Log( "one finger rotation recognizer fired: " + r );
            };
            TouchKit.addGestureRecognizer( recognizer );
        }

        if( GUILayout.Button( "Remove All Recognizers" ) )
        {
            TouchKit.removeAllGestureRecognizers();
        }

            GUILayout.EndScrollView();
        GUILayout.EndArea();
    }