home_bottom_countdown.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import { _decorator, Component, Label, Node } from 'cc';
  2. import { userDataManager } from '../../manager/userDataManager';
  3. import { Util } from '../../util';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('home_bottom_countdown')
  6. export class home_bottom_countdown extends Component {
  7. @property(Node) lab_countdown_time:Node = null
  8. private seconds:number = 0
  9. startTime() {
  10. this.seconds = userDataManager.getUserFreeAdsTime()
  11. if(this.seconds==-1) {
  12. this.unscheduleAllCallbacks()
  13. this.node.active = false
  14. return
  15. }
  16. this.node.active = true
  17. this.lab_countdown_time.getComponent(Label).string = Util.formatTimeForSecond(this.seconds)
  18. this.unscheduleAllCallbacks()
  19. this.schedule(()=>{
  20. this.seconds --
  21. if(this.seconds<=0) {
  22. userDataManager.is_free_ads = false
  23. this.unscheduleAllCallbacks()
  24. this.node.active = false
  25. return
  26. }
  27. this.lab_countdown_time.getComponent(Label).string = Util.formatTimeForSecond(this.seconds)
  28. },1)
  29. }
  30. }