ShareOrVideo.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import { cocosz } from "../Framework/CocosZ";
  8. import Constant from "../Framework/Constant";
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class ShareOrVideo extends cc.Component {
  12. _btn: boolean = false;
  13. @property()
  14. get btn(): boolean {
  15. return this._btn;
  16. }
  17. set btn(v: boolean) {
  18. this._btn = false;
  19. if (this.node.getChildByName("share")) {
  20. this.shareNode = this.node.getChildByName("share");
  21. }
  22. if (this.node.getChildByName("video")) {
  23. this.videoNode = this.node.getChildByName("video");
  24. }
  25. }
  26. @property({ type: cc.Boolean, tooltip: "是否新手指引免费使用" })
  27. isGuideSKill: boolean = false;
  28. @property({ type: cc.Node, tooltip: "分享图标" })
  29. shareNode: cc.Node = null;
  30. @property({ type: cc.Node, tooltip: "视频图标" })
  31. videoNode: cc.Node = null;
  32. protected onLoad(): void {
  33. // 监听点击
  34. this.node.on(cc.Node.EventType.TOUCH_END, () => {
  35. cc.game.emit(Constant.E_ShareOrVideo);
  36. })
  37. // 监听事件
  38. cc.game.on(Constant.E_ShareOrVideo, this.show, this);
  39. }
  40. protected onDestroy(): void {
  41. // 注销事件
  42. cc.game.targetOff(this);
  43. }
  44. protected start(): void {
  45. this.show();
  46. }
  47. show() {
  48. if (this.isGuideSKill && cocosz.dataMgr.guide_skill) {
  49. // 隐藏分享图标
  50. if (this.shareNode && this.shareNode.isValid) {
  51. this.shareNode.active = false;
  52. }
  53. // 隐藏视频图标
  54. if (this.videoNode && this.videoNode.isValid) {
  55. this.videoNode.active = false;
  56. }
  57. } else {
  58. // 显示分享图标
  59. if (this.shareNode && this.shareNode.isValid) {
  60. this.shareNode.active = cocosz.canShare;
  61. }
  62. // 显示视频图标
  63. if (this.videoNode && this.videoNode.isValid) {
  64. this.videoNode.active = !cocosz.canShare;
  65. }
  66. }
  67. }
  68. }