예제 #1
0
        private void Start()
        {
            pan = new PanGestureRecognizer();
            pan.StateUpdated += Pan_Updated;
            pan.MaximumNumberOfTouchesToTrack = 2;
            FingersScript.Instance.AddGesture(pan);

            TapGestureRecognizer tap = new TapGestureRecognizer();

            tap.StateUpdated += Tap_StateUpdated;
            tap.ClearTrackedTouchesOnEndOrFail = true;
            tap.AllowSimultaneousExecution(pan);
            FingersScript.Instance.AddGesture(tap);
        }
예제 #2
0
        private void Start()
        {
            fireGesture = new TapGestureRecognizer();
            fireGesture.StateUpdated += TapGestureUpdated;

            // we want the tap to fail with the pan gesture tap and pick up a new tap with another finger
            fireGesture.ClearTrackedTouchesOnEndOrFail = true;

            moveGesture = new PanGestureRecognizer();
            moveGesture.StateUpdated += PanGestureUpdated;
            moveGesture.AllowSimultaneousExecution(fireGesture);
            FingersScript.Instance.AddGesture(fireGesture);
            FingersScript.Instance.AddGesture(moveGesture);
        }
        private void OnEnable()
        {
            if (Camera == null)
            {
                Camera = Camera.main;
            }

            Target       = (Target == null ? transform : Target);
            origRotation = Target.rotation;
            origScale    = Target.localScale;

            PanGesture = new PanGestureRecognizer();
            PanGesture.StateUpdated        += PanGestureStateUpdated;
            PanGesture.PlatformSpecificView = gameObject;
            FingersScript.Instance.AddGesture(PanGesture);

            RotateGesture = new RotateGestureRecognizer();
            RotateGesture.StateUpdated        += RotateGestureStateUpdated;
            RotateGesture.PlatformSpecificView = gameObject;
            RotateGesture.AllowSimultaneousExecution(PanGesture);
            FingersScript.Instance.AddGesture(RotateGesture);

            ScaleGesture = new ScaleGestureRecognizer();
            ScaleGesture.StateUpdated        += ScaleGestureStateUpdated;
            ScaleGesture.PlatformSpecificView = gameObject;
            ScaleGesture.ZoomSpeed           *= ScaleSpeed;
            ScaleGesture.AllowSimultaneousExecution(RotateGesture);
            ScaleGesture.AllowSimultaneousExecution(PanGesture);
            FingersScript.Instance.AddGesture(ScaleGesture);

            TapGestureReset = new TapGestureRecognizer();
            TapGestureReset.NumberOfTapsRequired = 2;
            TapGestureReset.PlatformSpecificView = gameObject;
            TapGestureReset.StateUpdated        += TapGestureResetStateUpdated;
            FingersScript.Instance.AddGesture(TapGestureReset);

            TapGestureDestroy = new TapGestureRecognizer();
            TapGestureDestroy.NumberOfTapsRequired = 3;
            TapGestureDestroy.PlatformSpecificView = gameObject;
            TapGestureDestroy.StateUpdated        += TapGestureDestroyStateUpdated;
            FingersScript.Instance.AddGesture(TapGestureDestroy);

            TapGestureReset.RequireGestureRecognizerToFail = TapGestureDestroy;

            LongPressGesture = new LongPressGestureRecognizer();
            LongPressGesture.PlatformSpecificView = gameObject;
            LongPressGesture.StateUpdated        += LongPressGestureStateUpdated;
            FingersScript.Instance.AddGesture(LongPressGesture);
        }
