GameController.ts 3.6 KB

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