roblox object event
v1.1.0
@rbxts/object-event
這個針對Roblox-TS的NPM軟件包允許開發人員在無需訴諸BindableEvents
情況下實現自定義事件。
這對於嚴重依賴庫和其他遊戲組件的OOP範式的項目特別有用。
該模塊可以在純LUA(U)腳本(通過ROJO或任何其他方式)或Roblox-Ts中使用(包括編譯時類型檢查)。
/////// Module.ts ///////
import ObjectEvent from "@rbxts/object-event"
const event = new ObjectEvent < [ number , String , Vector3 ] > ( )
event . Connect ( ( id , msg , position ) => {
// We can safely assume that:
// id is a number
// msg is a string
// position is a Vector3
} )
export event
/////// Waiter.server.ts ///////
import { event } from "./Module"
event . Fire ( 10 , "oof" , new Vector3 ( 1 , 2 , 3 ) ) // all good
event . Fire ( 10 , "oof" ) // will not compile!
export { }
允許任何數字的各種參數:
let event = new ObjectEvent < [ ... unknown ] > ( )
ObjectEvent
APIConnect(f)
- f
是一個將相應鍵入的參數並返回void
函數。返回ObjectEventConnection
Wait()
- 產生線程直到事件發射為止。返回相應鍵入的值。Fire(...)
- 開火。參數必須是事件的數字和類型。Event
- RBXScriptSignal
類似於Connect()
和Wait()
的接口,以防萬一您更喜歡將其用作bindableEvent。SubscribedConnections
一個ObjectEventConnection
s的數組,當前正在偵聽事件的所有連接。 ObjectEventConnection
APIDisconnect()
- 與事件斷開連接Reconnect()
- 恢復斷開連接IsConnected()
- 如果連接正在收聽事件(這不是disconnect()'ed),則返回true
,否則為false
。Event
- 與此連接關聯的ObjectEvent
Listener
- 與此連接關聯的功能