using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class uScrollViewMgr : BackKeyAdd { public ScrollRect m_ScrollRect; public GameObject m_Content; public GameObject go_card; protected List list_CardBase = new List(); protected RectTransform contentRt; protected override void Awake() { base.Awake(); Init(); } protected virtual void Init() { if (m_ScrollRect) contentRt = m_ScrollRect.content; else if (m_Content) contentRt = m_Content.GetComponent(); } protected void CardBase_AllOff() { for (int i = 0; i < list_CardBase.Count; i++) list_CardBase[i].gameObject.SetActive(false); } CardBase MakeCard(int i) { CardBase temp; if (list_CardBase.Count > i) temp = list_CardBase[i]; else { temp = DSUtil.Get_Clone(go_card, contentRt); list_CardBase.Add(temp); } return temp; } protected virtual void Set_ScrollView(List _lst) { CardBase_AllOff(); for (int i = 0; i < _lst.Count; i++) MakeCard(i).Set(_lst[i]); } protected virtual void Set_ScrollView_NotSet(int _makecount) { for (int i = 0; i < _makecount; i++) { if (list_CardBase.Count > i) { } else list_CardBase.Add(DSUtil.Get_Clone(go_card, contentRt)); } CardBase_AllOff(); } protected void ScrollTo_XY(Transform target) { Set_Coroutine(() => { Canvas.ForceUpdateCanvases(); contentRt.anchoredPosition = (Vector2)m_ScrollRect.transform.InverseTransformPoint(contentRt.position) - (Vector2)m_ScrollRect.transform.InverseTransformPoint(target.position); }, Time.deltaTime); } protected void ScrollTo(Transform target, bool vertical, float halfsize) { Set_Coroutine(() => { Canvas.ForceUpdateCanvases(); Vector2 offset = (Vector2)m_ScrollRect.transform.InverseTransformPoint(contentRt.position) - (Vector2)m_ScrollRect.transform.InverseTransformPoint(target.position); Vector2 anchor = contentRt.anchoredPosition; if (vertical) anchor.y = offset.y - halfsize; else anchor.x = offset.x - halfsize; contentRt.anchoredPosition = anchor; }, Time.deltaTime); } public virtual void Set_UI() { } }