EffectRedAlert.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { _decorator, Component, isValid, Node, tween, UIOpacity } from 'cc';
  2. import { EventMgr } from '../manager/EventMgr';
  3. import { EventType } from '../enum/EventType';
  4. import { Global } from '../Global';
  5. import { AudioMgr } from '../manager/AudioMgr';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('Game/EffectRedAlert')
  8. export class EffectRedAlert extends Component {
  9. private uiOpacity: UIOpacity = null
  10. protected onLoad() {
  11. this.uiOpacity = this.getComponent(UIOpacity)
  12. EventMgr.on(EventType.TimeOutAlert, this.onTimeOutAlert, this)
  13. }
  14. protected onDestroy(): void {
  15. EventMgr.off(EventType.TimeOutAlert, this.onTimeOutAlert, this)
  16. }
  17. protected start(): void {
  18. const tw = tween(this.uiOpacity)
  19. tw.sequence(
  20. tween(this.uiOpacity).to(0.5, { opacity: 0 }),
  21. tween(this.uiOpacity).to(0.5, { opacity: 255 }),
  22. )
  23. tw.repeatForever()
  24. tw.start()
  25. this.scheduleOnce(this.onTimeOutAlert, Global.Time_Out_Alert_Time)
  26. AudioMgr.playSfx('倒计时')
  27. }
  28. protected onTimeOutAlert(): void {
  29. this.unscheduleAllCallbacks()
  30. if (isValid(this.node)) this.node.destroy()
  31. }
  32. }