This commit is contained in:
sli97
2022-12-03 21:28:38 +08:00
parent f3dc3ef7ba
commit a678a5b3fc
10 changed files with 76 additions and 32 deletions

View File

@@ -7,7 +7,8 @@ import { PrefabPathEnum, TexturePathEnum } from '../Enum';
import NetworkManager from '../Global/NetworkManager';
import ObjectPoolManager from '../Global/ObjectPoolManager';
import { BulletManager } from '../Entity/Bullet/BulletManager';
import { EntityTypeEnum, InputTypeEnum } from '../Common';
import { ApiMsgEnum, EntityTypeEnum, IMsgServerSync, InputTypeEnum } from '../Common';
import { toFixed } from '../Utils';
const { ccclass } = _decorator;
@@ -26,6 +27,7 @@ export class BattleManager extends Component {
await this.loadRes()
this.initScene()
await this.connectServer()
NetworkManager.Instance.listenMsg(ApiMsgEnum.MsgServerSync, this.handleSync);
this.isInited = true
}
@@ -84,6 +86,12 @@ export class BattleManager extends Component {
map.setParent(this.stage)
}
handleSync({ inputs }: IMsgServerSync) {
for (const input of inputs) {
DataManager.Instance.applyInput(input)
}
}
update(dt: number) {
if (!this.isInited) {
return
@@ -108,9 +116,11 @@ export class BattleManager extends Component {
}
tickGlobal(dt: number) {
DataManager.Instance.applyInput({
type: InputTypeEnum.TimePast,
dt
NetworkManager.Instance.sendMsg(ApiMsgEnum.MsgClientSync, {
input: {
type: InputTypeEnum.TimePast,
dt: toFixed(dt),
}
})
}