[Basic Type](../groups/Basic Type.Basic Type.md) / MulticastDelegate
MulticastDelegate<T> Class
Multicast delegate API
Effect
The calling end takes effect
Example usage: Create a script called "MultidelExample", open the script, enter the following code to save, run the game, and print out a+b:5.
ts
@Component
export default class MultidelExample extends Script {
// Example function that satisfies the DelegateFuncType constraint
public addNumbers(a: number, b: number): number {
let c = a + b;
console.log("a+b:"+ c);
return c;
}
protected onStart(): void {
// Instantiate MulticastDelegate class
const delegateInstance = new MulticastDelegate<typeof this.addNumbers>();
// Method for adding MulticastDelegate instance
delegateInstance.add(this.addNumbers);
// Method for broadcasting MulticastDelegate instances
delegateInstance.broadcast(2,3);
}
}@Component
export default class MultidelExample extends Script {
// Example function that satisfies the DelegateFuncType constraint
public addNumbers(a: number, b: number): number {
let c = a + b;
console.log("a+b:"+ c);
return c;
}
protected onStart(): void {
// Instantiate MulticastDelegate class
const delegateInstance = new MulticastDelegate<typeof this.addNumbers>();
// Method for adding MulticastDelegate instance
delegateInstance.add(this.addNumbers);
// Method for broadcasting MulticastDelegate instances
delegateInstance.broadcast(2,3);
}
}Type parameters
T | extends DelegateFuncType |
|---|
Implements
MulticastDelegateInterface<T>
Table of contents
Methods
add(func: T): void other |
|---|
| Add proxy event |
broadcast(...arg: Parameters<T>): void other |
| Trigger proxy event |
clear(): void other |
| Clear proxy events (dangerous operation, please note which proxy events you are clearing) |
remove(func: T): void other |
| Delete proxy event |
Type parameters
T | extends DelegateFuncType |
|---|
Methods
add
• add(func): void other
Add proxy event
Parameters
func T | Event callback function default |
|---|
Implementation of
MulticastDelegateInterface.add
broadcast
• broadcast(...arg): void other
Trigger proxy event
Parameters
...arg Parameters<T> | parameter |
|---|
Implementation of
MulticastDelegateInterface.broadcast
clear
• clear(): void other
Clear proxy events (dangerous operation, please note which proxy events you are clearing)
Implementation of
MulticastDelegateInterface.clear
remove
• remove(func): void other
Delete proxy event
Parameters
func T | Delete bound event default |
|---|
Implementation of
MulticastDelegateInterface.remove
Editor API