ngui 输入事件处理
生活随笔
收集整理的這篇文章主要介紹了
ngui 输入事件处理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
NGUI不僅提供了圖形接口,還提供了輸入事件接口!事件接口是通過UICamera來實現的。
Unity3d 為我們提供的原裝的input盡管非常方便,但真正跨平臺使用時(尤其是跨手機與Pc機時)仍然不是非常方便。
NGUI對input又進行了二次封裝,將全部平臺上的事件統一轉換成MouseOrTouch。
使用起來也比input要方便的多。input要在update中處理。而NGUI為我們提供了大量的函數,若要使用函數。僅僅須要在腳本中加入下列函數就可以:
/// - OnHover (isOver) is sent when the mouse hovers over a collider or moves away. /// - OnPress (isDown) is sent when a mouse button gets pressed on the collider. /// - OnSelect (selected) is sent when a mouse button is released on the same object as it was pressed on. /// - OnClick () is sent with the same conditions as OnSelect, with the added check to see if the mouse has not moved much. UICamera.currentTouchID tells you which button was clicked. /// - OnDoubleClick () is sent when the click happens twice within a fourth of a second. UICamera.currentTouchID tells you which button was clicked. /// - OnDrag (delta) is sent when a mouse or touch gets pressed on a collider and starts dragging it. /// - OnDrop (gameObject) is sent when the mouse or touch get released on a different collider than the one that was being dragged. /// - OnInput (text) is sent when typing (after selecting a collider by clicking on it). /// - OnTooltip (show) is sent when the mouse hovers over a collider for some time without moving. /// - OnScroll (float delta) is sent out when the mouse scroll wheel is moved. /// - OnKey (KeyCode key) is sent when keyboard or controller input is used.這樣。假設出現多層疊加的情況,就比較糾結了。
比方如今有這樣一個需求:
1、有一個面板,這個面板支持左右拖動。而且在此面包上的不論什么地方拖動都有效!
2、此面板上有個button。
3、當在button上左右拖拽時,面板也要感應到拖拽事件!
若要完畢這個需求,首先須要有兩個碰撞體,非常明顯,button的碰撞體要在面板的上面。但這樣無法完畢第三條需求。
幸運的是,NGUI為我們留了個后門!它能夠設置一個默認的事件接受體。
切此gameobjec不須要碰撞體!
static public GameObject genericEventHandler;如今實現上面提到的三個需求。1、將面板的gameobject賦值給genericEventHandler。
2、給面板上的某個腳本加入一個OnDrag函數
3、加入一個button(有碰撞體)
這樣就攻克了上面的問題,且僅僅須要一個碰撞體!
總結
以上是生活随笔為你收集整理的ngui 输入事件处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery元素过滤
- 下一篇: winfrom更新