import { _decorator, director, game } from "cc"; import BaseUIForm from "./BaseUIForm"; import { MainConfig } from "../../Launch/_MainConfig"; import { EGlobalEvent } from "../MesEvent/EGlobalEvent"; import LevelManager, { ISceneLoadData } from "../Mgr_Load/LevelManager"; import { EBundleName } from "../const/GameEnum"; import MesMgr from "../MesEvent/MesMgr"; import UIMgr from "./UIMgr"; import PlatformManager from "../Platform/PlatformManager"; import { MINIGAME } from "cc/env"; const { ccclass, property } = _decorator; @ccclass export default class LodingBaseUI extends BaseUIForm{ m_param:ISceneLoadData; loadResComplete:boolean =false; loadSceneComplete:boolean =false; /**当前加载时间 */ protected CurTime:number = 0; protected minNeedTime:number = 0.2; /**是否可以切换场景 */ CanSwitchloding: boolean = true; getloadingComplete(){ return this.loadResComplete && this.loadSceneComplete; } protected start(): void { MesMgr.on(EGlobalEvent.MAINUI_READY, this.statCheckClose, this); } onShow(m_param?: ISceneLoadData){ this.m_param = m_param; //game.frameRate = _MainConfig.GameFarme//+localStorage.getItem("GameFrameRate") || 61; this.loadResComplete = false; this.loadSceneComplete = false; this.CanSwitchloding = true; } onDisplay(){ this.releaseRes(); this.starload(); } /**释放资源 */ protected releaseRes(){ MesMgr.event(EGlobalEvent.E_LOADING_SCENE_SWITCH); UIMgr.Ins.ClearAllWindow(); } /**开始加载 */ protected starload() { if(this.m_param.LoadGroup){ this.m_param.LoadGroup.load(this.LoadingCompleted.bind(this)); }else{ this.LoadingCompleted(); } director.preloadScene(this.m_param.scene_name,()=>{ this.loadSceneComplete = true; }) } /**加载完成 */ protected LoadingCompleted() { this.loadResComplete = true; } protected switchScene(){ this.CanSwitchloding = false; LevelManager.LodeLevle(this.m_param.scene_name, () => { this.pre_loadingUIForms(); game.frameRate = this.m_param.Frame; }); } protected pre_loadingUIForms(){ let tCount = this.m_param.default_open_ui.length; if(!tCount){ this.loadingUIForms(); return; } this.loadingUIForms(); } protected loadingUIForms(){ let tCount = this.m_param.default_open_ui.length; if(!tCount){ this.CloseLoadingUI(); return; } for (let i = 0; i < this.m_param.default_open_ui.length; i++) { const tData = this.m_param.default_open_ui[i]; UIMgr.Ins.ShowUIForms(tData.uiUrl, null, tData.bundle as EBundleName, () => { tCount--; if (tCount <= 0) { this.m_param.back_funtion && this.m_param.back_funtion(); // if (MainConfig.LodingSceneComple) { // this.statCheckClose(); // } else { // this.scheduleOnce(this.statCheckClose, 0.1); // } } }); } } statCheckClose(){ if(MainConfig.LodingSceneComple){ this.unschedule(this.statCheckClose) this.scheduleOnce(()=>{ this.CloseLoadingUI(); },0.3) } } protected CloseLoadingUI(): void { MesMgr.off(EGlobalEvent.MAINUI_READY, this.statCheckClose, this); UIMgr.Ins.CloseUIForms(this.m_param.loadingUI, this.m_param.bundle); ConsoleEx.Warn("!!!!!!!!!!LodingUI_Proxy关闭"); // 上报游戏可交互 if(!MainConfig.isEnterGame){ MainConfig.isEnterGame = true; PlatformManager.PlatformInstance.reportScene(7001); // const feed_game_scene = PlatformManager.PlatformInstance.GetFeedType(); // if(!MINIGAME && feed_game_scene === 0 && !MainConfig.isFeedEnter){ // this.scheduleOnce(()=>{ // MainConfig.isFeedEnter = MainConfig.isEnterGame; // // 如果是获客方式正式进入,则发送一条时间,显示被隐藏的功能入口 // ConsoleEx.Warn("!!!!!!!!!!发送EGlobalEvent.E_FEED_ENTER_GAME"); // MainConfig.isFeedEnter && MesMgr.event(EGlobalEvent.E_FEED_ENTER_GAME); // },5); // } } } protected update(dt: number): void { this.CurTime += dt; if (this.CurTime >= this.minNeedTime && this.CanSwitchloding && this.getloadingComplete()) { this.switchScene(); } } }