Exemplo n.º 1
0
        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

            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.PlatformSpecificView = ScrollContentContainer;

            FingersScript.Instance.AddGesture(ScaleGesture);
            FingersScript.Instance.AddGesture(DoubleTapGesture);
            FingersScript.Instance.AddGesture(PanGesture);
        }
        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);
        }
        private void OnEnable()
        {
            // create a scale gesture to zoom orbiter in and out
            ScaleGesture = new ScaleGestureRecognizer();
            ScaleGesture.StateUpdated  += ScaleGesture_Updated;
            ScaleGesture.ThresholdUnits = ZoomThresholdUnits;

            // pan gesture
            PanGesture = new PanGestureRecognizer();
            PanGesture.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;
            }

            // point oribiter at target
            Orbiter.transform.LookAt(OrbitTarget.transform);

            FingersScript.Instance.AddGesture(ScaleGesture);
            FingersScript.Instance.AddGesture(PanGesture);
            FingersScript.Instance.AddGesture(TapGesture);
        }
        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);
        }
Exemplo n.º 5
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);
 }
Exemplo n.º 7
0
        private void Start()
        {
            _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
            {
                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;
            FingersScript.Instance.AddGesture(ScaleGesture);

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

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

            TapGesture = new TapGestureRecognizer();
            TapGesture.StateUpdated += TapGesture_Updated;
            FingersScript.Instance.AddGesture(TapGesture);
        }
Exemplo n.º 8
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 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);
        }
Exemplo n.º 10
0
        private void Start()
        {
            ScaleGestureRecognizer scale = new ScaleGestureRecognizer();

            scale.StateUpdated        += Scale_Updated;
            scale.PlatformSpecificView = ScrollView.gameObject;
            FingersScript.AddGesture(scale);

            TapGestureRecognizer tap = new TapGestureRecognizer();

            tap.NumberOfTapsRequired = 2;
            tap.StateUpdated        += Tap_Updated;
            tap.PlatformSpecificView = ScrollView.gameObject;
            FingersScript.AddGesture(tap);
        }
Exemplo n.º 11
0
        private void Start()
        {
            ScaleGestureRecognizer scale = new ScaleGestureRecognizer();

            scale.Updated += Scale_Updated;
            FingersScript.AddGesture(scale);

            TapGestureRecognizer tap = new TapGestureRecognizer();

            tap.NumberOfTapsRequired = 2;
            tap.Updated += Tap_Updated;
            FingersScript.AddGesture(tap);

            FingersScript.CaptureGestureHandler = CaptureGestureHandler;
        }
        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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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);
 }
Exemplo n.º 16
0
 private void CreateScaleGesture()
 {
     scaleGesture = new ScaleGestureRecognizer();
     scaleGesture.StateUpdated += ScaleGestureCallback;
     FingersScript.Instance.AddGesture(scaleGesture);
 }
		private void CreateScaleGesture()
		{
			scaleGesture = new ScaleGestureRecognizer();
			scaleGesture.Updated += ScaleGestureCallback;
			FingerScript.AddGesture(scaleGesture);
		}