114 lines
3.3 KiB
C#
114 lines
3.3 KiB
C#
using BrewMonster.UI;
|
|
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class DlgSetting : AUIDialog
|
|
{
|
|
[Header("Box Button")]
|
|
[SerializeField] private Button btn_system;
|
|
[SerializeField] private Button btn_interface;
|
|
[SerializeField] private Button btn_setting;
|
|
[SerializeField] private Button btn_sound;
|
|
[SerializeField] private Button btn_default;
|
|
[SerializeField] private Button btn_confirm;
|
|
[SerializeField] private Button btn_close;
|
|
|
|
[Header("Content")]
|
|
[SerializeField] private GameObject content_interface;
|
|
[SerializeField] private GameObject content_sound;
|
|
|
|
[Header("Sprite")]
|
|
[SerializeField] private Sprite tab_active;
|
|
[SerializeField] private Sprite tab_unactive;
|
|
|
|
[Header("Tab Text Color")]
|
|
[SerializeField] private Color activeTextColor = Color.white;
|
|
[SerializeField] private Color inactiveTextColor = Color.white;
|
|
|
|
private Button[] tabButtons;
|
|
|
|
public override void Awake()
|
|
{
|
|
tabButtons = new[]
|
|
{
|
|
btn_system,
|
|
btn_interface,
|
|
btn_setting,
|
|
btn_sound
|
|
};
|
|
}
|
|
|
|
public override void OnEnable()
|
|
{
|
|
btn_system.onClick.AddListener(OnBtnSystem);
|
|
btn_interface.onClick.AddListener(OnBtnInterface);
|
|
btn_setting.onClick.AddListener(OnBtnSetting);
|
|
btn_sound.onClick.AddListener(OnBtnSound);
|
|
btn_close.onClick.AddListener(OnBtnClose);
|
|
}
|
|
|
|
public override void OnDisable()
|
|
{
|
|
btn_system.onClick.RemoveListener(OnBtnSystem);
|
|
btn_interface.onClick.RemoveListener(OnBtnInterface);
|
|
btn_setting.onClick.RemoveListener(OnBtnSetting);
|
|
btn_sound.onClick.RemoveListener(OnBtnSound);
|
|
btn_close.onClick.RemoveListener(OnBtnClose);
|
|
}
|
|
|
|
private void OnBtnSystem()
|
|
{
|
|
SetActiveTab(btn_system);
|
|
}
|
|
|
|
private void OnBtnInterface()
|
|
{
|
|
SetActiveTab(btn_interface);
|
|
content_interface.SetActive(true);
|
|
content_sound.SetActive(false);
|
|
}
|
|
|
|
private void OnBtnSetting()
|
|
{
|
|
SetActiveTab(btn_setting);
|
|
}
|
|
|
|
private void OnBtnSound()
|
|
{
|
|
SetActiveTab(btn_sound);
|
|
content_interface.SetActive(false);
|
|
content_sound.SetActive(true);
|
|
}
|
|
|
|
private void SetActiveTab(Button activeButton)
|
|
{
|
|
foreach(Button button in tabButtons)
|
|
{
|
|
if (button == null)
|
|
continue;
|
|
|
|
Image image = button.GetComponent<Image>();
|
|
if(image != null)
|
|
{
|
|
image.sprite = button == activeButton ? tab_active : tab_unactive;
|
|
}
|
|
|
|
TMP_Text text = button.GetComponentInChildren<TMP_Text>();
|
|
if(text != null)
|
|
{
|
|
text.color = button == activeButton ? activeTextColor : inactiveTextColor;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnBtnClose()
|
|
{
|
|
CECUIManager.Instance.HideCurrentUIInStack();
|
|
}
|
|
}
|
|
}
|