114 lines
3.4 KiB
C#
114 lines
3.4 KiB
C#
|
|
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<CardBase> list_CardBase = new List<CardBase>();
|
||
|
|
protected RectTransform contentRt;
|
||
|
|
|
||
|
|
protected CardBase m_SelectCard;
|
||
|
|
|
||
|
|
protected override void Awake()
|
||
|
|
{
|
||
|
|
base.Awake();
|
||
|
|
Init();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected virtual void Init()
|
||
|
|
{
|
||
|
|
if (DSUtil.CheckNull(contentRt))
|
||
|
|
{
|
||
|
|
if (m_ScrollRect)
|
||
|
|
contentRt = m_ScrollRect.content;
|
||
|
|
else if (m_Content)
|
||
|
|
contentRt = m_Content.GetComponent<RectTransform>();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
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<CardBase>(go_card, contentRt);
|
||
|
|
list_CardBase.Add(temp);
|
||
|
|
}
|
||
|
|
return temp;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void ClickCard(int intdata)
|
||
|
|
{
|
||
|
|
for (int i = 0; i < list_CardBase.Count; i++)
|
||
|
|
{
|
||
|
|
if (list_CardBase[i].Get_IntData() == intdata)
|
||
|
|
{
|
||
|
|
list_CardBase[i].OnClick_Card();
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public virtual void Select_Card(CardBase card)
|
||
|
|
{
|
||
|
|
if (m_SelectCard) m_SelectCard.Set_Selected(false);
|
||
|
|
m_SelectCard = card;
|
||
|
|
m_SelectCard.Set_Selected(true);
|
||
|
|
}
|
||
|
|
public CardBase Get_SelectCard() { return m_SelectCard; }
|
||
|
|
public int Get_IntData() { return m_SelectCard ? m_SelectCard.Get_IntData() : -1; }
|
||
|
|
|
||
|
|
protected virtual void Set_ScrollView<T>(List<T> _lst, int intdata = -1)
|
||
|
|
{
|
||
|
|
Init();
|
||
|
|
CardBase_AllOff();
|
||
|
|
|
||
|
|
for (int i = 0; i < _lst.Count; i++)
|
||
|
|
MakeCard(i).Set(_lst[i]);
|
||
|
|
|
||
|
|
if (intdata > 0) ClickCard(intdata);
|
||
|
|
}
|
||
|
|
protected virtual void Set_ScrollView_NotSet(int _makecount)
|
||
|
|
{
|
||
|
|
Init();
|
||
|
|
for (int i = 0; i < _makecount; i++)
|
||
|
|
{
|
||
|
|
if (list_CardBase.Count > i) { }
|
||
|
|
else list_CardBase.Add(DSUtil.Get_Clone<CardBase>(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)
|
||
|
|
{
|
||
|
|
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 - target.GetComponent<RectTransform>().sizeDelta.y;
|
||
|
|
else anchor.x = offset.x - target.GetComponent<RectTransform>().sizeDelta.x;
|
||
|
|
contentRt.anchoredPosition = anchor;
|
||
|
|
}, Time.deltaTime);
|
||
|
|
}
|
||
|
|
|
||
|
|
public virtual void Set_UI() { }
|
||
|
|
}
|