using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using static DeMaDataManager; public class SheBeibaojingtaizhang : UpdateManager { public float scrollSpeed = 1.0f; // 滚动速度 public float scrollDelay = 3.0f; // 滚动延迟 List bjlist =new List(); public UIScrollScript us; override public void updateData() { base.updateData(); DeMaDataManager.Instance.GetGaoJingTaiZhang((data) => { bjlist=data; us.InitList(0,data.Count); }); } private void OnEnable() { if(cutine!=null) StopCoroutine(cutine); cutine = StartCoroutine(AutoScroll()); } Coroutine cutine; private void Awake() { us.Init(); us.onUpdateItem -= ContentUpdateItem; us.onUpdateItem += ContentUpdateItem; } float ct; IEnumerator AutoScroll() { yield return new WaitForSeconds(3f); while (true) { Vector2 v2 =us.GetComponent().anchoredPosition; if(ct>=(bjlist.Count-4)*46) { ct=0; } us.GetComponent().anchoredPosition=new Vector2(v2.x,ct); ct+=0.25f; yield return null; } } private void ContentUpdateItem(GameObject item, int wrapIndex, int realIndex) { if (realIndex >= 0&&bjlist.Count>realIndex) { GaoJingItem xitem = item.GetComponent(); xitem.init(bjlist[realIndex]); item.SetActive(true); } else { item.SetActive(false); } } }