LoadingText.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import {
  2. _decorator,
  3. Component,
  4. Node,
  5. tween,
  6. Vec3,
  7. UIOpacity,
  8. Color,
  9. Label,
  10. Tween,
  11. Quat,
  12. } from "cc";
  13. import BaseUI from "../base/BaseUI";
  14. const { ccclass, property } = _decorator;
  15. @ccclass("LoadingText")
  16. export class LoadingText extends BaseUI {
  17. @property({ type: Color, tooltip: "主顏色" })
  18. mainColor: Color = new Color(0, 255, 0, 255);
  19. @property({ type: Color, tooltip: "閃爍顏色" })
  20. flashColor: Color = Color.WHITE; // 綠色
  21. protected onLoad(): void {
  22. super.onLoad();
  23. let lbl1 = this.FindNode("1");
  24. let lbl2 = this.FindNode("2");
  25. let lbl3 = this.FindNode("3");
  26. let lbl4 = this.FindNode("4");
  27. let lbl5 = this.FindNode("5");
  28. this.playAnim(lbl1, lbl2, lbl3, lbl4, lbl5);
  29. }
  30. protected start(): void {
  31. // 確保顏色設置正確
  32. let lbl1 = this.FindNode("1");
  33. let lbl2 = this.FindNode("2");
  34. let lbl3 = this.FindNode("3");
  35. let lbl4 = this.FindNode("4");
  36. let lbl5 = this.FindNode("5");
  37. const labels = [lbl1, lbl2, lbl3, lbl4, lbl5];
  38. for (let lbl of labels) {
  39. let labelComp = lbl.getComponent(Label);
  40. if (labelComp) {
  41. labelComp.color = this.mainColor;
  42. }
  43. }
  44. }
  45. playAnim(lbl1: Node, lbl2: Node, lbl3: Node, lbl4: Node, lbl5: Node) {
  46. const labels = [lbl1, lbl2, lbl3, lbl4, lbl5];
  47. // 初始化
  48. for (let lbl of labels) {
  49. lbl.scale = new Vec3(0, 0, 1);
  50. lbl.eulerAngles = new Vec3(0, 0, 0);
  51. let opacity = lbl.getComponent(UIOpacity);
  52. if (!opacity) {
  53. opacity = lbl.addComponent(UIOpacity);
  54. }
  55. opacity.opacity = 0;
  56. // 設置主顏色
  57. let labelComp = lbl.getComponent(Label);
  58. if (labelComp) labelComp.color = this.mainColor;
  59. }
  60. // 依次播放動畫
  61. let delay = 0;
  62. labels.forEach((lbl, idx) => {
  63. tween(lbl)
  64. .delay(delay)
  65. .call(() => {
  66. let opacity = lbl.getComponent(UIOpacity)!;
  67. opacity.opacity = 0;
  68. lbl.scale = new Vec3(0, 0, 1);
  69. lbl.eulerAngles = new Vec3(0, 0, 0);
  70. })
  71. // 旋轉+放大+淡入
  72. .to(
  73. 0.25,
  74. {
  75. scale: new Vec3(1.5, 1.5, 1),
  76. eulerAngles: new Vec3(0, 0, 360),
  77. },
  78. { easing: "backOut" }
  79. )
  80. .call(() => {
  81. let opacity = lbl.getComponent(UIOpacity)!;
  82. opacity.opacity = 255;
  83. })
  84. // 彈跳縮放
  85. .to(0.1, { scale: new Vec3(1, 1, 1) }, { easing: "backIn" })
  86. .to(0.08, { scale: new Vec3(1.2, 0.8, 1) })
  87. .to(0.08, { scale: new Vec3(0.9, 1.1, 1) })
  88. .to(0.08, { scale: new Vec3(1, 1, 1) })
  89. // 顏色閃爍
  90. .call(() => {
  91. let labelComp = lbl.getComponent(Label);
  92. if (labelComp) {
  93. let colorTween = tween(labelComp);
  94. colorTween
  95. .to(0.08, { color: this.flashColor })
  96. .to(0.08, { color: this.mainColor })
  97. .start();
  98. }
  99. })
  100. .start();
  101. delay += 0.18;
  102. });
  103. // 最後集體閃爍+抖動
  104. let finalTween = tween();
  105. finalTween
  106. .delay(delay + 0.5)
  107. .call(() => {
  108. for (let lbl of labels) {
  109. let opacity = lbl.getComponent(UIOpacity)!;
  110. // 閃爍
  111. let opacityTween = tween(opacity);
  112. opacityTween
  113. .to(0.08, { opacity: 100 })
  114. .to(0.08, { opacity: 255 })
  115. .to(0.08, { opacity: 100 })
  116. .to(0.08, { opacity: 255 })
  117. .start();
  118. // 抖動
  119. let shakeTween = tween(lbl);
  120. shakeTween
  121. .to(0.04, { position: lbl.position.add(new Vec3(5, 0, 0)) })
  122. .to(0.04, { position: lbl.position.add(new Vec3(-10, 0, 0)) })
  123. .to(0.04, { position: lbl.position.add(new Vec3(10, 0, 0)) })
  124. .to(0.04, { position: lbl.position })
  125. .start();
  126. }
  127. })
  128. .start();
  129. }
  130. }