Easy Touch 簡單筆記
簡介:
EasyTouch可以讓你快速簡單的檢測屏幕觸摸和鼠標的事件.可以檢測的手勢比如 觸摸,單擊,雙擊,扭動,捏,,,
插件主要功能有三:
- Easy Button(按鈕):
普通按鈕
可監聽的事件有三個( 來自源碼 EasyButton.cs ):
#region Event
/// <summary>
/// Occurs when the button is down for the first time.
/// </summary>
public static event ButtonDownHandler On_ButtonDown;
/// <summary>
/// Occurs when the button is pressed.
/// </summary>
public static event ButtonPressHandler On_ButtonPress;
/// <summary>
/// Occurs when the button is up
/// </summary>
public static event ButtonUpHandler On_ButtonUp;
#endregion
監聽事件的方式主要有兩種 :
- Message
勾選"Broadcast message" 指定Receiver objcet;在Receiver object 帶的腳本內,使用和
中對應的方法.
- Event
不需要勾選Broadcast messages;把自己寫得方法註冊進對應的Event中即可
代碼參考:
void OnEnable() {
EasyButton.On_ButtonDown += DownMethod;
}
void OnDisable() {
EasyButton.On_ButtonDown -= DownMethod;
}
void DownMethod(string btnName) {
print(btnName+ " Down ");
}
其他方法類似.
- Easy Joystick(搖桿)
搖桿
可檢測的事件有如下幾種:
#region Event
/// <summary>
/// Occurs the joystick starts move.
/// </summary>
public static event JoystickMoveStartHandler On_JoystickMoveStart;
/// <summary>
/// Occurs when the joystick move.
/// </summary>
public static event JoystickMoveHandler On_JoystickMove;
/// <summary>
/// Occurs when the joystick stops move
/// </summary>
public static event JoystickMoveEndHandler On_JoystickMoveEnd;
/// <summary>
/// Occurs when a touch start hover the joystick
/// </summary>
public static event JoystickTouchStartHandler On_JoystickTouchStart;
/// <summary>
/// Occurs when a tap happen‘s on the joystick
/// </summary>
public static event JoystickTapHandler On_JoystickTap;
/// <summary>
/// Occurs when a double tap happen‘s on the joystick
/// </summary>
public static event JoystickDoubleTapHandler On_JoystickDoubleTap;
/// <summary>
/// Occurs when touch up happen‘s on the joystick
/// </summary>
public static event JoystickTouchUpHandler On_JoystickTouchUp;
#endregion
監聽方式:
- 獲取搖桿的位置信息:
public EasyJoystick joystick;//把搖桿的GO指定到這裏即可
// Update is called once per frame
void Update ()
{
print(joystick.JoystickAxis);
}
- 其余監聽方式可參考Easy Button.
- Easy Touch
讓GO響應用戶的操做,如:點擊,雙擊,滑動… …
Easy Touch可響應的方法比較多(參考源碼EasyTouch.cs):
#region Events
/// <summary>
/// Occurs when The system cancelled tracking for the touch, as when (for example) the user puts the device to her face.
/// </summary>
public static event TouchCancelHandler On_Cancel;
/// <summary>
/// Occurs when the touch count is no longer egal to 2 and different to 0, after the begining of a two fingers gesture.
/// </summary>
public static event Cancel2FingersHandler On_Cancel2Fingers;
/// <summary>
/// Occurs when a finger touched the screen.
/// </summary>
public static event TouchStartHandler On_TouchStart;
/// <summary>
/// Occurs as the touch is active.
/// </summary>
public static event TouchDownHandler On_TouchDown;
/// <summary>
/// Occurs when a finger was lifted from the screen.
/// </summary>
public static event TouchUpHandler On_TouchUp;
/// <summary>
/// Occurs when a finger was lifted from the screen, and the time elapsed since the beginning of the touch is less than the time required for the detection of a long tap.
/// </summary>
public static event SimpleTapHandler On_SimpleTap;
/// <summary>
/// Occurs when the number of taps is egal to 2 in a short time.
/// </summary>
public static event DoubleTapHandler On_DoubleTap;
/// <summary>
/// Occurs when a finger is touching the screen, but hasn‘t moved since the time required for the detection of a long tap.
/// </summary>
public static event LongTapStartHandler On_LongTapStart;
/// <summary>
/// Occurs as the touch is active after a LongTapStart
/// </summary>
public static event LongTapHandler On_LongTap;
/// <summary>
/// Occurs when a finger was lifted from the screen, and the time elapsed since the beginning of the touch is more than the time required for the detection of a long tap.
/// </summary>
public static event LongTapEndHandler On_LongTapEnd;
/// <summary>
/// Occurs when a drag start. A drag is a swipe on a pickable object
/// </summary>
public static event DragStartHandler On_DragStart;
/// <summary>
/// Occurs as the drag is active.
/// </summary>
public static event DragHandler On_Drag;
/// <summary>
/// Occurs when a finger that raise the drag event , is lifted from the screen.
/// </summary>/
public static event DragEndHandler On_DragEnd;
/// <summary>
/// Occurs when swipe start.
/// </summary>
public static event SwipeStartHandler On_SwipeStart;
/// <summary>
/// Occurs as the swipe is active.
/// </summary>
public static event SwipeHandler On_Swipe;
/// <summary>
/// Occurs when a finger that raise the swipe event , is lifted from the screen.
/// </summary>
public static event SwipeEndHandler On_SwipeEnd;
/// <summary>
/// Like On_TouchStart but for a 2 fingers gesture.
/// </summary>
public static event TouchStart2FingersHandler On_TouchStart2Fingers;
/// <summary>
/// Like On_TouchDown but for a 2 fingers gesture.
/// </summary>
public static event TouchDown2FingersHandler On_TouchDown2Fingers;
/// <summary>
/// Like On_TouchUp but for a 2 fingers gesture.
/// </summary>
public static event TouchUp2FingersHandler On_TouchUp2Fingers;
/// <summary>
/// Like On_SimpleTap but for a 2 fingers gesture.
/// </summary>
public static event SimpleTap2FingersHandler On_SimpleTap2Fingers;
/// <summary>
/// Like On_DoubleTap but for a 2 fingers gesture.
/// </summary>
public static event DoubleTap2FingersHandler On_DoubleTap2Fingers;
/// <summary>
/// Like On_LongTapStart but for a 2 fingers gesture.
/// </summary>
public static event LongTapStart2FingersHandler On_LongTapStart2Fingers;
/// <summary>
/// Like On_LongTap but for a 2 fingers gesture.
/// </summary>
public static event LongTap2FingersHandler On_LongTap2Fingers;
/// <summary>
/// Like On_LongTapEnd but for a 2 fingers gesture.
/// </summary>
public static event LongTapEnd2FingersHandler On_LongTapEnd2Fingers;
/// <summary>
/// Occurs when a twist gesture start
/// </summary>
public static event TwistHandler On_Twist;
/// <summary>
/// Occurs as the twist gesture is active.
/// </summary>
public static event TwistEndHandler On_TwistEnd;
/// <summary>
/// Occurs as the twist in gesture is active.
/// </summary>
public static event PinchInHandler On_PinchIn;
/// <summary>
/// Occurs as the pinch out gesture is active.
/// </summary>
public static event PinchOutHandler On_PinchOut;
/// <summary>
/// Occurs when the 2 fingers that raise the pinch event , are lifted from the screen.
/// </summary>
public static event PinchEndHandler On_PinchEnd;
/// <summary>
/// Like On_DragStart but for a 2 fingers gesture.
/// </summary>
public static event DragStart2FingersHandler On_DragStart2Fingers;
/// <summary>
/// Like On_Drag but for a 2 fingers gesture.
/// </summary>
public static event Drag2FingersHandler On_Drag2Fingers;
/// <summary>
/// Like On_DragEnd2Fingers but for a 2 fingers gesture.
/// </summary>
public static event DragEnd2FingersHandler On_DragEnd2Fingers;
/// <summary>
/// Like On_SwipeStart but for a 2 fingers gesture.
/// </summary>
public static event SwipeStart2FingersHandler On_SwipeStart2Fingers;
/// <summary>
/// Like On_Swipe but for a 2 fingers gesture.
/// </summary>
public static event Swipe2FingersHandler On_Swipe2Fingers;
/// <summary>
/// Like On_SwipeEnd but for a 2 fingers gesture.
/// </summary>
public static event SwipeEnd2FingersHandler On_SwipeEnd2Fingers;
/// <summary>
/// Occurs when easy touch is ready.
/// </summary>
public static event EasyTouchIsReadyHandler On_EasyTouchIsReady;
#endregion
事件監聽方式有三:
- 通過指定Receiver來監聽事件:
勾選Broadcast message,指定對應的GO,GO的腳本內協商對應代碼,並把這個GO指定給Other receiver.
void On_TouchStart(Gesture g) //方法名和上面提到的event中要一樣
{
Debug.Log("TouchStart:" + g.position);
}
- 創建腳本
參考前面的Easy Button中的用法,把我們的方法註冊到對應的事件中.
void Start(){
EasyTouch.On_TouchStart += On_TouchStart;
}
void On_TouchStart(Gesture gesture){
Print("Touch Start");
}
- 對某一Layer的Go統一監聽.
指定GO所在的Layer
設置EasyTouch響應的Layers
說明:
- Easy Touch的運作方式是通過OnGUI來實現的.參考區別於NGUI.EasyTouch只在Game視圖下能看到按鈕.
- 方法註冊到事件,應該有註冊有註銷.
歡迎交流 : D:[email protected]
Easy Touch 簡單筆記