123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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<baojing> bjlist =new List<baojing>();
- 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<RectTransform>().anchoredPosition;
- if(ct>=(bjlist.Count-4)*46)
- {
- ct=0;
- }
- us.GetComponent<RectTransform>().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<GaoJingItem>();
- xitem.init(bjlist[realIndex]);
- item.SetActive(true);
- }
- else
- {
- item.SetActive(false);
- }
- }
- }
|