大侠
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

156 lines
6.1 KiB

import { _decorator, Component, director, JsonAsset, Label, PhysicsSystem2D, sys, tween, Tween, UIOpacity, Widget } from "cc";
import { EDITOR_NOT_IN_PREVIEW } from "cc/env";
import { MainConfig } from "../Launch/_MainConfig";
import { EBundleName, ESceneName, LoadSceneType } from "./const/GameEnum";
import { Launch } from "../Launch/Launch";
import ResLoad from "./ResUrl/ResLoad";
import LevelManager from "./Mgr_Load/LevelManager";
import RedPointLogic from "./Mgr_RedPoint/RedPointLogic";
import { LoadingMgr } from "./Mgr_Loading/LoadingMgr";
import { Utils } from "./ExUtils/Utils";
import { GameConfigUserDataConfigs, SDKConfigs, TaskConfigs } from "./Mgr_Loading/LoadTaskConfig";
import { AllLoadingMgr } from "./Mgr_Loading/AllLoadingMgr";
import PlatformManager from "./Platform/PlatformManager";
import { TDAnalyticsMgr } from "./Mgr_Ge/TDAnalyticsMgr";
import { GEData, GEType } from "./Mgr_Ge/GeDifine";
import { Global } from "./Global";
import { ESounds } from "./MesEvent/ESounds";
import { EResUrls } from "./ResUrl/EResUrls";
import { TXSDKMgr } from "./Mgr_Ge/TXSDKMgr";
import CsvMgr from "./Mgr_CSV/CsvMgr";
import { GEAnalyticsMgr } from "./Mgr_Ge/GEAnalyticsMgr";
import CySDK from "./Mgr_Ge/CySDK";
/**
* 主要加载脚本
* 加载顺序:
* 1->initServerData 获取服务器数据
* 2->initLodingGame 加载游戏资源
*/
window["PhysicsSystem2D"] = PhysicsSystem2D;
const { ccclass, property } = _decorator;
@ccclass
export default class ScriptLaunch extends Component {
/**进度条 */
private mProgress: number = 0;
/**加载开始时间 */
private loadTime: number = 0;
private FirstKey: string = `${MainConfig.Name}_${"FirstKey"}`
get is_first(): boolean {
return !sys.localStorage.getItem(this.FirstKey);
}
set is_first(value: boolean) {
sys.localStorage.setItem(this.FirstKey, value);
}
mLaunch: Launch;
public setClassPoxy(poxy: Launch) {
this.mLaunch = poxy;
this.startLoad();
}
private async startLoad() {
if (EDITOR_NOT_IN_PREVIEW) { return }
const Platform = window["wx"] || window["tt"];
if (Platform) {
ConsoleEx.Log(Platform.getSystemInfoSync())
}
PlatformManager.instance.init();
const PlatformData = PlatformManager.instance.platData;
TXSDKMgr.ins.init(PlatformData);
// 创游sdk
CySDK.appKey = PlatformData.Cy_appKey;
CySDK.init((data)=>{ConsoleEx.Log("创游SDK初始化:",data)});
ResLoad.Ins.InitLoadBundleList();
director.preloadScene(ESceneName.Loading);
this.loadTime = Date.now();
/**事件上传 */
TDAnalyticsMgr.ins.TrySendtrack(GEData.GEeventName.loadingpage_start, { loading_start_number:1 });
GEAnalyticsMgr.ins.TrySendtrack(GEType.loadingpage_start);
// TDAnalyticsMgr.ins.TrySendtrack(GEData.GEeventName.load_start, { is_first: this.is_first });
let allLoadMgr = new AllLoadingMgr(
(progress: number, message: string) => {
this.updateProgress(progress, message);
},
() => {
// this.ExcessiveScene();
this.SwitchScene();
},
(error: any) => {
console.error("初始化失败:", error);
this.updateProgress(0, "加载失败,请重试");
});
// allLoadMgr.addLoadingMgr(new LoadingMgr(SDKConfigs))
CsvMgr.GetHotVs(PlatformData,() => {
MainConfig.isReviewVer = CsvMgr.isReviewVer();
allLoadMgr.addLoadingMgr(new LoadingMgr(GameConfigUserDataConfigs))
allLoadMgr.addLoadingMgr(new LoadingMgr(TaskConfigs))
allLoadMgr.start();
})
if (Platform){
this.mLaunch.btn_restart.off('click');
this.mLaunch.btn_restart.on('click', () => {
ConsoleEx.Log("重启游戏")
TDAnalyticsMgr.ins.TrySendtrack(GEData.GEeventName.Ge_restart, "");
Platform.restartMiniProgram();
});
}
// 快手显示软著信息
if(window['ks']){
this.mLaunch.lab_Copyright.active = true;
this.mLaunch.lab_Copyright.getComponent(Label).string = PlatformData.Copyright;
}
}
/**更新进度显示 */
updateProgress(progress: number, Key: string) {
this.mLaunch.loading.getComponent(Label).string = Key;
if (this.mProgress < progress) {
let tickTime = 0.2;
let tIcon = this.mLaunch.ProgressBar.barSprite.node.children[0];
Tween.stopAllByTarget(this.mLaunch.ProgressBar)
tween(this.mLaunch.ProgressBar).to(tickTime, { progress: progress }, {
onUpdate: () => {
tIcon.getComponent(Widget)?.updateAlignment();
}
}).start();
this.mProgress = progress;
if (tIcon) {
tIcon.getComponent(Widget)?.updateAlignment();
}
}
}
/**场景透明过度开始 */
private ExcessiveScene() {
tween(this.mLaunch.mCanvas.node.getComponent(UIOpacity)).to(0.1, { opacity: 0 }).call(() => {
this.SwitchScene();
}).start();
}
/**切换场景 */
private SwitchScene() {
let alltime = Date.now() - this.loadTime;
ConsoleEx.Com("加载总时长", alltime, "ms");
RedPointLogic.init();
let tTmepTime = Date.now();
MainConfig.SendEventTime = tTmepTime;
LevelManager.LoadForest2(LoadSceneType.OpenDirectly, () => {
let tSceneTime = Date.now() - tTmepTime;
ConsoleEx.Com("场景加载时间", tSceneTime);
ResLoad.Ins.InitSecendBundleList();
TXSDKMgr.ins.LOAD_FINISH();
});
TDAnalyticsMgr.ins.TrySendtrack(GEData.GEeventName.subpackage_load_finish, { load_time:alltime });
// TDAnalyticsMgr.ins.TrySendtrack(GEData.GEeventName.load_success, { is_first: this.is_first, duration: Utils.MathUtils.MsToFloat(alltime) });
if (this.is_first) {
this.is_first = false;
}
}
}