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

@ -30,10 +30,10 @@ import { Component } from "cc";
// let APIPath = `http://localhost:8080` // let APIPath = `http://localhost:8080`
// let WsPath = `ws://localhost:8080/websocket` // let WsPath = `ws://localhost:8080/websocket`
let APIPath = `http://192.168.1.23:8080` // let APIPath = `http://192.168.1.23:8080`
let WsPath = `ws://192.168.1.23:8080/websocket` // let WsPath = `ws://192.168.1.23:8080/websocket`
// let APIPath = `http://192.168.0.113:8080` let APIPath = `http://192.168.0.128:8080`
// let WsPath = `ws://192.168.0.113:8080/websocket` let WsPath = `ws://192.168.0.128:8080/websocket`
// let APIPath = `https://api.pet.jisol.cn` // let APIPath = `https://api.pet.jisol.cn`
// let WsPath = `wss://api.pet.jisol.cn/websocket` // let WsPath = `wss://api.pet.jisol.cn/websocket`
@ -148,7 +148,7 @@ export class JLoaderBattle extends JLoaderSystem{
//资源 //资源
resources:{[id:number]:Asset} = {}; resources:{[id:number]:Asset} = {};
foreverResources:number[] = []; //永久资源Id battleResources:number[] = []; //战斗资源Id
async onInit(): Promise<any> { async onInit(): Promise<any> {
@ -161,28 +161,28 @@ export class JLoaderBattle extends JLoaderSystem{
app.loading.setCurrent(JLoaderBattle.loadingInit); app.loading.setCurrent(JLoaderBattle.loadingInit);
//默认加载全部资源 //默认加载全部资源
await this.loadForeverResources(...TD.TbBattleResource.getDataList()); await this.loadBattleResources(...TD.TbBattleResource.getDataList());
app.loading.ok(JLoaderBattle.loadingInit); app.loading.ok(JLoaderBattle.loadingInit);
} }
//加载永久资源 //加载战斗资源
async loadForeverResources(...ress:TB.TbBattleResource[]){ async loadBattleResources(...ress:TB.TbBattleResource[]){
for (const res of ress) { for (const res of ress) {
await this.loadForeverResource(res); await this.loadBattleResource(res);
} }
} }
//加载永久资源 //加载战斗资源
loadForeverResource(res:TB.TbBattleResource){ loadBattleResource(res:TB.TbBattleResource){
return (new Promise<void>(r => { return (new Promise<void>(r => {
let Type:new ()=>Asset = [sp.SkeletonData,SpriteFrame][res.type]; let Type:new ()=>Asset = [sp.SkeletonData,SpriteFrame][res.type];
this.bundle.load(res.path,Type,(error,data) => { this.bundle.load(res.path,Type,(error,data) => {
if(this.foreverResources.indexOf(res.id) < 0){ if(this.battleResources.indexOf(res.id) < 0){
//添加永久资源 //添加永久资源
this.resources[res.id] = data; this.resources[res.id] = data;
data.addRef(); data.addRef();
@ -213,14 +213,14 @@ export class JLoaderBattle extends JLoaderSystem{
})) }))
} }
//销毁久资源 //销毁久资源
clearForeverResources(...ress:TB.TbBattleResource[]){ clearBattleResources(...ress:TB.TbBattleResource[]){
this.foreverResources.forEach(id => { this.battleResources.forEach(id => {
if(this.resources[id]){ if(this.resources[id]){
this.resources[id].decRef(); this.resources[id].decRef();
} }
}); });
this.foreverResources = []; this.battleResources = [];
this.onUpdateResources(); this.onUpdateResources();
} }

View File

@ -4,10 +4,12 @@ import { Camera } from "cc";
import GBaseMode from "./GBaseMode"; import GBaseMode from "./GBaseMode";
import { Node } from "cc"; import { Node } from "cc";
import { instantiate } 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 { JNFrameInfo, JNSyncFrameEvent } from "../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
import { CCObject } from "cc"; import { CCObject } from "cc";
import { Env, EnvCurrent } from "../Env"; import { Env, EnvCurrent } from "../Env";
import { TB } from "../../resources/config/data/schema";
import BattleResource from "../tools/BattleResource";
export enum BattleMode{ export enum BattleMode{
//无尽模式 //无尽模式
@ -26,6 +28,8 @@ export interface GBattleModeInfo{
export enum GBattleModeEvent{ export enum GBattleModeEvent{
//关闭模式 //关闭模式
Close = "GBattleModeEvent_Close", Close = "GBattleModeEvent_Close",
StartLoadingResource = "GBattleModeEvent_StartLoadingResource",
EndLoadingResource = "GBattleModeEvent_EndLoadingResource",
} }
//全局战斗模式管理器 //全局战斗模式管理器
@ -61,6 +65,12 @@ export default class GBattleModeManager extends Singleton {
//模式数据 //模式数据
data:any; data:any;
//是否加载资源
isLoadingResource:boolean = false;
//加载index
loadingIndex:number = 0;
//初始化管理器 //初始化管理器
async onInit(info:GBattleModeInfo){ 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){ async Open(mode:BattleMode = null,isAuto:boolean = false,data:any = this.data){
this.Close();
this.data = data; this.data = data;
if(!this.current && mode == null){ if(!this.current && mode == null){
@ -89,10 +104,25 @@ export default class GBattleModeManager extends Singleton {
}else if(mode == null){ }else if(mode == null){
return; return;
} }
this.current = mode; this.current = mode;
this.setAuto(isAuto); 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.onReset();
app.sync.onStart(); app.sync.onStart();

View File

@ -0,0 +1,26 @@
import { TB } from "../../resources/config/data/schema";
import { TD, app } from "../App";
import { BattleMode } from "../battle/GBattleModeManager";
export default class BattleResource {
//根据参数获取可能加载的资源
static getResources(mode:BattleMode,data:any):TB.TbBattleResource[]{
switch(mode){
default:
return TD.TbBattleResource.getDataList();
}
}
//加载资源
static async loadResource(mode:BattleMode,data:any){
let resources = this.getResources(mode,data);
//加载资源
await app.battleRes.loadBattleResources(...resources);
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "d90fa0e9-c8d6-44f4-aad2-41aac59b7e59",
"files": [],
"subMetas": {},
"userData": {}
}