Last active
November 9, 2018 08:25
-
-
Save nicloay/6999c2a6fe497897c7e2e15f4cda1b59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using DigitalRubyShared; | |
using PaintCraft.Controllers; | |
using UnityEngine; | |
public class CamControllGesture : ScreenCameraController | |
{ | |
[SerializeField] | |
private Camera _camera; | |
private PanGestureRecognizer _panGesture; | |
private ScaleGestureRecognizer _scaleGesture; | |
void Awake() | |
{ | |
InitCamPan(); | |
InitCamScale(); | |
} | |
private void InitCamScale() | |
{ | |
_scaleGesture = new ScaleGestureRecognizer(); | |
_scaleGesture.StateUpdated += ScaleGestureCallback; | |
FingersScript.Instance.AddGesture(_scaleGesture); | |
} | |
private void ScaleGestureCallback(GestureRecognizer gesture) | |
{ | |
if (gesture.State == GestureRecognizerState.Executing) | |
{ | |
_camera.orthographicSize /= _scaleGesture.ScaleMultiplier; | |
} | |
} | |
private void InitCamPan() | |
{ | |
_panGesture = new PanGestureRecognizer(); | |
_panGesture.MinimumNumberOfTouchesToTrack = 2; | |
_panGesture.MaximumNumberOfTouchesToTrack = 2; | |
_panGesture.StateUpdated += PanGestureCallback; | |
FingersScript.Instance.AddGesture(_panGesture); | |
} | |
private void PanGestureCallback(GestureRecognizer gesture) | |
{ | |
if (gesture.State == GestureRecognizerState.Executing) | |
{ | |
transform.position += GetWorldPositionDelta(gesture); | |
} | |
} | |
Vector3 GetWorldPositionDelta(GestureRecognizer gestureRecognizer) | |
{ | |
Vector2 screenPositionDelta = new Vector3(gestureRecognizer.DeltaX, gestureRecognizer.DeltaY); | |
Vector3 result = _camera.ScreenToWorldPoint(Vector2.zero) - Camera.ScreenToWorldPoint(screenPositionDelta); | |
result.z = 0; | |
return result; | |
} | |
void Update () { | |
//just override input from base class | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using DigitalRubyShared; | |
using PaintCraft.Controllers; | |
using PaintCraft.Tools; | |
using UnityEngine; | |
public class PaintcraftGesture : InputController | |
{ | |
public Camera Camera; | |
public LineConfig DrawingTool; | |
private PanGestureRecognizer panGesture; | |
void Start () | |
{ | |
panGesture = new PanGestureRecognizer(); | |
panGesture.MinimumNumberOfTouchesToTrack = 1; | |
panGesture.MaximumNumberOfTouchesToTrack = 1; | |
panGesture.StateUpdated += PanGestureCallback; | |
FingersScript.Instance.AddGesture(panGesture); | |
} | |
private void PanGestureCallback(GestureRecognizer gesture) | |
{ | |
if (gesture.State == GestureRecognizerState.Began) | |
{ | |
BeginLine(DrawingTool, 0, GetWorldPosition(gesture)); | |
} else if (gesture.State == GestureRecognizerState.Executing) | |
{ | |
ContinueLine(0, GetWorldPosition(gesture)); | |
} else if (gesture.State == GestureRecognizerState.Ended) | |
{ | |
EndLine(0, GetWorldPosition(gesture)); | |
} | |
} | |
public override bool DontAllowInteraction(Vector2 worldPosition) | |
{ | |
return false; | |
} | |
Vector3 GetWorldPosition(GestureRecognizer gestureRecognizer) | |
{ | |
Vector3 vector3ScreenPosition = new Vector3(gestureRecognizer.FocusX, gestureRecognizer.FocusY, transform.position.z); | |
return Camera.ScreenToWorldPoint(vector3ScreenPosition); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment