RecommendGamesWidget.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { utils } from "./Utils";
  2. import RecommendGamesNode from "./RecommendGamesNode";
  3. import { SubLocation } from "./YZ_Constant";
  4. import PlatUtils from "./PlatUtils";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class RecommendGamesWidget extends cc.Component {
  8. _recommendNode: RecommendGamesNode = null;
  9. _isInit: boolean = false;
  10. onLoad() {
  11. this._recommendNode = this.getComponentInChildren("RecommendGamesNode");
  12. this._recommendNode.node.active = false;
  13. }
  14. onEnable() {
  15. utils.registerServerInitEvent(() => {
  16. this._initWidget();
  17. }, this);
  18. }
  19. onDisable() {
  20. utils.unregisterServerInitEvent(this);
  21. }
  22. _initWidget() {
  23. if (this._isInit) return;
  24. let valid: boolean = true;
  25. if (utils.isShowRecommondGamesList()) {
  26. if (PlatUtils.IsDouyin) {
  27. if (!utils.Tool_Douyin.isShowMoreGamesModal()) {
  28. this.node.destroy();
  29. }
  30. }
  31. let data: any = utils.getRecommondGameList();
  32. if (data) {
  33. if (data.length > 0) {
  34. this._isInit = true;
  35. this._recommendNode.init(data);
  36. this._recommendNode.node.active = true;
  37. } else {
  38. cc.warn("交叉推广数据长度为0");
  39. valid = false;
  40. }
  41. } else {
  42. cc.warn("交叉推广数据为null!");
  43. valid = false;
  44. }
  45. }
  46. if (!valid) {
  47. this.node.destroy();
  48. }
  49. }
  50. }