Skip to content
Action1<T>

基础类型 / Action1

Action1<T> Class

一个参数的代理

使用示例: 一个参数的代理
ts
@Component
export default class ActionExample extends Script {

    private readonly action1:Action1<player> = new Action1();

    protected onStart(): void {

        // 添加Action1的监听
        const id = this.action1.add((player: player) => {
            if(player.age < 18) {
                console.log("sorry , only those over 18 years old can enter")
            } else {
                // 可以对player展开具体的实现逻辑
                player.game();
            }
        });

        InputUtil.onKeyDown(Keys.One, () => {
            let playerOne : multiPlayer = new multiPlayer(10.5,"Janny");
            this.action1.call(playerOne);
        });
    }
}
class player
{
    public age:number = 2;
    public name:string = "Li";
    constructor(age: number, name: string) {
        this.age = age;
        this.name = name;
    }
    public game(){
        console.log("player is playing game");
    }
}
class lowPlayer extends player
{
    public game(): void {
        console.log("lowplayer is playing game");
    }
}
class multiPlayer extends player
{
    public game(): void {
        console.log("multiPlayer is playing game");
    }
}
@Component
export default class ActionExample extends Script {

    private readonly action1:Action1<player> = new Action1();

    protected onStart(): void {

        // 添加Action1的监听
        const id = this.action1.add((player: player) => {
            if(player.age < 18) {
                console.log("sorry , only those over 18 years old can enter")
            } else {
                // 可以对player展开具体的实现逻辑
                player.game();
            }
        });

        InputUtil.onKeyDown(Keys.One, () => {
            let playerOne : multiPlayer = new multiPlayer(10.5,"Janny");
            this.action1.call(playerOne);
        });
    }
}
class player
{
    public age:number = 2;
    public name:string = "Li";
    constructor(age: number, name: string) {
        this.age = age;
        this.name = name;
    }
    public game(){
        console.log("player is playing game");
    }
}
class lowPlayer extends player
{
    public game(): void {
        console.log("lowplayer is playing game");
    }
}
class multiPlayer extends player
{
    public game(): void {
        console.log("multiPlayer is playing game");
    }
}

Type parameters

Name
T

Hierarchy

Table of contents

Accessors

click

Accessors

count(): number
监听方法的数量

Methods

click

Methods

add(fn: Function, thisArg?: any): number
添加一个监听方法
call(...params: any): void
执行
clear(): void
清除所有监听
includes(fn: Function, thisArg: any): boolean
判断是否包含某个监听方法
remove(fn: number Function, thisArg?: any): void
移除一个监听方法

Accessors

Methods