예제 #4
0
        private void Start()
        {
            PanGesture = new PanGestureRecognizer
            {
                AllowSimultaneousExecutionWithAllGestures = true,
                PlatformSpecificView = JoystickImage.gameObject,
                ThresholdUnits       = 0.0f
            };
            PanGesture.Updated += PanGestureUpdated;
            FingersScript.Instance.AddGesture(PanGesture);

#if UNITY_EDITOR
            if (JoystickImage == null || JoystickImage.canvas.renderMode != RenderMode.ScreenSpaceOverlay)
            {
                Debug.LogError("Fingers joystick script requires that JoystickImage be set and that the Canvas be in ScreenSpaceOverlay mode.");
            }
#endif
        }
        private void OnEnable()
        {
            if (Camera == null)
            {
                Camera = Camera.main;
            }

            Targets = (Targets == null || Targets.Count == 0 ? new List <Transform> {
                transform
            } : Targets);
            UpdateOrigStates();

            PanGesture = new PanGestureRecognizer();
            PanGesture.StateUpdated += PanGestureStateUpdated;
            FingersScript.Instance.AddGesture(PanGesture);

            RotateGesture = new RotateGestureRecognizer();
            RotateGesture.StateUpdated += RotateGestureStateUpdated;
            RotateGesture.AllowSimultaneousExecution(PanGesture);
            FingersScript.Instance.AddGesture(RotateGesture);

            ScaleGesture = new ScaleGestureRecognizer();
            ScaleGesture.StateUpdated += ScaleGestureStateUpdated;
            ScaleGesture.ZoomSpeed    *= ScaleSpeed;
            ScaleGesture.AllowSimultaneousExecution(RotateGesture);
            ScaleGesture.AllowSimultaneousExecution(PanGesture);
            FingersScript.Instance.AddGesture(ScaleGesture);

            TapGestureReset = new TapGestureRecognizer();
            TapGestureReset.NumberOfTapsRequired = 2;
            TapGestureReset.StateUpdated        += TapGestureResetStateUpdated;
            FingersScript.Instance.AddGesture(TapGestureReset);

            TapGestureDestroy = new TapGestureRecognizer();
            TapGestureDestroy.NumberOfTapsRequired = 3;
            TapGestureDestroy.StateUpdated        += TapGestureDestroyStateUpdated;
            FingersScript.Instance.AddGesture(TapGestureDestroy);
            TapGestureReset.RequireGestureRecognizerToFail = TapGestureDestroy;

            LongPressGesture = new LongPressGestureRecognizer();
            LongPressGesture.StateUpdated += LongPressGestureStateUpdated;
            FingersScript.Instance.AddGesture(LongPressGesture);
        }
예제 #6
0
        private void Start()
        {
            scaleGesture = new ScaleGestureRecognizer
            {
                ZoomSpeed = 6.0f // for a touch screen you'd probably not do this, but if you are using ctrl + mouse wheel then this helps zoom faster
            };
            scaleGesture.Updated += Gesture_Updated;
            FingersScript.Instance.AddGesture(scaleGesture);

            panGesture          = new PanGestureRecognizer();
            panGesture.Updated += PanGesture_Updated;
            FingersScript.Instance.AddGesture(panGesture);

            // the scale and pan can happen together
            scaleGesture.AllowSimultaneousExecution(panGesture);

            tapGesture          = new TapGestureRecognizer();
            tapGesture.Updated += TapGesture_Updated;
            FingersScript.Instance.AddGesture(tapGesture);
        }
