chicken_dy/Assets/Scripts/UI/CustomControl/PageSpot.cs

73 lines
1.5 KiB
C#
Raw Normal View History

2022-02-13 10:18:17 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PageSpot : MonoBehaviour
{
[SerializeField] GameObject mTplSpot;
private Transform mCtn;
private List<GameObject> mLightSpots;
2022-02-14 04:44:49 +00:00
private List<GameObject> mSpotList;
private int mSpotCount;
2022-02-13 10:18:17 +00:00
private void Awake()
{
mCtn = transform;
}
public void Init(int pTotalCount)
{
2022-02-14 04:44:49 +00:00
mSpotCount = pTotalCount;
2022-02-13 10:18:17 +00:00
mLightSpots = new List<GameObject>();
for (int i = 0; i < pTotalCount; i++)
{
2022-02-14 04:44:49 +00:00
GameObject tSpot = GetSpot(i);
2022-02-13 10:18:17 +00:00
mLightSpots.Add(tSpot.transform.GetChild(0).gameObject);
}
2022-02-14 04:44:49 +00:00
HideUnused();
2022-02-13 10:18:17 +00:00
}
public void SetPageIndex(int pCurrentIndex)
{
for(int i = 0; i < mLightSpots.Count; i++)
{
mLightSpots[i].SetActive(pCurrentIndex == i);
}
}
2022-02-14 04:44:49 +00:00
private GameObject GetSpot(int pSpotIndex)
{
if (mSpotList == null)
{
mSpotList = new List<GameObject>();
}
GameObject tCell = null;
if (pSpotIndex < mSpotList.Count)
{
tCell = mSpotList[pSpotIndex];
}
else
{
tCell = Instantiate(mTplSpot, mCtn);
tCell.transform.localScale = Vector3.one;
mSpotList.Add(tCell);
}
tCell.SetActive(true);
return tCell;
}
private void HideUnused()
{
for (int i = mSpotCount; i < mSpotList.Count; i++)
{
mSpotList[i].SetActive(false);
}
}
2022-02-13 10:18:17 +00:00
}