Main.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { Component, game, UIRenderer, _decorator, Game, SpriteFrame, ProgressBar } from 'cc';
  2. import { ViewID } from '../framework/config/LayerConf';
  3. import { Framework } from '../framework/Framework';
  4. import { GameEvent } from './data/GameEvent';
  5. import { MaterialUtil } from '../framework/util/MaterialUtil';
  6. import { NetManager } from './common/NetManager';
  7. import { FrameworkConf } from '../framework/config/FrameworkConf';
  8. import { resLoader } from '../framework/res/ResLoader';
  9. import { UnionManager } from './manager/UnionManager';
  10. const { ccclass, property } = _decorator;
  11. // export let NetMgr: NetManager = null;
  12. //临时解决透明度为0还会渲染的bug
  13. // UIRenderer.prototype.updateAssembler = function updateAssembler(render: any) {
  14. // if (this._renderDataFlag) {
  15. // this._assembler!.updateRenderData(this, render);
  16. // this._renderDataFlag = false;
  17. // }
  18. // if (render._pOpacity > 0 && this._renderFlag) {
  19. // // console.log(render);
  20. // this._render(render);
  21. // }
  22. // }
  23. game.frameRate = 59;
  24. // 获取URL参数的函数
  25. function getParameterByName(name) {
  26. let url = window.location.href;
  27. name = name.replace(/[\[\]]/g, "\\$&");
  28. const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
  29. const results = regex.exec(url);
  30. if (!results) return null;
  31. if (!results[2]) return '';
  32. return decodeURIComponent(results[2].replace(/\+/g, ' '));
  33. // return results[2].replace(/\+/g, ' ')
  34. }
  35. @ccclass('Main')
  36. export class Main extends Component {
  37. private _uid = "";
  38. //切换后台的起始时间 单位ms
  39. hideTime = 0;
  40. //重连的时间 超过2秒就重连 单位ms
  41. reconnectTime = 2000;
  42. onLoad() {
  43. Framework.event.addEvent(FrameworkConf.Event.GAME_SHOW, this.gameEvent_onShow, this);
  44. Framework.event.addEvent(FrameworkConf.Event.GAME_HIDE, this.gameEvent_onHide, this);
  45. let loginbg = this.node.getChildByPath('loginbg');
  46. Framework.unionManager = UnionManager;
  47. let loadRes = [
  48. 'bomb/game/icon_1'
  49. ];
  50. let loadNum = 0;
  51. let maxLoadNum = loadRes.length; // + MaterialUtil.init资源数量
  52. let finishBack = () => {
  53. loadNum++;
  54. if (loadNum >= maxLoadNum) {
  55. }
  56. };
  57. MaterialUtil.init(finishBack);
  58. for (let index = 0; index < loadRes.length; index++) {
  59. const element = loadRes[index];
  60. let path = `texture/${element}/spriteFrame`
  61. resLoader.load('package', path, SpriteFrame, (error: Error, res: SpriteFrame) => {
  62. if (!error) {
  63. finishBack();
  64. }
  65. });
  66. }
  67. // Framework.layer.open(ViewID.TowerUI, null,{});
  68. // Framework.layer.open(ViewID.ZombieUI, null,{});
  69. Framework.layer.open(ViewID.LoginUI, null, () => {
  70. // this.node.getChildByPath('UICamera/loginbg').destroy()
  71. });
  72. // this.connect()
  73. }
  74. gameEvent_onShow() {
  75. // let time = Date.now() - this.hideTime
  76. // if(time > this.reconnectTime){
  77. // this.connect()
  78. // }
  79. }
  80. gameEvent_onHide() {
  81. // this.hideTime = Date.now()
  82. }
  83. }