2023-10-23 18:56:01 +08:00
|
|
|
import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
|
|
|
|
import { JNFrameInfo, JNSyncFrameEvent } from '../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame';
|
|
|
|
import { app } from './App';
|
|
|
|
import { JNSyncAction } from '../../extensions/ngame/assets/ngame/sync/JNSyncAction';
|
|
|
|
import { Camera } from 'cc';
|
2023-11-03 02:57:38 +08:00
|
|
|
import GBaseMode from './battle/GBaseMode';
|
2023-10-23 18:56:01 +08:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
@ccclass('WorldCanvas')
|
|
|
|
export class WorldCanvas extends Component {
|
|
|
|
|
|
|
|
@property(Node)
|
|
|
|
root:Node = null;
|
|
|
|
@property(Camera)
|
|
|
|
camera:Camera = null;
|
|
|
|
|
2023-11-03 02:57:38 +08:00
|
|
|
@property([Prefab])
|
|
|
|
prefabs:Prefab[] = [];
|
|
|
|
|
|
|
|
index:number = 0;
|
2023-10-23 18:56:01 +08:00
|
|
|
|
|
|
|
async onLoad(){
|
|
|
|
|
|
|
|
//重置相机位置
|
|
|
|
this.camera.node.setWorldPosition(0,0,1000);
|
|
|
|
|
|
|
|
//监听帧同步
|
|
|
|
app.event.on(JNSyncFrameEvent.CLEAR,this.clear,this);
|
|
|
|
app.event.on(JNSyncFrameEvent.CREATE,this.create,this);
|
|
|
|
|
|
|
|
//监听帧回调
|
|
|
|
app.socket.on(JNSyncAction.NSyncFrameBack,this.onFrameBack,this,"JNFrameInfo");
|
|
|
|
|
|
|
|
app.sync.onReset();
|
|
|
|
app.sync.onStart();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//清除世界
|
|
|
|
clear(){
|
|
|
|
this.root.removeAllChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
//创建世界
|
|
|
|
create(){
|
2023-11-03 02:57:38 +08:00
|
|
|
let world = instantiate(this.prefabs[this.index]);
|
|
|
|
world.getComponent(GBaseMode).camera = this.camera;
|
|
|
|
this.root.addChild(world)
|
2023-10-30 18:53:21 +08:00
|
|
|
this.scheduleOnce(() => {
|
|
|
|
app.sync.onStart();
|
|
|
|
});
|
2023-10-23 18:56:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
update(deltaTime: number) {
|
|
|
|
app.sync.update(deltaTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
onFrameBack(info:JNFrameInfo){
|
|
|
|
app.sync.addFrame(info,true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|