SheBeibaojingtaizhang.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using static DeMaDataManager;
  6. public class SheBeibaojingtaizhang : UpdateManager
  7. {
  8. public float scrollSpeed = 1.0f; // 滚动速度
  9. public float scrollDelay = 3.0f; // 滚动延迟
  10. List<baojing> bjlist =new List<baojing>();
  11. public UIScrollScript us;
  12. override public void updateData()
  13. {
  14. base.updateData();
  15. DeMaDataManager.Instance.GetGaoJingTaiZhang((data) => {
  16. bjlist=data;
  17. us.InitList(0,data.Count);
  18. });
  19. }
  20. private void OnEnable() {
  21. if(cutine!=null)
  22. StopCoroutine(cutine);
  23. cutine = StartCoroutine(AutoScroll());
  24. }
  25. Coroutine cutine;
  26. private void Awake() {
  27. us.Init();
  28. us.onUpdateItem -= ContentUpdateItem;
  29. us.onUpdateItem += ContentUpdateItem;
  30. }
  31. float ct;
  32. IEnumerator AutoScroll()
  33. {
  34. yield return new WaitForSeconds(3f);
  35. while (true)
  36. {
  37. Vector2 v2 =us.GetComponent<RectTransform>().anchoredPosition;
  38. if(ct>=(bjlist.Count-4)*46)
  39. {
  40. ct=0;
  41. }
  42. us.GetComponent<RectTransform>().anchoredPosition=new Vector2(v2.x,ct);
  43. ct+=0.25f;
  44. yield return null;
  45. }
  46. }
  47. private void ContentUpdateItem(GameObject item, int wrapIndex, int realIndex)
  48. {
  49. if (realIndex >= 0&&bjlist.Count>realIndex)
  50. {
  51. GaoJingItem xitem = item.GetComponent<GaoJingItem>();
  52. xitem.init(bjlist[realIndex]);
  53. item.SetActive(true);
  54. }
  55. else
  56. {
  57. item.SetActive(false);
  58. }
  59. }
  60. }