在多人游戏中暂时限制房间访问
4 分
您可以使用锁定和解锁功能在您希望的时间限制或允许房间访问。
📘 请参考以下指南。 [ZEPETO.Multiplay(Server) API]
锁定
锁定功能是限制房间访问的功能。
await this.lock();
解锁
解锁功能是允许房间访问的功能。 但是,如果当前连接的人数与房间允许的最大人数相同,则房间无法解锁。
await this.unlock();
示例
以下是一个使用锁定和解锁功能的示例代码。
import { Sandbox, SandboxOptions, SandboxPlayer } from 'ZEPETO.Multiplay';
export default class extends Sandbox {
onCreate(options: SandboxOptions) {
}
async onJoin(client: SandboxPlayer) {
try {
if (this.clients.length > 8) {
await this.lock();
}
} catch(e) {
console.error(e);
}
}
async onLeave(client: SandboxPlayer, consented?: boolean){
try {
if (this.clients.length <= 8) {
await this.unlock();
}
} catch(e) {
console.error(e);
}
}
}👍 锁定和私有功能之间的区别
- 锁定的多人房间在 ZEPETO 房间列表中不可见,且无法通过邀请进入。
- 私有多人房间在 ZEPETO 房间列表中不显示,但可以接受邀请。