75 lines
1.9 KiB
C#
75 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace BrewMonster.Scripts
|
|
{
|
|
public class LoopCommandListView : MonoBehaviour
|
|
{
|
|
[SerializeField] DlgConsole _console;
|
|
[SerializeField] Transform _content;
|
|
[SerializeField] LoopCommandListItem _itemPrefab;
|
|
[SerializeField] TMP_Text _emptyText;
|
|
|
|
private readonly List<LoopCommandListItem> _items = new List<LoopCommandListItem>();
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (_console != null)
|
|
_console.LoopCommandsChanged += Rebuild;
|
|
|
|
Rebuild();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (_console != null)
|
|
_console.LoopCommandsChanged -= Rebuild;
|
|
}
|
|
|
|
public void Rebuild()
|
|
{
|
|
if (_content == null || _itemPrefab == null || _console == null)
|
|
{
|
|
SetEmptyTextVisible(true);
|
|
return;
|
|
}
|
|
|
|
ClearItems();
|
|
|
|
var active = _console.GetActiveLoopCommands();
|
|
if (active == null || active.Count == 0)
|
|
{
|
|
SetEmptyTextVisible(true);
|
|
return;
|
|
}
|
|
|
|
SetEmptyTextVisible(false);
|
|
for (int i = 0; i < active.Count; i++)
|
|
{
|
|
var item = Instantiate(_itemPrefab, _content);
|
|
item.gameObject.SetActive(true);
|
|
item.Bind(_console, active[i]);
|
|
_items.Add(item);
|
|
}
|
|
}
|
|
|
|
private void ClearItems()
|
|
{
|
|
for (int i = 0; i < _items.Count; i++)
|
|
{
|
|
if (_items[i] != null)
|
|
Destroy(_items[i].gameObject);
|
|
}
|
|
_items.Clear();
|
|
}
|
|
|
|
private void SetEmptyTextVisible(bool visible)
|
|
{
|
|
if (_emptyText != null)
|
|
_emptyText.gameObject.SetActive(visible);
|
|
}
|
|
}
|
|
}
|
|
|