Unityã§ã¿ããã¨ãã¹ã¯ã¤ãã¨ããç°¡åã«å®è£ ã§ãã¦ãã¾ãFingerGesturesè²·ã£ã
http://fingergestures.fatalfrog.com/
ã¿ã¤ãã«ã®éãAssetStoreã§FingerGesturesãè²·ãã¾ããã$55ã§ãã
Unity iOS/Androidãç¡ååããã¦ãAssetStoreã«èª²éãã¦ãã¾ãã
ãããã¾ãã§ã½ã¼ã·ã£ã«ã²ã¼ã ã®ããã«ã
ä¸ä¸å·¦å³ã®ã¹ã¯ã¤ãã¤ãã³ããåãåããµã³ãã«ãä½æããã®ã§æé ãç´¹ä»è´ãã¾ãã
Hierarchyã«FingerGesturesãã¬ãããé ç½®
FingerGesturesãimportããã¨Assets/Plugins/FingerGestures/Prefabs以ä¸ã«FingerGesturesã¨ããååã®ãã¬ãããããã®ã§ãããçªã£è¾¼ã¿ã¾ã
ã¹ã¯ã¤ãã¤ãã³ããèµ·ãããããªãã¸ã§ã¯ããä½æãã
é©å½ã«ãªãã¸ã§ã¯ããä½æãã¾ããNGUIã°ãã使ã£ã¦ãç§ã¯Spriteãä½æãã¾ããã
ãã®ãªãã¸ã§ã¯ãã«å¯¾ãã¦ã"Swipe Recognizer"ã¨"Screen Raycaster"ã¨ããã³ã³ãã¼ãã³ãã追å ãã¾ãã
ScreenRaycasterã®è¦ç´ ã§ãã"Cameras->Size"ã1ã«å¤æ´ãã"Cameras->Element 0"ã«å¯¾ãã¦ãHierarchyã«åå¨ãã"Camera"ãªãã¸ã§ã¯ããD&Dã§æã£ã¦ãã¾ãã
ããã§å¾ã¯Swipeãåãåã£ãæã®å¦çãæ¸ãã ãã§ãã
Swipeã¤ãã³ããåãåã£ãéã®å¦çãè¨è¿°ãã
ä»åã¯ä¸ä¸å·¦å³ã®ã¹ã¯ã¤ãã¤ãã³ããå¦çããããã以ä¸ã®ãããªã³ã¼ããæ¸ãã¾ããã
SimpleSwipe.cs
ä¸è¨ã§ä½æãããªãã¸ã§ã¯ãã«è¿½å ãã¾ãã
"swipeReceiver"ã¯ä¸è¨ã®"SwipeReceiverImpl.cs"ã追å ãããªãã¸ã§ã¯ããæå®ãã¾ãã
ä»åã§ããã°ãä½æãããªãã¸ã§ã¯ãã§ãã
using UnityEngine; using System.Collections; public class SimpleSwipe : MonoBehaviour { public GameObject swipeReceiver; void OnSwipe(SwipeGesture gesture) { FingerGestures.SwipeDirection direction = gesture.Direction; switch(direction) { case FingerGestures.SwipeDirection.Right: swipeReceiver.SendMessage("RightSwipe"); break; case FingerGestures.SwipeDirection.Left: swipeReceiver.SendMessage("LeftSwipe"); break; case FingerGestures.SwipeDirection.Up: swipeReceiver.SendMessage("UpSwipe"); break; case FingerGestures.SwipeDirection.Down: swipeReceiver.SendMessage("DownSwipe"); break; default: break; } } }
ISwipeReciever.cs
using UnityEngine; using System.Collections; public class ISwipeReceiver : MonoBehaviour { public virtual void LeftSwipe() {} public virtual void RightSwipe() {} public virtual void UpSwipe() {} public virtual void DownSwipe() {} }
SwipeReceiverImpl.cs
ãããä¸è¨ã§ä½æãããªãã¸ã§ã¯ãã«è¿½å ãã¾ãã
using UnityEngine; using System.Collections; public class SwipeReceiverImpl : ISwipeReceiver { public override void LeftSwipe() { print("left swipe"); } public override void RightSwipe() { print("right swipe"); } public override void UpSwipe() { print("up swipe"); } public override void DownSwipe() { print("down swipe"); } }
ãã£ãããã ãã§åç´ãªã¹ã¯ã¤ãã¤ãã³ãã®å¦çãå¯è½ã«ãªãã¾ãã