37 行
1.2 KiB
TypeScript
37 行
1.2 KiB
TypeScript
|
|
import { _decorator, Component, Button, EditBox } from 'cc';
|
||
|
|
import { GameManager } from '../core/GameManager';
|
||
|
|
|
||
|
|
const { ccclass, property } = _decorator;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* LoginScene 负责游客/设备登录与角色选择入口。
|
||
|
|
*/
|
||
|
|
@ccclass('LoginScene')
|
||
|
|
export class LoginScene extends Component {
|
||
|
|
@property({ type: Button })
|
||
|
|
public loginButton: Button | null = null;
|
||
|
|
|
||
|
|
@property({ type: EditBox })
|
||
|
|
public nameInput: EditBox | null = null;
|
||
|
|
|
||
|
|
onLoad() {
|
||
|
|
this.loginButton?.node.on(Button.EventType.CLICK, this.onLogin, this);
|
||
|
|
}
|
||
|
|
|
||
|
|
async onLogin() {
|
||
|
|
const gm = GameManager.getInstance();
|
||
|
|
// TODO: 调用 AuthService/Register 或 Login
|
||
|
|
const resp = { code: 0, data: { player_id: 'p-001', nakama_token: 'token', character_id: 'c-001' } };
|
||
|
|
if (resp.code === 0) {
|
||
|
|
gm.setAuth(resp.data.player_id, resp.data.character_id, resp.data.nakama_token);
|
||
|
|
gm.networkManager?.setToken(resp.data.nakama_token);
|
||
|
|
gm.networkManager?.connectSocket();
|
||
|
|
gm.switchScene('LobbyScene');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
onDestroy() {
|
||
|
|
this.loginButton?.node.off(Button.EventType.CLICK, this.onLogin, this);
|
||
|
|
}
|
||
|
|
}
|