TryGamesWidget.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import TryGameNode from "./TryGameNode";
  2. import { utils } from "./Utils";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class TryGamesWidget extends cc.Component {
  6. _tryGameNode: TryGameNode = null;
  7. _isInit: boolean = false;
  8. onLoad() {
  9. this._tryGameNode = this.getComponentInChildren("TryGameNode");
  10. this._tryGameNode.node.active = false;
  11. }
  12. onEnable() {
  13. utils.registerServerInitEvent(() => {
  14. this._initWidget();
  15. }, this);
  16. }
  17. onDisable() {
  18. utils.unregisterServerInitEvent(this);
  19. }
  20. _initWidget() {
  21. if (this._isInit) return;
  22. let dataValid: boolean = true;
  23. let data: any = utils.getInnerRecommendData();
  24. if (data) {
  25. if (data.jump_list) {
  26. if (data.jump_list.length <= 0) {
  27. cc.warn("字段jump_list的长度不合法!");
  28. dataValid = false;
  29. }
  30. } else {
  31. cc.warn("字段jump_list不存在!");
  32. dataValid = false;
  33. }
  34. } else {
  35. cc.warn("交叉推广数据为null");
  36. dataValid = false;
  37. }
  38. if (dataValid) {
  39. this._isInit = true;
  40. utils.showLog("交叉推广数据:", JSON.stringify(data));
  41. this._tryGameNode.init({ "jump_refresh_time": data.jump_refresh_time, "jump_list": data.jump_list });
  42. this._tryGameNode.node.active = true;
  43. } else {
  44. this.node.destroy();
  45. }
  46. }
  47. }