Project_WL/Assets/Script/Util/uScrollViewArrMgr.cs

64 lines
1.9 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class uScrollViewArrMgr : BackKeyAdd
{
public ScrollRect[] m_scrollview;
public GameObject[] m_content;
public GameObject[] go_card;
protected List<Transform> list_cardParent = new List<Transform>();
protected Dictionary<int, List<CardBase>> dic_cardbase = new Dictionary<int, List<CardBase>>();
void Init()
{
if (list_cardParent.Count == 0)
{
if (m_scrollview != null && m_scrollview.Length > 0)
{
for (int i = 0; i < m_scrollview.Length; i++)
{
list_cardParent.Add(m_scrollview[i].content);
dic_cardbase.Add(i, new List<CardBase>());
}
}
else if (m_content != null && m_content.Length > 0)
{
for (int i = 0; i < m_content.Length; i++)
{
list_cardParent.Add(m_content[i].transform);
dic_cardbase.Add(i, new List<CardBase>());
}
}
}
}
protected void CardBase_AllOff(int _index)
{
Init();
for (int i = 0; i < dic_cardbase[_index].Count; i++)
dic_cardbase[_index][i].gameObject.SetActive(false);
}
CardBase MakeCard(int _index, int i)
{
CardBase temp;
if (dic_cardbase[_index].Count > i) temp = dic_cardbase[_index][i];
else
{
temp = DSUtil.Get_Clone<CardBase>(go_card[_index], list_cardParent[_index]);
dic_cardbase[_index].Add(temp);
}
return temp;
}
protected virtual void Set_ScrollView<T>(int _index, List<T> _lst, bool _forcerepos = false)
{
CardBase_AllOff(_index);
for (int i = 0; i < _lst.Count; i++)
MakeCard(_index, i).Set(_lst[i]);
}
}