55 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2023-10-23 18:56:01 +08:00
import { Vec2 } from "cc";
import GObject from "./base/GObject";
import { v3 } from "cc";
2023-10-26 03:06:44 +08:00
import { JNFrameInfo } from "../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
2023-10-30 02:34:11 +08:00
import { Node } from "cc";
import { Vec3 } from "cc";
2023-11-03 02:57:38 +08:00
import { Camera } from "cc";
2023-11-21 01:57:40 +08:00
import GBattleModeManager from "./GBattleModeManager";
2023-10-23 18:56:01 +08:00
2023-11-21 01:57:40 +08:00
export default class GBaseMode<T,DT> extends GObject<T> {
2023-10-23 18:56:01 +08:00
2023-11-03 02:57:38 +08:00
//场景相机
camera:Camera;
2023-11-21 01:57:40 +08:00
//模式数据
data:DT;
2023-11-03 02:57:38 +08:00
2023-10-31 02:34:12 +08:00
get scene():Node{
return this.node;
}
2023-10-23 18:56:01 +08:00
//添加对象到场景中
2023-10-30 02:34:11 +08:00
addGObject(obj: GObject<{}>,pos?:Vec2 | Vec3){
2023-10-24 02:32:06 +08:00
obj.mode = this;
2023-10-31 02:34:12 +08:00
this.scene.addChild(obj.node);
2023-10-23 18:56:01 +08:00
if(pos){
obj.node.setWorldPosition(v3(pos.x,pos.y,0));
}
}
2023-10-30 02:34:11 +08:00
//添加Node到场景中
addGNode(obj:Node,pos?:Vec2 | Vec3){
2023-10-31 02:34:12 +08:00
this.scene.addChild(obj);
2023-10-30 02:34:11 +08:00
if(pos){
obj.setWorldPosition(v3(pos.x,pos.y,0));
}
}
2023-11-21 01:57:40 +08:00
//结束场景
2023-11-22 17:46:08 +08:00
Close(data?:any){
GBattleModeManager.getIns().Close(data);
2023-11-21 01:57:40 +08:00
}
2023-10-26 03:06:44 +08:00
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: T) {
//重置 场景中的层级
2023-11-04 05:56:28 +08:00
[...this.scene.children].sort((node1,node2) => node2.worldPosition.y - node1.worldPosition.y).forEach((node,index) => {
2023-10-26 03:06:44 +08:00
node.setSiblingIndex(index);
})
}
2023-10-23 18:56:01 +08:00
}