63 lines
1.7 KiB
C#
63 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Ashwild.UI;
|
|
|
|
namespace Ashwild.Settings
|
|
{
|
|
public class SettingsPanel : UIPanel
|
|
{
|
|
[System.Serializable]
|
|
private struct CategoryEntry
|
|
{
|
|
public Button button;
|
|
public SettingsSubPanel subPanel;
|
|
}
|
|
|
|
[Header("Categories")]
|
|
[SerializeField] private List<CategoryEntry> categories;
|
|
[SerializeField] private int defaultCategoryIndex = 0;
|
|
|
|
[Header("Navigation")]
|
|
[SerializeField] private Button backButton;
|
|
|
|
private SettingsSubPanel activeSubPanel;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
for (int i = 0; i < categories.Count; i++)
|
|
{
|
|
int captured = i;
|
|
categories[i].button.onClick.AddListener(() => SelectCategory(captured));
|
|
}
|
|
|
|
backButton.onClick.AddListener(() => UIManager.Instance.Back());
|
|
}
|
|
|
|
public override void Show()
|
|
{
|
|
base.Show();
|
|
SelectCategory(defaultCategoryIndex);
|
|
}
|
|
|
|
public override void Hide()
|
|
{
|
|
if (activeSubPanel != null) activeSubPanel.gameObject.SetActive(false);
|
|
activeSubPanel = null;
|
|
base.Hide();
|
|
}
|
|
|
|
private void SelectCategory(int index)
|
|
{
|
|
if (index < 0 || index >= categories.Count) return;
|
|
|
|
if (activeSubPanel != null) activeSubPanel.gameObject.SetActive(false);
|
|
activeSubPanel = categories[index].subPanel;
|
|
activeSubPanel.gameObject.SetActive(true);
|
|
activeSubPanel.Refresh();
|
|
}
|
|
}
|
|
}
|