跳转到内容

入口(Cocos)

入口 描述”玩家是怎么进入本次会话的”。冷启动、点推送、点好友的游戏邀请,情况各不相同。处理得好,玩家就能直接落到他们想去的位置。

async onGameReady() {
  const name = await FRVRSDK.instance.getEntrypointName();
  const data = await FRVRSDK.instance.getEntrypointData();

  switch (name) {
    case 'notification_tap':
      // 玩家点了推送。data.deepLink 告诉我们他们想去的地方。
      this.router.go(data.deepLink ?? 'home');
      break;

    case 'game_invite':
      // 好友邀请玩家加入某个具体房间。
      this.joinLobby(data.lobbyId);
      break;

    case 'share':
      // 玩家点开了别人分享的对局。
      this.startChallenge(data.seed, data.challengeId);
      break;

    default:
      this.router.go('home');
  }
}

if (data?.level) goToLevel(data.level);
  • getEntrypointName() 返回渠道提供的简短字符串,如 'notification_tap''game_invite''share''direct''home'
  • getEntrypointData() 返回入口创建时附带的任意 JSON 载荷(来自分享面板、计划推送、邀请等)。

把载荷视作 不可信输入 —— 它来自另一个客户端(或来自渠道的 URL 参数)。使用前先校验。

name === 'direct' / 'home' / null 都意味着”玩家就是直接打开了游戏”。把他们路由到正常的开始页即可。