123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- import GameConstant from 'GameConstant'
- let UIHelper = require("UIHelper");
- let Global = require("Global");
- let BaseDefine = require("BaseDefine");
- let GameUpdate = require("GameUpdate");
- let BundleLoaderManager = require("BundleLoaderManager");
- let _ScenceManagerInstance = null;
- import GameManagerBase from 'GameManagerBase'
- //退出游戏,需要保留的内存资源
- let filter_assets = [
- //捕鱼
- ]
- let homeSceneLoadDir = [
- ];
- let filter_home_assets = [
- ];
- class HNScenceManager {
- constructor() {
- this._rootComponent = null;
- this._currGameNode = null;
- this._currGameComponent = null;
- this.recvMemoryRes = [];
- }
- CreateGame() {
- let gameComponent = null;
- if (!this._currGameNode) {
- return null;
- }
- let nameComponent = "GameBase";
- if (nameComponent.length > 0) {
- gameComponent = this._currGameNode.getComponent(nameComponent);
- }
- this._currGameComponent = gameComponent;
- if (gameComponent) {
- this.inGameScence();
- }
- return gameComponent;
- }
- setRootComponent(rootComponent) {
- this._rootComponent = rootComponent;
- }
- getRootComponent() {
- return this._rootComponent;
- }
- setGameComponent(gameComponent) { //BYSCENE
- this._currGameComponent = gameComponent;
- }
- getGameComponent() {
- return this._currGameComponent;
- }
- inGameScence() {
- let rootComponent = this.getRootComponent();
- if (rootComponent) {
- rootComponent.inGameScence();
- }
- }
- releaseHomeAssets() { //BYSCENE
- // if (BaseDefine.GAME_PLATFORM != BaseDefine.WEB_H5_PLATFORM) {
- // if (homeSceneLoadDir.length > 0) {
- // for (let i = 0; i < homeSceneLoadDir.length; ++i) {
- // cc.assetManager.releaseAsset(homeSceneLoadDir[i]);
- // }
- // }
- // Global.print("---releaseHomeAssets");
- // //cc.assetManager.releaseAll();
- // //cc.sys.garbageCollect();
- // }
- }
- releaseAssets(arrRes) {
- if (BaseDefine.GAME_PLATFORM != BaseDefine.WEB_H5_PLATFORM) {
- //内存回收(目前只针对捕鱼游戏)
- if (arrRes.length > 0) {
- for (let i = 0; i < arrRes.length; ++i) {
- let deps = cc.assetManager.getDependsRecursively(arrRes[i]);
- //排除共享资源
- for (let j = 0; j < filter_assets.length; ++j) {
- let index = deps.indexOf(filter_assets[j]);
- if (index !== -1)
- deps.splice(index, 1);
- }
- cc.assetManager.releaseAsset(deps);
- cc.assetManager.releaseAsset(arrRes[i]);
- }
- }
- Global.print("---releaseAssets");
- //cc.assetManager.releaseAll();
- //cc.sys.garbageCollect();
- }
- }
- getPrefabsByKind(wKindID) {
- let arrRes = [];
- let bundleData = this.getMainPrefabsByKind(wKindID);
- if (bundleData != '') {
- arrRes.push(bundleData);
- }
- return arrRes;
- }
- getMainPrefabsByKind(wKindID) {
- let bundleData = {
- [GameConstant.KIND_ID_BRAB]: {
- bundle: "BRAB",
- importBundle: [],
- gamePrefabPath: ["filter-BRAB/BRABGameScence", "GamePrefabs/Base/TP"]
- }, [GameConstant.KIND_ID_BRTP]: {
- bundle: "BRTP",
- importBundle: [],
- gamePrefabPath: ["filter-BRTP/BRTPGameSence"]
- }
- };
- return bundleData[wKindID];
- }
- releaseBYAssets() {
- // BYSCENE
- // if (cc.sys.os == cc.sys.OS_ANDROID || cc.sys.os == cc.sys.OS_IOS) {
- //内存回收(目前只针对捕鱼游戏)
- /*for(let i = 0; i < filter_assets.length;i++)
- {
- cc.loader.setAutoRelease(filter_assets[i],false);
- }
- if (this.recvMemoryRes.length > 0) {
- for (let i = 0 ; i < this.recvMemoryRes.length; ++i) {
- let deps = cc.loader.getDependsRecursively(this.recvMemoryRes[i]);
- cc.loader.release(deps);
- cc.loader.release(this.recvMemoryRes[i]);
- }
- }*/
- //jsb
- //Global.print("cc.textureCache.dumpCachedTextureInfo():: " + cc.textureCache.dumpCachedTextureInfo());
- //cc.loader.releaseResDir("GameTextures");
- //cc.loader.releaseAll();
- // cc.sys.garbageCollect();
- // //恢复渲染画质
- // //cc.Texture2D.setDefaultAlphaPixelFormat(0);
- // }
- }
- recvMemory() {
- // 内存回收
- // this.recvMemoryRes = [];
- // let arrRes = this.getPrefabsByKind(wKindID);
- // if (BaseDefine.GAME_PLATFORM != BaseDefine.WEB_H5_PLATFORM) {
- // cc.assetManager.releaseAll();
- // }
- }
- loadGameBaseData(wKindID, callBack) {
- this.callBack = callBack;
- window.testFunction = (bundle, url) => {
- this.loadBundlePrefab(bundle, url)
- }
- this.recvMemory();
- BundleLoaderManager.Instance().loadBundleGame(wKindID, callBack, this._currGameNode);
- }
- loadBundlePrefab(bundle, url) {
- for (let i = 0; i < url.length; i += 1) {
- url[i] = "resourcesPrefab/" + url[i];
- }
- UIHelper.showWaitNode("connectServer")
- UIHelper.nodeMAP = new Map();
- bundle.load(url, cc.Prefab, () => {
- // this.loadBundleProgress();
- }, (err, prefab) => {
- Global.print("创建游戏节点 strPrefabs = " + prefab);
- UIHelper.hideWaitNode();
- UIHelper.hideAMask();
- let gameNode = null;
- if (Array.isArray(prefab)) {
- gameNode = cc.instantiate(prefab[0]);
- let gameNode2 = cc.instantiate(prefab[1]);
- gameNode2.zIndex = -1;
- gameNode2.parent = gameNode;
- } else {
- gameNode = cc.instantiate(prefab);
- }
- let runScene = cc.director.getScene().getChildByName("GameScence");
- runScene.addChild(gameNode);
- gameNode.setPosition(cc.v2(cc.winSize / 2, cc.winSize.height / 2));
- if (this._currGameNode != undefined && this._currGameNode != null) {
- this._currGameNode.removeFromParent(true);
- this._currGameNode = null;
- }
- if (cc.vv && cc.vv.audioMgr) {
- cc.vv.audioMgr.stopBackMusic();
- }
- this._currGameNode = gameNode;
- if (this.callBack) {
- this.callBack(gameNode);
- }
- cc.vv.Revenue = cc.vv.globalUserInfo.getRevenue()//记录进游戏时候福卡数量
- // if (!cc.vv.config.ReviewApk) {
- // cc.vv.GetHallScript().onBtnSelectRoomOut();
- // }
- if (window.LoadGameTime) {
- let intervalTime = (Date.now() - window.LoadGameTime) / 1000; // 单位 s(秒)
- if (intervalTime <= 3) {
- cc.userOperate.sendRecord("enter-Game Time0-3s");
- } else if (intervalTime <= 5) {
- cc.userOperate.sendRecord("enter-Game Time3-5s");
- } else if (intervalTime <= 10) {
- cc.userOperate.sendRecord("enter-Game Time5-10s");
- } else if (intervalTime <= 15) {
- cc.userOperate.sendRecord("enter-Game Time10-15s");
- } else {
- cc.userOperate.sendRecord("enter-Game Time15s+");
- }
- window.LoadGameTime = null;
- }
- })
- }
- gameBackScence() {
- cc.vv.audioMgr.stopBackMusic();
- cc.vv.audioMgr.stopAllEffects();
- if (this._currGameNode != undefined && this._currGameNode != null) {
- this._currGameNode.removeFromParent(true);
- this._currGameNode = null;
- let runScene = cc.director.getScene();
- runScene.getChildByName("Canvas").active = true;
- }
- this._currGameComponent = null;
- let rootComponent = this.getRootComponent();
- if (rootComponent) {
- rootComponent.gameBackScence();
- }
- }
- };
- HNScenceManager.Instance = function () {
- if (!_ScenceManagerInstance) {
- _ScenceManagerInstance = new HNScenceManager();
- }
- return _ScenceManagerInstance;
- }
- module.exports = HNScenceManager;
|