Unity事件處理機制與NGUI事件機制,unity事件機制ngui
1 Unity原生
1.1 GUI
void OnGUI(){
if(GUI.Button(Rect position, string text)){
//點擊後立即執行
}
1.1 Input
每個手指觸控是通過Input.touches數據結構描述的:
-
fingerId 手指索引
The unique index for a touch. 觸摸的唯一索引。
-
position 位置
The screen position of the touch. 觸摸屏幕的位置。
-
deltaPosition 增量位置
The screen position change since the last frame.
自最後一幀改變的屏幕位置。
-
deltaTime 增量時間
Amount of time that has passed since the last state change.
從最後狀態改變到現在經過的時間
-
tapCount 點擊數
The iPhone/iPad screen is able to distinguish quick finger taps by the user. This counter will let you know how many times the user has tapped the screen without moving a finger to the sides. Android devices do not count number of taps, this field is always 1.
iPhone/iPad屏幕能夠識別用過的快速點擊, 這個計數器讓你知道用戶點擊屏幕多少次,而不是移動手指。android設備不對點擊計數,這個方法總是返回1
-
phase 相位(狀態)
Describes so called "phase" or the state of the touch. It can help you determine if the touch just began, if user moved the finger or if he just lifted the finger.
描述觸摸的狀態,可以幫助開發者確定用戶是否剛開始觸摸,是否用戶移動手指,是否用戶剛剛抬起手指。
Phase can be one of the following:
相位(狀態)可能是下列之一:
-
Began 開始
A finger just touched the screen. 手指剛剛觸摸屏幕
-
Moved 移動
A finger moved on the screen. 手指在屏幕上移動
-
Stationary 靜止
A finger is touching the screen but hasn't moved since the last frame.
手指觸摸屏幕,但是自最後一幀沒有移動
-
Ended 結束
A finger was lifted from the screen. This is the final phase of a touch.
手指從屏幕上抬起,這是觸控的最後狀態。
-
Canceled 取消
The system cancelled tracking for the touch, as when (for example) the user puts the device to her face or more than five touches happened simultaneously. This is the final phase of a touch.
系統取消了觸控跟蹤,如,用戶將設備放在了臉上或超過同時超過5個觸摸點。這是觸控的最後狀態。