예제 #7
0
        private void Start()
        {
            // create a scale gesture to zoom orbiter in and out
            scaleGesture          = new ScaleGestureRecognizer();
            scaleGesture.Updated += ScaleGesture_Updated;

            // pan gesture
            panGesture = new PanGestureRecognizer();
            panGesture.MaximumNumberOfTouchesToTrack = 2;
            panGesture.Updated += PanGesture_Updated;

            // create a tap gesture that only executes on the target, note that this requires a physics ray caster on the camera
            tapGesture          = new TapGestureRecognizer();
            tapGesture.Updated += TapGesture_Updated;
            tapGesture.PlatformSpecificView = OrbitTarget;

            FingersScript.Instance.AddGesture(scaleGesture);
            FingersScript.Instance.AddGesture(panGesture);
            FingersScript.Instance.AddGesture(tapGesture);
        }
        private void OnEnable()
        {
            // create a scale gesture to zoom orbiter in and out
            //ScaleGesture = new ScaleGestureRecognizer { ZoomSpeed = ZoomSpeed };
            //ScaleGesture.StateUpdated += ScaleGesture_Updated;
            //ScaleGesture.ThresholdUnits = ZoomThresholdUnits;

            // pan gesture
            if (PanGesture == default)
            {
                PanGesture = new PanGestureRecognizer
                {
                    MaximumNumberOfTouchesToTrack = 2
                };
                PanGesture.StateUpdated += PanGesture_Updated;

                // create a tap gesture that only executes on the target, note that this requires a physics ray caster on the camera
                TapGesture = new TapGestureRecognizer();
                TapGesture.StateUpdated        += TapGesture_Updated;
                TapGesture.PlatformSpecificView = OrbitTarget.gameObject;

                if (RequireOrbitGesturesToStartOnTarget)
                {
                    ScaleGesture.PlatformSpecificView = OrbitTarget.gameObject;
                    PanGesture.PlatformSpecificView   = OrbitTarget.gameObject;
                }

                if (LookAtTarget)
                {
                    // point oribiter at target
                    Orbiter.transform.LookAt(OrbitTarget.transform);
                }
            }
            else
            {
            }

            //FingersScript.Instance.AddGesture(ScaleGesture);
            FingersScript.Instance.AddGesture(PanGesture);
            //FingersScript.Instance.AddGesture(TapGesture);
        }
예제 #9
0
 private void Start()
 {
     this.Camera = (this.Camera == null ? Camera.main : this.Camera);
     PanGesture  = new PanGestureRecognizer();
     PanGesture.MinimumNumberOfTouchesToTrack = PanMinimumTouchCount;
     PanGesture.StateUpdated    += PanGestureUpdated;
     ScaleGesture                = new ScaleGestureRecognizer();
     ScaleGesture.StateUpdated  += ScaleGestureUpdated;
     RotateGesture               = new RotateGestureRecognizer();
     RotateGesture.StateUpdated += RotateGestureUpdated;
     rigidBody2D    = GetComponent <Rigidbody2D>();
     rigidBody      = GetComponent <Rigidbody>();
     spriteRenderer = GetComponent <SpriteRenderer>();
     canvasRenderer = GetComponent <CanvasRenderer>();
     if (spriteRenderer != null)
     {
         startSortOrder = spriteRenderer.sortingOrder;
     }
     if (AllowExecutionWithAllGestures)
     {
         PanGesture.AllowSimultaneousExecutionWithAllGestures();
         PanGesture.AllowSimultaneousExecutionWithAllGestures();
         ScaleGesture.AllowSimultaneousExecutionWithAllGestures();
     }
     else
     {
         PanGesture.AllowSimultaneousExecution(ScaleGesture);
         PanGesture.AllowSimultaneousExecution(RotateGesture);
         ScaleGesture.AllowSimultaneousExecution(RotateGesture);
     }
     if (SetPlatformSpecificView)
     {
         RotateGesture.PlatformSpecificView = gameObject;
         PanGesture.PlatformSpecificView    = gameObject;
         ScaleGesture.PlatformSpecificView  = gameObject;
     }
     FingersScript.Instance.AddGesture(PanGesture);
     FingersScript.Instance.AddGesture(ScaleGesture);
     FingersScript.Instance.AddGesture(RotateGesture);
 }
        private void OnEnable()
        {
            _camera = GetComponent <Camera>();
            if (GetComponent <UnityEngine.EventSystems.PhysicsRaycaster>() == null)
            {
                gameObject.AddComponent <UnityEngine.EventSystems.PhysicsRaycaster>();
            }
            if (GetComponent <UnityEngine.EventSystems.Physics2DRaycaster>() == null)
            {
                gameObject.AddComponent <UnityEngine.EventSystems.Physics2DRaycaster>();
            }

            ScaleGesture = new ScaleGestureRecognizer
            {
                ThresholdUnits = ScaleThreshold,
                ZoomSpeed      = 6.0f // for a touch screen you'd probably not do this, but if you are using ctrl + mouse wheel then this helps zoom faster
            };
            ScaleGesture.StateUpdated += Gesture_Updated;

            PanGesture = new PanGestureRecognizer();
            PanGesture.StateUpdated += PanGesture_Updated;

            // the scale and pan can happen together
            ScaleGesture.AllowSimultaneousExecution(PanGesture);

            TapGesture = new TapGestureRecognizer();
            TapGesture.StateUpdated += TapGesture_Updated;

            RotateGesture = new RotateGestureRecognizer();
            RotateGesture.StateUpdated += RotateGesture_Updated;
            RotateGesture.AllowSimultaneousExecution(PanGesture);
            RotateGesture.AllowSimultaneousExecution(ScaleGesture);

            FingersScript.Instance.AddGesture(ScaleGesture);
            FingersScript.Instance.AddGesture(PanGesture);
            FingersScript.Instance.AddGesture(TapGesture);
            FingersScript.Instance.AddGesture(RotateGesture);
        }
