Ejemplo n.º 1
0
        private void Start()
        {
            asteroids = Resources.LoadAll <Sprite>("FingersAsteroids");

            // don't reorder the creation of these :)
            CreatePlatformSpecificViewTripleTapGesture();
            CreateDoubleTapGesture();
            CreateTapGesture();
            CreateSwipeGesture();
            CreatePanGesture();
            CreateScaleGesture();
            CreateRotateGesture();
            CreateLongPressGesture();

            // pan, scale and rotate can all happen simultaneously
            panGesture.AllowSimultaneousExecution(scaleGesture);
            panGesture.AllowSimultaneousExecution(rotateGesture);
            scaleGesture.AllowSimultaneousExecution(rotateGesture);

            // prevent the one special no-pass button from passing through,
            //  even though the parent scroll view allows pass through (see FingerScript.PassThroughObjects)
            FingersScript.Instance.CaptureGestureHandler = CaptureGestureHandler;

            // show touches, only do this for debugging as it can interfere with other canvases
            FingersScript.Instance.ShowTouches = true;
        }
        private void OnEnable()
        {
            if (Target == null)
            {
                Target = transform;
            }

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

            TiltGesture = new PanGestureRecognizer();
            TiltGesture.StateUpdated  += TiltGestureCallback;
            TiltGesture.ThresholdUnits = 0.5f; // higher than normal to not interfere with other gestures
            TiltGesture.MinimumNumberOfTouchesToTrack = TiltGesture.MaximumNumberOfTouchesToTrack = 2;
            FingersScript.Instance.AddGesture(TiltGesture);

            ScaleGesture = new ScaleGestureRecognizer();
            ScaleGesture.StateUpdated += ScaleGestureCallback;
            FingersScript.Instance.AddGesture(ScaleGesture);

            RotateGesture = new RotateGestureRecognizer();
            RotateGesture.StateUpdated += RotateGestureCallback;
            FingersScript.Instance.AddGesture(RotateGesture);

            PanGesture.AllowSimultaneousExecution(ScaleGesture);
            PanGesture.AllowSimultaneousExecution(RotateGesture);
            ScaleGesture.AllowSimultaneousExecution(RotateGesture);
        }
Ejemplo n.º 3
0
        private void Start()
        {
            if (FingersScript.Instance == null)
            {
                Debug.LogError("Fingers script prefab needs to be added to the first scene");
                return;
            }

            this.Camera = (this.Camera == null ? Camera.main : this.Camera);
            panGesture  = new PanGestureRecognizer();
            panGesture.MinimumNumberOfTouchesToTrack = PanMinimumTouchCount;
            panGesture.Updated    += PanGestureUpdated;
            scaleGesture           = new ScaleGestureRecognizer();
            scaleGesture.Updated  += ScaleGestureUpdated;
            rotateGesture          = new RotateGestureRecognizer();
            rotateGesture.Updated += RotateGestureUpdated;
            rigidBody              = GetComponent <Rigidbody2D>();
            spriteRenderer         = GetComponent <SpriteRenderer>();
            if (spriteRenderer != null)
            {
                startSortOrder = spriteRenderer.sortingOrder;
            }
            panGesture.AllowSimultaneousExecution(scaleGesture);
            panGesture.AllowSimultaneousExecution(rotateGesture);
            scaleGesture.AllowSimultaneousExecution(rotateGesture);
            FingersScript.Instance.AddGesture(panGesture);
            FingersScript.Instance.AddGesture(scaleGesture);
            FingersScript.Instance.AddGesture(rotateGesture);
        }
 private void Start()
 {
     this.Camera = (this.Camera == null ? Camera.main : this.Camera);
     PanGesture  = new PanGestureRecognizer();
     PanGesture.MinimumNumberOfTouchesToTrack = PanMinimumTouchCount;
     PanGesture.MaximumNumberOfTouchesToTrack = 2;
     PanGesture.StateUpdated    += PanGestureUpdated;
     ScaleGesture                = new ScaleGestureRecognizer();
     ScaleGesture.StateUpdated  += ScaleGestureUpdated;
     RotateGesture               = new RotateGestureRecognizer();
     RotateGesture.StateUpdated += RotateGestureUpdated;
     SetStartState(gameObject);
     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);
 }
        private void OnEnable()
        {
            contentRectTransform   = ScrollContent.GetComponent <RectTransform>();
            containerRectTransform = ScrollContentContainer.GetComponent <RectTransform>();

            // create the scale, tap and pan gestures that will manage the scroll view
            ScaleGesture = new ScaleGestureRecognizer();
            ScaleGesture.StateUpdated        += Scale_Updated;
            ScaleGesture.PlatformSpecificView = ScrollContentContainer;
            ScaleGesture.ThresholdUnits       = 0.0f; // start zooming immediately

            RotateGesture = new RotateGestureRecognizer();
            RotateGesture.StateUpdated        += Rotate_Updated;
            RotateGesture.PlatformSpecificView = ScrollContentContainer;
            RotateGesture.AllowSimultaneousExecution(ScaleGesture);

            DoubleTapGesture = new TapGestureRecognizer();
            DoubleTapGesture.NumberOfTapsRequired = 2;
            DoubleTapGesture.StateUpdated        += Tap_Updated;
            DoubleTapGesture.PlatformSpecificView = ScrollContentContainer;

            PanGesture = new PanGestureRecognizer();
            PanGesture.MaximumNumberOfTouchesToTrack = 2;
            PanGesture.StateUpdated += Pan_Updated;
            PanGesture.AllowSimultaneousExecution(ScaleGesture);
            PanGesture.AllowSimultaneousExecution(RotateGesture);
            PanGesture.PlatformSpecificView = ScrollContentContainer;

            FingersScript.Instance.AddGesture(ScaleGesture);
            FingersScript.Instance.AddGesture(RotateGesture);
            FingersScript.Instance.AddGesture(DoubleTapGesture);
            FingersScript.Instance.AddGesture(PanGesture);
        }
