迁移剩下的 UI 到 Serialization 方式
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public partial class DisplayListForm
|
||||
{
|
||||
private readonly List<DisplayItem> _displayItems = new List<DisplayItem>();
|
||||
|
||||
public void OnInit(DisplayListContext context)
|
||||
{
|
||||
View.titleFormatText.Set(context.CurrentCount, context.MaxCount);
|
||||
|
||||
int targetCount = Mathf.Min(context.CurrentCount, context.ItemContexts.Length);
|
||||
EnsureItemCount(targetCount);
|
||||
|
||||
for (int i = 0; i < _displayItems.Count; i++)
|
||||
{
|
||||
DisplayItem item = _displayItems[i];
|
||||
if (i < targetCount)
|
||||
{
|
||||
item.OnInit(context.ItemContexts[i], i).Forget();
|
||||
item.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.OnReset();
|
||||
item.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
{
|
||||
for (int i = 0; i < _displayItems.Count; i++)
|
||||
{
|
||||
_displayItems[i].OnReset();
|
||||
_displayItems[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureItemCount(int count)
|
||||
{
|
||||
while (_displayItems.Count < count)
|
||||
{
|
||||
DisplayItem item = Instantiate(View.displayItemTemplate, View.listRoot.transform);
|
||||
_displayItems.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user