I want to implement something like Unity’s IPointer handlers for gesture detection but I don’t really have any ideas that feels nice and clean, this is the direction I’m currently going with:
public interface IGestureControlHandler {
void onSwipe(Vector2 dir);
void onTap(Vector2 pos);
void onDoubleTap(Vector2 pos);
void onPinch(Vector2 thumbMvmt, Vector2 indexMvmt);
}
public class GestureControl : MonoBehaviour {
IGestureControlHandler receiver;
public void setEventReceiver(IGestureControlHandler planeController) {
receiver = planeController;
}
void Update() {
if(Input.touchCount > 0) {
// Gesture detection stuff
if(receiver != null) {
Vector2 swipeDir = Vector2.whatever;
receiver.onSwipe(swipeDir);
}
}
}
}
And in whatever GameObject that needs gesture detection:
public class PlaneController : MonoBehaviour, IGestureControlHandler {
void Awake() {
gameObject.AddComponent<GestureControl>().setEventReceiver(this);
}
public void onSwipe(Vector2 dir) {
throw new System.NotImplementedException();
}
public void onTap(Vector2 pos) {
throw new System.NotImplementedException();
}
public void onDoubleTap(Vector2 pos) {
throw new System.NotImplementedException();
}
public void onPinch(Vector2 thumbMvmt, Vector2 indexMvmt) {
throw new System.NotImplementedException();
}
}
I feel pretty disgusted by this tbh:
what do you think I can do to make it better?