Skip to content
RoomSettings

设置 / RoomSettings

RoomSettings Class

房间设置

使用示例:创建一个名为"ClassExample"的脚本,放置在对象栏中,打开脚本,输入以下代码保存,运行游戏,你将在服务器Log中看到对应方法调用信息。代码如下:
ts
@Component
export default class ClassExample extends Script {

    protected onStart(): void {
         this.RoomSettings();
    }

    @mw.RemoteFunction(mw.Server)
    public RoomSettings(){
        //设置玩家是否可以中途加入游戏
        RoomSettings.enableJoiningMidgame(true);

        let joinPeople = RoomSettings.isJoiningMidgameEnabled();
        console.log("玩家是否可以中途加入游戏:" + joinPeople);

        let players = RoomSettings.getMaxPlayers();
        console.log("游戏中玩家数量上限是:" + players + "人。");

        let resEnable = RoomSettings.isPlayerReserveEnabled();
        console.log("服务器预留玩家是否开启:" + resEnable);

        let resPlayers = RoomSettings.getReservedPlayers();
        console.log("服务器预留玩家数量是:" + resPlayers + "人。");
    }
}
@Component
export default class ClassExample extends Script {

    protected onStart(): void {
         this.RoomSettings();
    }

    @mw.RemoteFunction(mw.Server)
    public RoomSettings(){
        //设置玩家是否可以中途加入游戏
        RoomSettings.enableJoiningMidgame(true);

        let joinPeople = RoomSettings.isJoiningMidgameEnabled();
        console.log("玩家是否可以中途加入游戏:" + joinPeople);

        let players = RoomSettings.getMaxPlayers();
        console.log("游戏中玩家数量上限是:" + players + "人。");

        let resEnable = RoomSettings.isPlayerReserveEnabled();
        console.log("服务器预留玩家是否开启:" + resEnable);

        let resPlayers = RoomSettings.getReservedPlayers();
        console.log("服务器预留玩家数量是:" + resPlayers + "人。");
    }
}

Table of contents

Methods

enableJoiningMidgame(isEnable: boolean): void server
设置中途加入开关
getMaxPlayers(): number server
获取玩家数量上限
getReservedPlayers(): number server
获取服务器预留玩家数量
isJoiningMidgameEnabled(): boolean server
获取是否开启中途加入
isPlayerReserveEnabled(): boolean server
获取服务器预留玩家是否开启

Methods

enableJoiningMidgame

Static enableJoiningMidgame(isEnable): void server

设置中途加入开关

Parameters

isEnable boolean-true:开启中途加入 -false:关闭中途加入

getMaxPlayers

Static getMaxPlayers(): number server

获取玩家数量上限

Returns

numberDS房间玩家数量上限。如果返回值为undefined,请检查是否在服务端调用或者玩家数量上限是否为空

getReservedPlayers

Static getReservedPlayers(): number server

获取服务器预留玩家数量

Returns

number服务器预留玩家数量。如果返回值为undefined,请检查是否在服务端调用或者预留玩家数量是否为空

isJoiningMidgameEnabled

Static isJoiningMidgameEnabled(): boolean server

获取是否开启中途加入

Returns

booleantrue:开启中途加入 false:关闭中途加入。如果返回值为undefined,请检查是否在服务端调用

isPlayerReserveEnabled

Static isPlayerReserveEnabled(): boolean server

获取服务器预留玩家是否开启

Returns

boolean预留玩家功能是否开启。如果返回值为undefined,请检查是否在服务端调用或者预留玩家是否为空