first
This commit is contained in:
89
assets/script/game/initialize/Initialize.ts
Normal file
89
assets/script/game/initialize/Initialize.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-11-11 17:45:23
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-17 12:38:59
|
||||
*/
|
||||
import { Node } from "cc";
|
||||
import { UICallbacks } from "../../../../extensions/oops-plugin-framework/assets/core/gui/layer/Defines";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { AsyncQueue, NextFunction } from "../../../../extensions/oops-plugin-framework/assets/libs/collection/AsyncQueue";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { LoadingViewComp } from "./view/LoadingViewComp";
|
||||
|
||||
/**
|
||||
* 游戏进入初始化模块
|
||||
* 1、热更新
|
||||
* 2、加载默认资源
|
||||
*/
|
||||
@ecs.register(`Initialize`)
|
||||
export class Initialize extends ecs.Entity {
|
||||
LoadingView!: LoadingViewComp;
|
||||
|
||||
protected init() {
|
||||
var queue: AsyncQueue = new AsyncQueue();
|
||||
|
||||
// 加载自定义资源
|
||||
this.loadCustom(queue);
|
||||
// 加载多语言包
|
||||
this.loadLanguage(queue);
|
||||
// 加载公共资源
|
||||
this.loadCommon(queue);
|
||||
// 加载游戏内容加载进度提示界面
|
||||
this.onComplete(queue);
|
||||
|
||||
queue.play();
|
||||
}
|
||||
|
||||
|
||||
/** 加载自定义内容(可选) */
|
||||
private loadCustom(queue: AsyncQueue) {
|
||||
queue.push(async (next: NextFunction, params: any, args: any) => {
|
||||
// 加载多语言对应字体
|
||||
oops.res.load("language/font/" + oops.language.current, next);
|
||||
});
|
||||
}
|
||||
|
||||
/** 加载化语言包(可选) */
|
||||
private loadLanguage(queue: AsyncQueue) {
|
||||
queue.push((next: NextFunction, params: any, args: any) => {
|
||||
// 设置默认语言
|
||||
let lan = oops.storage.get("language");
|
||||
// if (lan == null) {
|
||||
if (lan == null || lan == "") {
|
||||
lan = "zh";
|
||||
oops.storage.set("language", lan);
|
||||
}
|
||||
|
||||
// 设置语言包路径
|
||||
oops.language.pack.json = oops.config.game.languagePathJson;
|
||||
oops.language.pack.texture = oops.config.game.languagePathTexture;
|
||||
|
||||
// 加载语言包资源
|
||||
oops.language.setLanguage(lan, next);
|
||||
});
|
||||
}
|
||||
|
||||
/** 加载公共资源(必备) */
|
||||
private loadCommon(queue: AsyncQueue) {
|
||||
queue.push((next: NextFunction, params: any, args: any) => {
|
||||
oops.res.loadDir("common", next);
|
||||
});
|
||||
}
|
||||
|
||||
/** 加载完成进入游戏内容加载界面 */
|
||||
private onComplete(queue: AsyncQueue) {
|
||||
queue.complete = () => {
|
||||
var uic: UICallbacks = {
|
||||
onAdded: (node: Node, params: any) => {
|
||||
var comp = node.getComponent(LoadingViewComp) as ecs.Comp;
|
||||
this.add(comp);
|
||||
}
|
||||
};
|
||||
|
||||
// 界面管理 - 打开游戏内容资源加载进度提示界面
|
||||
oops.gui.open(UIID.Loading, null, uic);
|
||||
};
|
||||
}
|
||||
}
|
||||
9
assets/script/game/initialize/Initialize.ts.meta
Normal file
9
assets/script/game/initialize/Initialize.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ffbce42c-e99f-48a0-8e73-ea6b756af330",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
assets/script/game/initialize/LoadingViewComp.ts.meta
Normal file
9
assets/script/game/initialize/LoadingViewComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e316d2a4-1d8a-4f55-994c-f00db0076e7f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
12
assets/script/game/initialize/view.meta
Normal file
12
assets/script/game/initialize/view.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "a36c4006-66a4-4a3e-9f87-e64b179de4e5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
92
assets/script/game/initialize/view/LoadingViewComp.ts
Normal file
92
assets/script/game/initialize/view/LoadingViewComp.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-07-03 16:13:17
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-17 13:46:25
|
||||
*/
|
||||
import { _decorator } from "cc";
|
||||
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCVMParentComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCVMParentComp";
|
||||
import { UIID } from "../../common/config/GameUIConfig";
|
||||
import { smc } from "../../common/SingletonModuleComp";
|
||||
import { GameMap } from "../../map/GameMap";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 游戏资源加载 */
|
||||
@ccclass('LoadingViewComp')
|
||||
@ecs.register('LoadingView', false)
|
||||
export class LoadingViewComp extends CCVMParentComp {
|
||||
/** VM 组件绑定数据 */
|
||||
data: any = {
|
||||
/** 加载资源当前进度 */
|
||||
finished: 0,
|
||||
/** 加载资源最大进度 */
|
||||
total: 0,
|
||||
/** 加载资源进度比例值 */
|
||||
progress: "",
|
||||
/** 加载流程中提示文本 */
|
||||
prompt: ""
|
||||
};
|
||||
|
||||
private progress: number = 0;
|
||||
|
||||
reset(): void {
|
||||
// 获取用户信息的多语言提示文本
|
||||
this.data.prompt = oops.language.getLangByID("loading_load_player");
|
||||
|
||||
// 关闭加载界面
|
||||
oops.gui.remove(UIID.Loading);
|
||||
|
||||
// 释放加载界面资源
|
||||
oops.res.releaseDir("loading");
|
||||
|
||||
// 加载地图
|
||||
var map = ecs.getEntity<GameMap>(GameMap);
|
||||
map.load();
|
||||
smc.map = map;
|
||||
}
|
||||
|
||||
start() {
|
||||
this.loadRes();
|
||||
}
|
||||
|
||||
/** 加载资源 */
|
||||
private async loadRes() {
|
||||
this.data.progress = 0;
|
||||
this.loadCustom();
|
||||
this.loadGameRes();
|
||||
}
|
||||
|
||||
/** 加载游戏本地JSON数据(自定义内容) */
|
||||
private loadCustom() {
|
||||
// 加载游戏本地JSON数据的多语言提示文本
|
||||
this.data.prompt = oops.language.getLangByID("loading_load_json");
|
||||
}
|
||||
|
||||
/** 加载初始游戏内容资源 */
|
||||
private loadGameRes() {
|
||||
// 加载初始游戏内容资源的多语言提示文本
|
||||
this.data.prompt = oops.language.getLangByID("loading_load_game");
|
||||
|
||||
oops.res.loadDir("game", this.onProgressCallback.bind(this), this.onCompleteCallback.bind(this));
|
||||
}
|
||||
|
||||
/** 加载进度事件 */
|
||||
private onProgressCallback(finished: number, total: number, item: any) {
|
||||
this.data.finished = finished;
|
||||
this.data.total = total;
|
||||
|
||||
var progress = finished / total;
|
||||
if (progress > this.progress) {
|
||||
this.progress = progress;
|
||||
this.data.progress = (progress * 100).toFixed(2);
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载完成事件 */
|
||||
private onCompleteCallback() {
|
||||
this.ent.remove(LoadingViewComp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "92429ca4-4e7c-450a-b706-c96e7c2568e3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user