LoadingUI.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { _decorator, Component, Label, ProgressBar } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('LoadingUI')
  4. // export class LoadingUI extends UIBase {
  5. // progressBar: ProgressBar = null;
  6. // progressLabel: Label = null;
  7. // whichRes: Label = null;
  8. // protected onStart(): void {
  9. // this.progressBar = this.getComponentInChildren(ProgressBar);
  10. // this.progressLabel = this.getComponentInChildren(Label);
  11. // this.whichRes = this.getLabel("_which");
  12. // }
  13. // public updateProgress(progress: number){
  14. // if(this.progressBar){
  15. // this.progressBar.progress = progress;
  16. // }
  17. // if(this.progressLabel){
  18. // this.progressLabel.string = `${Math.floor(progress * 100)}%`;
  19. // }
  20. // }
  21. // public updateWhichRes(which: number){
  22. // if(this.whichRes){
  23. // this.whichRes.string = `${which}/2`;
  24. // }
  25. // }
  26. // }
  27. export class LoadingUI extends Component {
  28. progressBar: ProgressBar = null;
  29. progressLabel: Label = null;
  30. whichRes: Label = null;
  31. protected start(): void {
  32. this.progressBar = this.getComponentInChildren(ProgressBar);
  33. this.progressLabel = this.getComponentInChildren(Label);
  34. this.whichRes = this.node.getChildByName("_which").getComponent(Label);
  35. }
  36. public updateProgress(progress: number) {
  37. if (this.progressBar) {
  38. this.progressBar.progress = progress;
  39. }
  40. if (this.progressLabel) {
  41. this.progressLabel.string = `${Math.floor(progress * 100)}%`;
  42. }
  43. }
  44. public updateWhichRes(which: number) {
  45. if (this.whichRes) {
  46. this.whichRes.string = `${which}/3`;
  47. }
  48. }
  49. }