home_bottom_countdown.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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(active_cb) {
  10. this.seconds = userDataManager.getUserFreeAdsTime()
  11. if(this.seconds==-1) {
  12. this.unscheduleAllCallbacks()
  13. this.node.active = false
  14. if(active_cb){ active_cb(false) }
  15. return
  16. }
  17. this.node.active = true
  18. if(active_cb){ active_cb(true) }
  19. this.lab_countdown_time.getComponent(Label).string = Util.formatTimeForSecond(this.seconds)
  20. this.unscheduleAllCallbacks()
  21. this.schedule(()=>{
  22. this.seconds --
  23. if(this.seconds<=0) {
  24. userDataManager.is_free_ads = false
  25. userDataManager.saveUserFreeAdsLookVideoCount(0)
  26. this.unscheduleAllCallbacks()
  27. this.node.active = false
  28. if(active_cb){ active_cb(false) }
  29. return
  30. }
  31. this.lab_countdown_time.getComponent(Label).string = Util.formatTimeForSecond(this.seconds)
  32. },1)
  33. }
  34. }