UINetMask.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // 网络遮罩层
  2. import { NetworkEvent } from "../../../data/const/EventConst";
  3. import { ViewZOrder } from "../../../data/const/ViewZOrder";
  4. import EventMng from "../../../manager/EventMng";
  5. import { uiCommon } from "../../../utils/UICommon";
  6. const { ccclass, menu, property } = cc._decorator;
  7. @ccclass
  8. @menu("UI/persistNode/NetMask")
  9. export default class NetMask extends cc.Component {
  10. @property(cc.Node)
  11. imgBg: cc.Node = null
  12. private _waitCount: number = 0
  13. private life: number = 0
  14. protected onEnable() {
  15. cc.game.addPersistRootNode(this.node)
  16. this.node.zIndex = ViewZOrder.MASK
  17. this.imgBg.setContentSize(cc.winSize)
  18. this.node.x = cc.winSize.width / 2
  19. this.node.y = cc.winSize.height / 2
  20. this.setUITween()
  21. EventMng.on(NetworkEvent.WAIT, this.addWaitCount, this)
  22. EventMng.on(NetworkEvent.WAIT_CLOSE, this.delWait, this)
  23. uiCommon.onRegisterEvent(this.imgBg, this.onClick, this)
  24. this.imgBg.active = false
  25. }
  26. protected onDisable() {
  27. EventMng.off(NetworkEvent.WAIT, this.addWaitCount, this)
  28. EventMng.off(NetworkEvent.WAIT_CLOSE, this.delWait, this)
  29. uiCommon.unRegisterEvent(this.imgBg)
  30. }
  31. setUITween() {
  32. // this.animNode.scale = 0
  33. // this.animNode.angle = 360
  34. // this.tipsMask.width = 0
  35. // let dotAnim = cc.tween().to(0.3, { y: 22 }).to(0.6, { y: 10 }).to(0.3, { y: 16 })
  36. // cc.tween(this.animNode).to(0.5, { scale: 1, angle: 0 }).call(() => {
  37. // cc.tween(this.gAnim).by(4, { angle: -360 }).repeatForever().start()
  38. // cc.tween(this.tipsMask).to(0.3, { width: 180 }).call(() => {
  39. // let index: number = 0
  40. // let cd = () => {
  41. // index++
  42. // cc.tween(this[`dot${index}`]).then(dotAnim.clone(this[`dot${index}`])).repeatForever().start()
  43. // if (index == 3) {
  44. // this.unschedule(cd)
  45. // }
  46. // }
  47. // this.schedule(cd, 0.15)
  48. // }).start()
  49. // }).start()
  50. }
  51. addWaitCount(val: number = 1) {
  52. this.waitCount += val
  53. }
  54. delWait() {
  55. this.waitCount = 0
  56. this.life = 0
  57. this.imgBg.active = false
  58. }
  59. set waitCount(val: number) {
  60. this._waitCount = val
  61. if (this._waitCount <= 0) {
  62. this._waitCount = 0
  63. }
  64. // this.imgBg.active = this._waitCount != 0
  65. }
  66. get waitCount() {
  67. return this._waitCount
  68. }
  69. update(dt: number) {
  70. if (this.waitCount > 0) {
  71. this.life++
  72. if (this.imgBg.active == false) {
  73. this.imgBg.active = this.life > 120
  74. }
  75. //遮罩展示2s后自动关闭,避免卡死
  76. if (this.imgBg.active == true && this.life > 240) {
  77. this.waitCount--
  78. }
  79. } else {
  80. this.life = 0
  81. this.imgBg.active = false
  82. }
  83. }
  84. onClick() {
  85. console.warn("net遮罩层被点击")
  86. }
  87. }