This file contains 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 UnityEngine; | |
using UnityEngine.EventSystems; | |
public class InputManager : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler | |
{ | |
} |
This file contains 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
public void OnBeginDrag(PointerEventData eventData) | |
{ | |
throw new System.NotImplementedException(); | |
} | |
public void OnDrag(PointerEventData eventData) | |
{ | |
throw new System.NotImplementedException(); | |
} |
This file contains 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
public enum Direction { Left, Up, Right, Down, None } |
This file contains 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
Direction direction; | |
Vector2 startPos, endPos; | |
public float swipeThreshold = 100f; | |
bool draggingStarted; |
This file contains 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
private void Awake() | |
{ | |
draggingStarted = false; | |
direction = Direction.None; | |
} |
This file contains 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
public void OnBeginDrag(PointerEventData eventData) | |
{ | |
draggingStarted = true; | |
startPos = eventData.pressPosition; | |
} |
This file contains 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
public void OnDrag(PointerEventData eventData) | |
{ | |
if (draggingStarted) | |
{ | |
endPos = eventData.position; | |
Vector2 difference = endPos - startPos; // difference vector between start and end positions. | |
if (difference.magnitude > swipeThreshold) | |
{ |
This file contains 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
public void OnEndDrag(PointerEventData eventData) | |
{ | |
if (draggingStarted && direction != Direction.None) | |
{ | |
//Do something with this direction data. | |
Debug.Log("Swipe direction: " + direction); | |
} | |
//reset the variables | |
startPos = Vector2.zero; |
This file contains 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 UnityEngine; | |
using UnityEngine.EventSystems; | |
public class InputManager : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler | |
{ | |
public enum Direction { Left, Up, Right, Down, None } | |
Direction direction; | |
Vector2 startPos, endPos; |
This file contains 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; | |
public class InputManager : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler | |
{ | |
public Action<Direction> onSwipeDetected; | |
} |
OlderNewer