예제 #11
0
        private void Start()
        {
#if UNITY_EDITOR
            ValidateImages(DPadBackgroundImage, DPadUpImageSelected, DPadRightImageSelected, DPadDownImageSelected, DPadLeftImageSelected, DPadCenterImageSelected);
#endif

            PanGesture = new PanGestureRecognizer
            {
                PlatformSpecificView = (MoveDPadToGestureStartLocation ? null : DPadBackgroundImage.canvas.gameObject),
                ThresholdUnits       = 0.0f
            };
            PanGesture.AllowSimultaneousExecutionWithAllGestures();
            PanGesture.StateUpdated += PanGestureUpdated;
            FingersScript.Instance.AddGesture(PanGesture);

            TapGesture = new TapGestureRecognizer
            {
                PlatformSpecificView = DPadBackgroundImage.gameObject
            };
            TapGesture.AllowSimultaneousExecutionWithAllGestures();
            TapGesture.StateUpdated += TapGestureUpdated;
            FingersScript.Instance.AddGesture(TapGesture);
        }
예제 #12
0
        private void DPadPanned(FingersDPadScript script, FingersDPadItem item, PanGestureRecognizer gesture)
        {
            Vector3 pos  = Mover.transform.position;
            float   move = Speed * Time.deltaTime;

            if ((item & FingersDPadItem.Right) != FingersDPadItem.None)
            {
                pos.x += move;
            }
            if ((item & FingersDPadItem.Left) != FingersDPadItem.None)
            {
                pos.x -= move;
            }
            if ((item & FingersDPadItem.Up) != FingersDPadItem.None)
            {
                pos.y += move;
            }
            if ((item & FingersDPadItem.Down) != FingersDPadItem.None)
            {
                pos.y -= move;
            }
            Mover.transform.position = pos;
        }
 private void Start()
 {
     this.Camera = (this.Camera == null ? Camera.main : this.Camera);
     PanGesture  = new PanGestureRecognizer {
         MaximumNumberOfTouchesToTrack = 2, ThresholdUnits = 0.01f
     };
     PanGesture.StateUpdated    += PanGestureUpdated;
     ScaleGesture                = new ScaleGestureRecognizer();
     ScaleGesture.StateUpdated  += ScaleGestureUpdated;
     RotateGesture               = new RotateGestureRecognizer();
     RotateGesture.StateUpdated += RotateGestureUpdated;
     if (Mode != GestureRecognizerComponentScriptBase.GestureObjectMode.AllowOnAnyGameObjectViaRaycast)
     {
         SetStartState(gameObject, true);
     }
     if (AllowExecutionWithAllGestures)
     {
         PanGesture.AllowSimultaneousExecutionWithAllGestures();
         PanGesture.AllowSimultaneousExecutionWithAllGestures();
         ScaleGesture.AllowSimultaneousExecutionWithAllGestures();
     }
     else
     {
         PanGesture.AllowSimultaneousExecution(ScaleGesture);
         PanGesture.AllowSimultaneousExecution(RotateGesture);
         ScaleGesture.AllowSimultaneousExecution(RotateGesture);
     }
     if (Mode == GestureRecognizerComponentScriptBase.GestureObjectMode.RequireIntersectWithGameObject)
     {
         RotateGesture.PlatformSpecificView = gameObject;
         PanGesture.PlatformSpecificView    = gameObject;
         ScaleGesture.PlatformSpecificView  = gameObject;
     }
     FingersScript.Instance.AddGesture(PanGesture);
     FingersScript.Instance.AddGesture(ScaleGesture);
     FingersScript.Instance.AddGesture(RotateGesture);
 }
예제 #14
0
        private void Start()
        {
            PanGesture = new PanGestureRecognizer
            {
                PlatformSpecificView = (MoveJoystickToGestureStartLocation ? null : JoystickImage.gameObject),
                ThresholdUnits       = 0.0f
            };
            PanGesture.AllowSimultaneousExecutionWithAllGestures();
            PanGesture.StateUpdated += PanGestureUpdated;
            FingersScript.Instance.AddGesture(PanGesture);

#if UNITY_EDITOR
            if (JoystickImage == null || JoystickImage.canvas.renderMode != RenderMode.ScreenSpaceOverlay)
            {
                Debug.LogError("Fingers joystick script requires that JoystickImage be set and that the Canvas be in ScreenSpaceOverlay mode.");
            }
#endif

            if (!string.IsNullOrEmpty(CrossPlatformInputHorizontalAxisName) && !string.IsNullOrEmpty(CrossPlatformInputVerticalAxisName))
            {
                crossPlatformInputHorizontalAxisObject = FingersCrossPlatformInputReflectionScript.RegisterVirtualAxis(CrossPlatformInputHorizontalAxisName, out crossPlatformInputNewlyRegistered);
                crossPlatformInputVerticalAxisObject   = FingersCrossPlatformInputReflectionScript.RegisterVirtualAxis(CrossPlatformInputVerticalAxisName, out crossPlatformInputNewlyRegistered);
            }
        }
예제 #15
0
        private void Start()
        {
            playerBody = GetComponent <Rigidbody2D>();

            TapGesture = new TapGestureRecognizer();
            TapGesture.StateUpdated += JumpTap_StateUpdated;
            TapGesture.ClearTrackedTouchesOnEndOrFail = true;

            // allow other fingers to jump while panning
            TapGesture.MaximumNumberOfTouchesToTrack = 10;

            // require fast taps
            TapGesture.ThresholdSeconds = JumpThresholdSeconds;

            // allow a little more slide than a normal tap
            TapGesture.ThresholdUnits = JumpThresholdUnits;

            PanGesture = new PanGestureRecognizer();
            PanGesture.StateUpdated  += MovePan_StateUpdated;
            PanGesture.ThresholdUnits = 0.35f; // require a little more slide before panning starts

            // jump up and move sideways is allowed
            PanGesture.AllowSimultaneousExecution(TapGesture);

            // swipe down requires no other gestures to be executing
            SwipeGesture = new SwipeGestureRecognizer
            {
                Direction = SwipeGestureRecognizerDirection.Down
            };
            SwipeGesture.StateUpdated += SwipeDown_StateUpdated;
            SwipeGesture.AllowSimultaneousExecution(PanGesture);

            FingersScript.Instance.AddGesture(TapGesture);
            FingersScript.Instance.AddGesture(PanGesture);
            FingersScript.Instance.AddGesture(SwipeGesture);
        }
