重构NetManager支持MessagePair,新增TSRPCWsClient。
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { Node, Vec3, instantiate, Prefab } from 'cc';
|
||||
import { instantiate, Node, Prefab } from 'cc';
|
||||
import { NetManager } from '../../Framework/Net/NetManager';
|
||||
import { ResMgr } from '../../Framework/ResMgr/ResMgr';
|
||||
import { MsgPlayerJoin } from '../../Shared/protocols/MsgPlayerJoin';
|
||||
import { MsgPlayerMove } from '../../Shared/protocols/MsgPlayerMove';
|
||||
import { PlayerInfo } from '../../Shared/protocols/PtlLogin';
|
||||
import { PlayerInfo } from '../../Shared/protocols/MsgResLogin';
|
||||
import { CameraController } from './CameraController';
|
||||
import { PlayerController } from './PlayerController';
|
||||
import { RemotePlayer } from './RemotePlayer';
|
||||
|
||||
@@ -33,7 +34,10 @@ export class World {
|
||||
/** 玩家模型预制体 */
|
||||
private playerPrefab: Prefab = null;
|
||||
|
||||
private constructor() {}
|
||||
/** 摄像机控制器 */
|
||||
private cameraController: CameraController = null;
|
||||
|
||||
private constructor() { }
|
||||
|
||||
public static getInstance(): World {
|
||||
if (!World.instance) {
|
||||
@@ -68,7 +72,7 @@ export class World {
|
||||
*/
|
||||
private async loadPlayerPrefab(): Promise<void> {
|
||||
try {
|
||||
this.playerPrefab = await ResMgr.getInstance().load('resources', 'res://Actor/M1/M1', Prefab);
|
||||
this.playerPrefab = await ResMgr.getInstance().load('res', 'Actor/M1/M1', Prefab);
|
||||
console.log('[World] 玩家模型预制体加载成功');
|
||||
} catch (error) {
|
||||
console.error('[World] 加载玩家模型预制体失败:', error);
|
||||
@@ -113,6 +117,10 @@ export class World {
|
||||
this.localPlayerController = this.localPlayerNode.addComponent(PlayerController);
|
||||
this.localPlayerController.init(this.localPlayer);
|
||||
|
||||
// 创建并绑定摄像机控制器(只有本地玩家需要)
|
||||
this.cameraController = this.worldRoot.addComponent(CameraController) as CameraController;
|
||||
this.cameraController.setTarget(this.localPlayerNode);
|
||||
|
||||
console.log('[World] 本地玩家创建完成:', this.localPlayer.name);
|
||||
}
|
||||
|
||||
@@ -198,6 +206,12 @@ export class World {
|
||||
}
|
||||
this.localPlayerController = null;
|
||||
|
||||
// 销毁摄像机控制器
|
||||
if (this.cameraController) {
|
||||
this.cameraController.node.removeComponent(CameraController);
|
||||
this.cameraController = null;
|
||||
}
|
||||
|
||||
// 销毁所有远程玩家
|
||||
this.remotePlayers.forEach((remotePlayer) => {
|
||||
remotePlayer.destroy();
|
||||
|
||||
Reference in New Issue
Block a user