BYSceneManager.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. let GameConstant = require('GameConstant');
  2. let _BYManagerInstance = null;
  3. class BYSceneManager {
  4. loadGameBaseData(wKindID, bundle) {
  5. //捕鱼单独处理
  6. this._bundle = bundle;
  7. this._percent = 0;
  8. if (cc.director.getScene().name == "byScene") { //BYSCENE
  9. Global.print("捕鱼正在游戏中,不需要重新创建游戏内核~~~~~~~~~~~~~~");
  10. cc.vv.inBYGame = true;
  11. cc.director.getScene().getChildByName("Canvas").getChildByName("BYGameScene").getComponent("BYGameScene").initGame();
  12. return;
  13. }
  14. let arrRes = [];
  15. let bByGame = false;
  16. let bBYGame = false;
  17. if (GameConstant.KIND_ID_BY == wKindID) {
  18. arrRes = [
  19. { res: "resourcesPrefab/Public" },
  20. { res: "resourcesPrefab/Net", funCall: require("BYNetManager") },
  21. { res: "resourcesPrefab/Bullet", funCall: require("BYBulletManager") },
  22. { res: "resourcesPrefab/Battery", funCall: require("BYBatteryManager") },
  23. { res: "resourcesPrefab/ByBg", funCall: require("BYBgManager") },
  24. { res: "resourcesPrefab/Fish", funCall: require("BYFishManager") },
  25. { res: "resourcesPrefab/Action", funCall: require("BYActionManager") },
  26. ]
  27. bBYGame = true;
  28. bByGame = true;
  29. } else if (GameConstant.KIND_ID_BRBYZB == wKindID) {
  30. //捕鱼争霸
  31. arrRes = [
  32. { res: "GamePrefabs/filter-brzb/Public" },
  33. { res: "GamePrefabs/filter-brzb/Net", funCall: require("BYZBNetManager") },
  34. { res: "GamePrefabs/filter-brzb/Bullet", funCall: require("BYZBBulletManager") },
  35. { res: "GamePrefabs/filter-brzb/Battery", funCall: require("BYZBBatteryManager") },
  36. { res: "GamePrefabs/filter-brzb/Role", funCall: require("BYZBRoleManager") },
  37. { res: "GamePrefabs/filter-brzb/Action", funCall: require("BYZBActionManager") },
  38. ]
  39. bBYGame = true;
  40. }
  41. if (bBYGame) {
  42. cc.vv.gameLoadStart = true;
  43. cc.find("GoFishNode").getComponent("GoFishLoading").showGoFishScene();
  44. if (bByGame) {
  45. bundle.preloadScene("byScene");
  46. this.loadCount = 0;
  47. this._percent = 0;
  48. for (let i = 1; i < arrRes.length; i++) {
  49. this.loadBYResDir(arrRes[i].res, arrRes[i].funCall, arrRes.length - 1, "byScene", i);
  50. }
  51. } else {
  52. bundle.preloadScene("byChampions");
  53. for (let i = 1; i < arrRes.length; i++) {
  54. this.loadBYResDir(arrRes[i].res, arrRes[i].funCall, i == arrRes.length - 1, "byChampions", i);
  55. }
  56. }
  57. return;
  58. }
  59. }
  60. loadBYResDir(strPath, funCall, isFinish, scene, idx) {
  61. this._bundle.loadDir(strPath, (completedCount, totalCount, item) => {
  62. if (totalCount > 0) {
  63. let percent = completedCount / totalCount * 0.1 + idx / isFinish;
  64. this._percent = percent < this._percent ? this._percent : percent;//防止加载进度条倒退
  65. cc.find("GoFishNode").getComponent("GoFishLoading").updateProgress(this._percent);
  66. }
  67. }, (err, assets) => {
  68. if (funCall && funCall.init) {
  69. this.loadCount++;
  70. assets.sort((a, b) => {
  71. let nameA = a.name;
  72. let nameB = b.name;
  73. if (nameA < nameB) {
  74. return -1;
  75. }
  76. if (nameA > nameB) {
  77. return 1;
  78. }
  79. return 0;
  80. });
  81. funCall.init(assets);
  82. if (this.loadCount >= isFinish) {
  83. cc.director.loadScene(scene);
  84. }
  85. }
  86. });
  87. }
  88. };
  89. BYSceneManager.Instance = function () {
  90. if (!_BYManagerInstance) {
  91. _BYManagerInstance = new BYSceneManager();
  92. }
  93. return _BYManagerInstance;
  94. }
  95. module.exports = BYSceneManager;