예제 #16
0
        private void DPadPanned(FingersDPadScript script, FingersDPadItem item, PanGestureRecognizer gesture)
        {
            Vector3 pos = Mover.transform.position;

            switch (item)
            {
            case FingersDPadItem.Up:
                pos.y += Speed * Time.deltaTime;
                break;

            case FingersDPadItem.Right:
                pos.x += Speed * Time.deltaTime;
                break;

            case FingersDPadItem.Down:
                pos.y -= Speed * Time.deltaTime;
                break;

            case FingersDPadItem.Left:
                pos.x -= Speed * Time.deltaTime;
                break;
            }
            Mover.transform.position = pos;
        }
		private void CreatePanGesture()
		{
			panGesture = new PanGestureRecognizer();
			panGesture.MinimumNumberOfTouchesRequired = panGesture.MaximumNumberOfTouchesAllowed = 2;
			panGesture.Updated += PanGestureCallback;
			FingerScript.AddGesture(panGesture);
		}
예제 #18
0
 private void OnEnable()
 {
     if ((Cameras == null || Cameras.Length == 0) && Camera.main != null)
     {
         Cameras = new Camera[] { Camera.main };
     }
     PanGesture = new PanGestureRecognizer {
         MaximumNumberOfTouchesToTrack = 2, ThresholdUnits = 0.01f
     };
     PanGesture.StateUpdated    += PanGestureUpdated;
     ScaleGesture                = new ScaleGestureRecognizer();
     ScaleGesture.StateUpdated  += ScaleGestureUpdated;
     RotateGesture               = new RotateGestureRecognizer();
     RotateGesture.StateUpdated += RotateGestureUpdated;
     if (Mode != GestureRecognizerComponentScriptBase.GestureObjectMode.AllowOnAnyGameObjectViaRaycast)
     {
         SetStartState(null, gameObject, true);
     }
     if (DoubleTapResetMode != _DoubleTapResetMode.Off)
     {
         DoubleTapGesture = new TapGestureRecognizer {
             NumberOfTapsRequired = 2
         };
         DoubleTapGesture.StateUpdated += DoubleTapGestureUpdated;
     }
     if (AllowExecutionWithAllGestures)
     {
         PanGesture.AllowSimultaneousExecutionWithAllGestures();
         RotateGesture.AllowSimultaneousExecutionWithAllGestures();
         ScaleGesture.AllowSimultaneousExecutionWithAllGestures();
         if (DoubleTapGesture != null)
         {
             DoubleTapGesture.AllowSimultaneousExecutionWithAllGestures();
         }
     }
     else
     {
         PanGesture.AllowSimultaneousExecution(ScaleGesture);
         PanGesture.AllowSimultaneousExecution(RotateGesture);
         ScaleGesture.AllowSimultaneousExecution(RotateGesture);
         if (DoubleTapGesture != null)
         {
             DoubleTapGesture.AllowSimultaneousExecution(ScaleGesture);
             DoubleTapGesture.AllowSimultaneousExecution(RotateGesture);
             DoubleTapGesture.AllowSimultaneousExecution(PanGesture);
         }
     }
     if (Mode == GestureRecognizerComponentScriptBase.GestureObjectMode.RequireIntersectWithGameObject)
     {
         RotateGesture.PlatformSpecificView = gameObject;
         PanGesture.PlatformSpecificView    = gameObject;
         ScaleGesture.PlatformSpecificView  = gameObject;
         if (DoubleTapGesture != null)
         {
             DoubleTapGesture.PlatformSpecificView = gameObject;
         }
     }
     FingersScript.Instance.AddGesture(PanGesture);
     FingersScript.Instance.AddGesture(ScaleGesture);
     FingersScript.Instance.AddGesture(RotateGesture);
     FingersScript.Instance.AddGesture(DoubleTapGesture);
 }