日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ngui 输入事件处理

發布時間:2025/3/19 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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.


但它的缺點就是。這些事件都要基于碰撞體。也就是說,若要使用這些函數,就必須將腳本所在的gameobject上加入碰撞體。!!

這樣。假設出現多層疊加的情況,就比較糾結了。

比方如今有這樣一個需求:

1、有一個面板,這個面板支持左右拖動。而且在此面包上的不論什么地方拖動都有效!

2、此面板上有個button。

3、當在button上左右拖拽時,面板也要感應到拖拽事件!

若要完畢這個需求,首先須要有兩個碰撞體,非常明顯,button的碰撞體要在面板的上面。但這樣無法完畢第三條需求。


幸運的是,NGUI為我們留了個后門!它能夠設置一個默認的事件接受體。

切此gameobjec不須要碰撞體!

static public GameObject genericEventHandler;如今實現上面提到的三個需求。

1、將面板的gameobject賦值給genericEventHandler。

2、給面板上的某個腳本加入一個OnDrag函數

3、加入一個button(有碰撞體)

這樣就攻克了上面的問題,且僅僅須要一個碰撞體!


與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的ngui 输入事件处理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。