UIToast.ts 676 B

1234567891011121314151617181920212223242526272829303132
  1. import { Widget, _decorator, Node, Label } from 'cc';
  2. import { UIBase } from '../scriptBase/UIBase';
  3. const { ccclass, property, requireComponent } = _decorator;
  4. @ccclass('UI/UIToast')
  5. @requireComponent(Widget)
  6. export class UIToast extends UIBase {
  7. private lbToast: Label = null
  8. protected onLoad(): void {
  9. this.lbToast = this.getComponentInChildren(Label)
  10. }
  11. protected onDestroy(): void {
  12. this.unscheduleAllCallbacks()
  13. }
  14. public onOpen(data?: any): void {
  15. this.lbToast.string = `${data}`
  16. this.scheduleOnce(() => {
  17. this.node.destroy()
  18. }, 2)
  19. }
  20. public onClose(data?: any): void {
  21. }
  22. }