<aside> ❓ 조건
<aside> 📌 기능
ObjectPooling.cs
using UnityEngine;
using UnityEngine.UI;
public class ObjectPooling : MonoBehaviour
{
public static ObjectPooling instance;
[SerializeField]
private GameObject[] objPool;
LinkedList<string> datas; //데이터 리스트
[SerializeField] RectTransform scrollRect;
[SerializeField] Scrollbar scrollBar;
int count = 0;
bool check = false;
public GameObject NodeUI;
private void Awake()
{
if (instance != null)
Destroy(instance);
instance = this;
datas = new LinkedList<string>();
scrollBar.value = 0;
}
void Start()
{
//임시로 데이터 넣어놓고 확인해보기
for (int i = 0; i < 100; i++)
{
datas.Insert(i.ToString());
}
for (int i = 0; i < 10; i++)
{
objPool[i].GetComponentInChildren<Text>().text = datas.SearchIndex(i);
count++;
}
}
private void Update()
{
if (scrollBar.value == 1 && count != datas.Count())
{
if (check == true)
{
count += 11;
}
OnCheckScrollingUP();
scrollBar.value = 0.94f;
check = false;
}else if (scrollBar.value == 0 && count >0 && objPool[0].GetComponentInChildren<Text>().text != datas.SearchIndex(0))
{
if(check==false)
{
count -= 11;
}
OnCheckScrollingDown();
check = true;
scrollBar.value = 0.06f;
}
}
public void OnCheckScrollingUP()
{
Transform goj = scrollRect.GetChild(0);
goj.SetAsLastSibling();
goj.gameObject.GetComponentInChildren<Text>().text = datas.SearchIndex(count);
count++;
}
public void OnCheckScrollingDown()
{
Transform goj = scrollRect.GetChild(9);
goj.SetAsFirstSibling();
goj.gameObject.GetComponentInChildren<Text>().text = datas.SearchIndex(count);
count--;
}
}
뒤로 스크롤링
public void OnCheckScrollingUP()
{
Transform goj = scrollRect.GetChild(0);
goj.SetAsLastSibling();
goj.gameObject.GetComponentInChildren<Text>().text = datas.SearchIndex(count);
count++;
}
앞으로 스크롤링
public void OnCheckScrollingDown()
{
Transform goj = scrollRect.GetChild(9);
goj.SetAsFirstSibling();
goj.gameObject.GetComponentInChildren<Text>().text = datas.SearchIndex(count);
count--;
}