GameController.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import Config from "./Config";
  2. import Gamecfg from "./common/gameCfg";
  3. import GameDataCenter from "./data/GameDataCenter";
  4. import { eg } from "./frameWork/eg";
  5. import FguiMgr from "./frameWork/fgui/FguiMgr";
  6. import HttpRequest from "./network/HttpRequest";
  7. import Network from "./network/Network";
  8. import AssetsBundleMgr from "./utils/AssetsBundleMgr";
  9. import Load from "./utils/Load";
  10. import NativeManager from "./utils/NativeManager";
  11. import { SingletonFactory } from "./utils/SingletonFactory";
  12. import ThinkingDataMgr from "./utils/ThinkingDataMgr";
  13. class GameController {
  14. network: Network = null;
  15. rewardedVideoAd: any = null;
  16. // websocket: NetworkWebSocket = null;
  17. constructor() {
  18. CC_PREVIEW && (window['gamecontroller'] = this)
  19. }
  20. init(callback: Function) {
  21. // 新建一个网络单例
  22. this.network = SingletonFactory.getInstance(Network);
  23. // this.websocket = SingletonFactory.getInstance(NetworkWebSocket);
  24. // 所有UI扩展都写在这
  25. this.initUIExpand()
  26. NativeManager.Init()
  27. console.log("初始化配置表")
  28. let startTime = new Date().getTime()
  29. Gamecfg.initLoading((isSucc: boolean) => {
  30. console.log("初始化配置表流程结束,消耗时长:" + (new Date().getTime() - startTime) + "ms")
  31. if (isSucc) {
  32. console.log("解析成功")
  33. // 初始化数据模块
  34. GameDataCenter.initLoadModule();
  35. // GameDataCenter.adVideo.setAdOpen()
  36. // //初始化数数
  37. ThinkingDataMgr.TDInit();
  38. } else {
  39. console.log("解析失败")
  40. }
  41. callback(isSucc)
  42. })
  43. }
  44. clear() {
  45. this.network.RemoveTimers();
  46. // if (GameDataCenter.plat.instance.rewardedVideoAd) {
  47. // // 销毁激励视频广告实例
  48. // console.log("销毁广告实例,避免重复触发回调")
  49. // GameDataCenter.plat.instance.rewardedVideoAd.destroy();
  50. // }
  51. cc.Tween.stopAll()
  52. //清空已经所有的界面
  53. FguiMgr.Instance.clearAllUI()
  54. fgui.TweenManager.clearAll();
  55. Load.clear()
  56. if (Config.upid != null) {
  57. clearInterval(Config.upid)
  58. }
  59. if (Config.upFrame != null) {
  60. clearInterval(Config.upFrame)
  61. }
  62. if (Config.upFight != null) {
  63. clearInterval(Config.upFight)
  64. }
  65. cc.director.getScene().removeAllChildren(true)
  66. Config.inGame = 0
  67. this.network.stopRequest = false
  68. HttpRequest.errPostMap.Clear()
  69. GameDataCenter._rspModel.clear();
  70. eg.poolManager?.ReleaseAllPool();
  71. fgui.UIPackage.removeAllPackage()
  72. AssetsBundleMgr.releaseAllBundle();
  73. }
  74. private initUIExpand() {
  75. // tween的暂停与恢复
  76. // cc.ActionInterval.prototype.step = function (dt) {
  77. // if (this.paused) {
  78. // return;
  79. // }
  80. // if (this._firstTick && !this._goto) {
  81. // this._firstTick = false;
  82. // this._elapsed = 0;
  83. // } else {
  84. // this._elapsed += dt;
  85. // }
  86. // let t = this._elapsed / (this._duration > 0.0000001192092896 ? this._duration : 0.0000001192092896);
  87. // t = (1 > t ? t : 1);
  88. // this.update(t > 0 ? t : 0);
  89. // //Compatible with repeat class, Discard after can be deleted (this._repeatMethod)
  90. // if (this._repeatMethod && this._timesForRepeat > 1 && this.isDone()) {
  91. // if (!this._repeatForever) {
  92. // this._timesForRepeat--;
  93. // }
  94. // this.startWithTarget(this.target);
  95. // this.step(this._elapsed - this._duration);
  96. // }
  97. // };
  98. // cc.Tween.prototype.pause = function () {
  99. // this._finalAction.paused = true;
  100. // };
  101. // cc.Tween.prototype.resume = function () {
  102. // this._finalAction.paused = false;
  103. // };
  104. }
  105. }
  106. export default new GameController();