LoadingComp.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using Plugins.CxShine.page;
  3. using Unity.VisualScripting;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace UI.Loading
  7. {
  8. public class LoadingComp : MonoBehaviour
  9. {
  10. public GameObject CenterRotate;
  11. public Text WaitingText;
  12. public string[] strs;
  13. private void Start()
  14. {
  15. strs = new[] { "Waiting", "Waiting.", "Waiting..", "Waiting..." };
  16. initAutoClose(12000000);
  17. }
  18. public float interval = 0.01f;
  19. private int currentIndex;
  20. private float lastSpriteChangeTime;
  21. private float currentTime;
  22. private float closeTime;
  23. private void Update()
  24. {
  25. currentTime = Time.time;
  26. float elapsedTime = Time.time - lastSpriteChangeTime;
  27. if (elapsedTime > interval)
  28. {
  29. currentIndex = (currentIndex + 1) % strs.Length;
  30. lastSpriteChangeTime = currentTime;
  31. }
  32. WaitingText.text = strs[currentIndex];
  33. if (Time.time >= closeTime)
  34. {
  35. gameObject.GetComponent<PageComp>().A__ClosePage();
  36. }
  37. }
  38. private void LateUpdate()
  39. {
  40. }
  41. public void A__ClickClose()
  42. {
  43. closeTime = Time.time;
  44. }
  45. public void initAutoClose(int time)
  46. {
  47. closeTime = Time.time + time;
  48. }
  49. }
  50. }