Ejemplo n.º 6
0
        private void Start()
        {
            // we have set a prefab instance on this script - if we don't have a singleton of FingersScript yet,
            // create an instance of the prefab and set it as the singleton. This allows the fingers script
            // to live forever and eliminates the need to add the fingers script to every scene in your game.
            // you should only have this logic in the first scene of your game, and it must be in the Start method.
            FingersScript.CreateSingletonFromPrefabIfNeeded(FingersScriptPrefab);

            asteroids = Resources.LoadAll <Sprite>("Asteroids");

            // don't reorder the creation of these :)
            CreatePlatformSpecificViewTripleTapGesture();
            CreateDoubleTapGesture();
            CreateTapGesture();
            CreateSwipeGesture();
            CreatePanGesture();
            CreateScaleGesture();
            CreateRotateGesture();
            CreateLongPressGesture();

            // pan, scale and rotate can all happen simultaneously
            panGesture.AllowSimultaneousExecution(scaleGesture);
            panGesture.AllowSimultaneousExecution(rotateGesture);
            scaleGesture.AllowSimultaneousExecution(rotateGesture);

            // prevent the one special no-pass button from passing through,
            //  even though the parent scroll view allows pass through (see FingerScript.PassThroughObjects)
            FingersScript.Instance.CaptureGestureHandler = CaptureGestureHandler;

            // show touches, only do this for debugging as it can interfere with other canvases
            FingersScript.Instance.ShowTouches = true;
        }
Ejemplo n.º 7
0
 private void OnEnable()
 {
     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(null, gameObject, true);
     }
     if (DoubleTapToReset)
     {
         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);
 }
        private void Start()
        {
            playerBody = GetComponent <Rigidbody2D>();

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

            // 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);
        }
Ejemplo n.º 9
0
        private void Start()
        {
            contentRectTransform = ScrollContent.GetComponent <RectTransform>();

            ScaleGestureRecognizer scale = new ScaleGestureRecognizer();

            scale.StateUpdated        += Scale_Updated;
            scale.PlatformSpecificView = ScrollContent.gameObject;
            scale.ThresholdUnits       = 0.0f; // start zooming immediately
            FingersScript.Instance.AddGesture(scale);

            TapGestureRecognizer tap = new TapGestureRecognizer();

            tap.NumberOfTapsRequired = 2;
            tap.StateUpdated        += Tap_Updated;
            tap.PlatformSpecificView = ScrollContent.gameObject;
            FingersScript.Instance.AddGesture(tap);

            PanGestureRecognizer pan = new PanGestureRecognizer();

            pan.MaximumNumberOfTouchesToTrack = 2;
            pan.StateUpdated += Pan_Updated;
            pan.AllowSimultaneousExecution(scale);
            pan.PlatformSpecificView = ScrollContent.gameObject;
            FingersScript.Instance.AddGesture(pan);
        }
Ejemplo n.º 10
0
        private void Start()
        {
            CreateSwipeGesture();
            CreatePanGesture();
            CreateScaleGesture();

            panGesture.AllowSimultaneousExecution(scaleGesture);
            FingersScript.Instance.CaptureGestureHandler = CaptureGestureHandler;
        }
Ejemplo n.º 11
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);
 }
Ejemplo n.º 12
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);
        }