This commit is contained in:
PC-20230316NUNE\Administrator
2023-12-07 21:34:26 +08:00
parent 931f580082
commit fae958aac6
5 changed files with 375 additions and 297 deletions

View File

@@ -4,10 +4,12 @@ import { Camera } from "cc";
import GBaseMode from "./GBaseMode";
import { Node } from "cc";
import { instantiate } from "cc";
import { app } from "../App";
import { TD, app } from "../App";
import { JNFrameInfo, JNSyncFrameEvent } from "../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
import { CCObject } from "cc";
import { Env, EnvCurrent } from "../Env";
import { TB } from "../../resources/config/data/schema";
import BattleResource from "../tools/BattleResource";
export enum BattleMode{
//无尽模式
@@ -26,6 +28,8 @@ export interface GBattleModeInfo{
export enum GBattleModeEvent{
//关闭模式
Close = "GBattleModeEvent_Close",
StartLoadingResource = "GBattleModeEvent_StartLoadingResource",
EndLoadingResource = "GBattleModeEvent_EndLoadingResource",
}
//全局战斗模式管理器
@@ -61,6 +65,12 @@ export default class GBattleModeManager extends Singleton {
//模式数据
data:any;
//是否加载资源
isLoadingResource:boolean = false;
//加载index
loadingIndex:number = 0;
//初始化管理器
async onInit(info:GBattleModeInfo){
@@ -77,8 +87,13 @@ export default class GBattleModeManager extends Singleton {
}
//打开指定模式
// isAuto 是否自动推帧
// data 模式数据
// res 资源加载列表 (因为是帧同步所以打开模式前必须提前加载可能使用的资源)
async Open(mode:BattleMode = null,isAuto:boolean = false,data:any = this.data){
this.Close();
this.data = data;
if(!this.current && mode == null){
@@ -89,10 +104,25 @@ export default class GBattleModeManager extends Singleton {
}else if(mode == null){
return;
}
this.current = mode;
this.setAuto(isAuto);
//加载资源
let loadingIndex = (this.loadingIndex+=1);
this.isLoadingResource = true;
app.event.emit(GBattleModeEvent.StartLoadingResource);
console.log("[GBattleModeManager] 加载资源");
await BattleResource.loadResource(mode,data);
console.log("[GBattleModeManager] 加载结束",loadingIndex,this.loadingIndex);
if(this.loadingIndex == loadingIndex){
this.isLoadingResource = false;
app.event.emit(GBattleModeEvent.EndLoadingResource);
}else{
//如果加载中途切换了模式则直接返回
return;
}
//资源加载完成则显示世界
app.sync.onReset();
app.sync.onStart();