跳至主要內容

Class: event_target<CT>

muzzik大约 2 分钟

index / event_target

Class: event_target<CT>

事件对象(类型安全)

Remarks

获取事件键使用 event_target.key.xxx

Type parameters

Name
CT

Hierarchy

  • EventTarget

    event_target

Table of contents

Properties

Methods

Properties

key

key: { [k in string | number | symbol]: k }

事件键

Defined in

assets/@framework/mk_event_target.ts:11open in new window

Methods

on

on<T, T2>(type_, callback_, target_?, once_b_?): null | T2

监听事件

Type parameters

NameType
Textends string | number | symbol
T2extends (...event_: Parameters<CT[T]>) => void

Parameters

NameTypeDescription
type_T | T[]事件类型
callback_T2触发回调
target_?any事件目标对象
once_b_?boolean是否触发单次

Returns

null | T2

触发回调

Overrides

cc.EventTarget.on

Defined in

assets/@framework/mk_event_target.ts:25open in new window


once

once<T, T2>(type_, callback_, target_?): null | T2

监听单次事件

Type parameters

NameType
Textends string | number | symbol
T2extends (...event_: Parameters<CT[T]>) => void

Parameters

NameTypeDescription
type_T | T[]事件类型
callback_T2触发回调
target_?any事件目标对象

Returns

null | T2

触发回调

Overrides

cc.EventTarget.once

Defined in

assets/@framework/mk_event_target.ts:53open in new window


off

off<T, T2>(type_, callback_?, target_?): void

取消监听事件

Type parameters

NameType
Textends string | number | symbol
T2extends (...event_: Parameters<CT[T]>) => void

Parameters

NameTypeDescription
type_T | T[]事件类型
callback_?T2触发回调
target_?any事件目标对象

Returns

void

触发回调

Overrides

cc.EventTarget.off

Defined in

assets/@framework/mk_event_target.ts:80open in new window


emit

emit<T, T2>(type_, ...args_): void

派发事件

Type parameters

NameType
Textends string | number | symbol
T2extends unknown[]

Parameters

NameTypeDescription
type_T | T[]事件类型
...args_T2事件参数

Returns

void

Overrides

cc.EventTarget.emit

Defined in

assets/@framework/mk_event_target.ts:96open in new window


has

has<T, T2>(type_, callback_?, target_?): boolean

是否存在事件

Type parameters

NameType
Textends string | number | symbol
T2extends (...event_: Parameters<CT[T]>) => void

Parameters

NameTypeDescription
type_T事件类型
callback_?T2触发回调
target_?any事件目标对象

Returns

boolean

Defined in

assets/@framework/mk_event_target.ts:114open in new window


clear

clear(): void

清空所有事件

Returns

void

Defined in

assets/@framework/mk_event_target.ts:119open in new window


request

request<T, T2, T3>(type_, ...args_): Promise<T3>[]

请求事件

Type parameters

NameType
Textends string | number | symbol
T2extends unknown[]
T3extends unknown

Parameters

NameTypeDescription
type_T | T[]事件类型
...args_T2事件参数

Returns

Promise<T3>[]

Remarks

等待请求事件返回

Defined in

assets/@framework/mk_event_target.ts:132open in new window

📣 觉得很赞?分享给你的朋友吧!