Unity獲取滑鼠滾輪資訊

2021-10-03 11:49:25 字數 3847 閱讀 9837

ugui關於滑鼠滾輪資訊的獲取有乙個專門的介面iscrollhandler用於接收滾輪事件。繼承該事件之後便需要實現函式onscroll

如下:

public

virtual

void

onscroll

(pointereventdata eventdata)

該函式接收的引數pointereventdata,如下:

using system;

using system.collections.generic;

namespace unityengine.eventsystems

//// 摘要:

// the camera associated with the last onpointerpress event.

public

camera presseventcamera

//// 摘要:

// the camera associated with the last onpointerenter event.

public

camera entereventcamera

//// 摘要:

// the eventsystems.pointereventdata.inputbutton for this event.

public

inputbutton button

//// 摘要:

// determines whether the user is dragging the mouse or trackpad.

public

bool dragging

//// 摘要:

// should a drag threshold be used?

public

bool usedragthreshold

//// 摘要:

// the amount of scroll since the last update.

public

vector2 scrolldelta

//// 摘要:

// number of clicks in a row.

public

int clickcount

//// 摘要:

// the last time a click event was sent.

public

float clicktime

[obsolete

("use either pointercurrentraycast.worldnormal or pointerpressraycast.worldnormal")]

public

vector3 worldnormal

[obsolete

("use either pointercurrentraycast.worldposition or pointerpressraycast.worldposition")]

public

vector3 worldposition

//// 摘要:

// the screen space coordinates of the last pointer click.

public

vector2 pressposition

//// 摘要:

// pointer delta since last update.

public

vector2 delta

//// 摘要:

// current pointer position.

public

vector2 position

//// 摘要:

// identification of the pointer.

public

int pointerid

public

bool eligibleforclick

//// 摘要:

// raycastresult associated with the pointer press.

public

raycastresult pointerpressraycast

//// 摘要:

// raycastresult associated with the current event.

public

raycastresult pointercurrentraycast

//// 摘要:

// the object that is receiving ondrag.

public

gameobject pointerdrag

//// 摘要:

public

gameobject rawpointerpress

//// 摘要:

// the gameobject for the last press event.

public

gameobject lastpress

//// 摘要:

// the object that received 'onpointerenter'.

public

gameobject pointerenter

//// 摘要:

// is the pointer moving.

//// 返回結果:

// moving.

public

bool

ispointermoving()

;//// 摘要:

// is scroll being used on the input device.

//// 返回結果:

// scrolling.

public

bool

isscrolling()

;public

override

string

tostring()

;//// 摘要:

// input press tracking.

public

enum inputbutton

//// 摘要:

// the state of a press for the given frame.

public

enum framepressstate

}}

其中,vector2型別的字段scrolldelta中的y,便是滾輪滾動的資訊具體數值資訊:上滑滾輪為正1,下滑滾輪為負1

通過input獲取滾輪資訊的方式為input.getaxis("mouse scrollwheel")

public

void

onupdate()

通過測試便可得到如下效果:

滾輪上滑為正,下滑為負;且滾輪的每個小格卡頓,其數值資訊表示為0.1,快速連續滾動時其數值會直接出現對應的數值,不會一格一格出現。

獲取滑鼠資訊

1.獲取滑鼠雙擊時間間隔 連續兩次滑鼠單擊之間會被處理成雙擊事件的時間間隔 重寫api函式 dllimport user32.dll entrypoint getdoubleclicktime public extern static int getdoubleclicktime 2.獲取游標閃爍的...

滑鼠 5 滾輪

這不是乙個噱頭,看 雖然很長,但卻很經典,可以實現鍵盤,滾輪滑動滾動條。下面是標頭檔案,是儲存的資料。define numlines int sizeof sysmetrics sizeof sysmetrics 0 struct sysmetrics 來了 include include incl...

滑鼠滾輪事件

新增事件 有相容性 註冊事件 if document.addeventlistener window.onmousewheel document.onmousewheel scrollfunc ie opera chrome detail與wheeldelta 判斷滾輪向上或向下在瀏覽器中也有相容性...