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); }
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 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); }
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); }
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 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; }
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; } 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); }
private void Start() { if (useScaleGesture) { CreateScaleGesture(); } if (useRotateGesture) { CreateRotateGesture(); } scaleGesture.AllowSimultaneousExecution(rotateGesture); }
private void Update() { if (allowOrbitWhileZooming != AllowOrbitWhileZooming) { allowOrbitWhileZooming = AllowOrbitWhileZooming; if (allowOrbitWhileZooming) { scaleGesture.AllowSimultaneousExecution(panGesture); } else { scaleGesture.DisallowSimultaneousExecution(panGesture); } } }
private void Update() { if (allowOrbitWhileZooming != AllowOrbitWhileZooming) { allowOrbitWhileZooming = AllowOrbitWhileZooming; if (allowOrbitWhileZooming) { scaleGesture.AllowSimultaneousExecution(panGesture); } else { scaleGesture.DisallowSimultaneousExecution(panGesture); } } scaleGesture.ZoomSpeed = ZoomSpeed; UpdateOrbit(panVelocity.x, panVelocity.y); panVelocity = panVelocity * OrbitInertia; }
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); }
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); }
protected virtual void LateUpdate() { if (allowOrbitWhileZooming != AllowOrbitWhileZooming) { allowOrbitWhileZooming = AllowOrbitWhileZooming; if (allowOrbitWhileZooming) { scaleGesture.AllowSimultaneousExecution(panGesture); } else { scaleGesture.DisallowSimultaneousExecution(panGesture); } } Vector3 startPos = Orbiter.transform.position; UpdateOrbit(panVelocity.x, panVelocity.y); UpdateZoom(); ClampDistance(startPos); panVelocity *= OrbitInertia; zoomSpeed *= OrbitInertia; }