add mini uma facial
This commit is contained in:
@@ -15,29 +15,38 @@ public class PageManager : MonoBehaviour
|
||||
{
|
||||
public ScrollRect ScrollRect;
|
||||
public InputField PageText;
|
||||
public InputField SearchText;
|
||||
public int ShowCount;
|
||||
public GameObject ContainerPrefab;
|
||||
private int totalPage;
|
||||
private int currentPage = 0;
|
||||
private List<Entry> Entries;
|
||||
private List<Entry> SubEntries;
|
||||
public void Initialize(List<Entry> entries, ScrollRect scrollRect)
|
||||
{
|
||||
ScrollRect = scrollRect;
|
||||
Entries = entries;
|
||||
if (SearchText)
|
||||
SearchText.text = "";
|
||||
ShowCount = Mathf.FloorToInt(ScrollRect.GetComponent<RectTransform>().rect.height / ContainerPrefab.GetComponent<RectTransform>().rect.height);
|
||||
totalPage = Mathf.CeilToInt(entries.Count / (float)ShowCount);
|
||||
if (totalPage > 0)
|
||||
{
|
||||
currentPage = 0;
|
||||
LoadPage(currentPage);
|
||||
SearchText.interactable = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetCtrl()
|
||||
{
|
||||
if(ScrollRect)Clear();
|
||||
totalPage = 0;
|
||||
currentPage = 0;
|
||||
PageText.text = "";
|
||||
if(SearchText)
|
||||
SearchText.text = "";
|
||||
SearchText.interactable = false;
|
||||
SubEntries = null;
|
||||
Entries = null;
|
||||
((Text)PageText.placeholder).text = $"- / -";
|
||||
}
|
||||
@@ -45,14 +54,15 @@ public class PageManager : MonoBehaviour
|
||||
private void LoadPage(int index)
|
||||
{
|
||||
if (totalPage == 0) return;
|
||||
var entries = (SearchText && SearchText.text != "" ? SubEntries : Entries);
|
||||
Clear();
|
||||
PageText.text = "";
|
||||
((Text)PageText.placeholder).text = $"{currentPage + 1} / {totalPage}";
|
||||
var start = ShowCount * index;
|
||||
for (int i = 0;i< ShowCount; i++)
|
||||
{
|
||||
if (start + i >= Entries.Count) break;
|
||||
var entry = Entries[start + i];
|
||||
if (start + i >= entries.Count) break;
|
||||
var entry = entries[start + i];
|
||||
var container = Instantiate(ContainerPrefab, ScrollRect.content).GetComponent<UmaUIContainer>();
|
||||
container.Name = container.name = entry.Name;
|
||||
if (entry.FontSize > 0)
|
||||
@@ -76,8 +86,30 @@ public class PageManager : MonoBehaviour
|
||||
LoadPage(currentPage);
|
||||
}
|
||||
|
||||
private void Clear()
|
||||
public void OnSearch(string val)
|
||||
{
|
||||
Clear();
|
||||
if (Entries == null) return;
|
||||
if(val == "")
|
||||
{
|
||||
Initialize(Entries, ScrollRect);
|
||||
}
|
||||
else
|
||||
{
|
||||
SubEntries = new List<Entry>(Entries.Where(a => a.Name.Contains(val)));
|
||||
ShowCount = Mathf.FloorToInt(ScrollRect.GetComponent<RectTransform>().rect.height / ContainerPrefab.GetComponent<RectTransform>().rect.height);
|
||||
totalPage = Mathf.CeilToInt(SubEntries.Count / (float)ShowCount);
|
||||
if (totalPage > 0)
|
||||
{
|
||||
currentPage = 0;
|
||||
LoadPage(currentPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (!ScrollRect) return;
|
||||
for (int i = ScrollRect.content.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
Destroy(ScrollRect.content.GetChild(i).gameObject);
|
||||
|
||||
Reference in New Issue
Block a user