Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/EquipmentCategoryButton.cs
2026-02-21 16:45:37 +08:00

75 lines
1.6 KiB
C#

using System.Collections.Generic;
using BitStrap;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class EquipmentCategoryButton : MonoBehaviour
{
public List<GameObject> childButtons = new List<GameObject>();
public Image arrowImage;
public Image separatorImage;
public Text nameText;
public bool expandAtStart;
[ReadOnly]
public bool isExpanded;
private EquipmentGUI equipmentGUI;
private void OnEnable()
{
if (equipmentGUI != null)
{
Expand(false);
}
}
private void Start()
{
equipmentGUI = Object.FindObjectOfType<EquipmentGUI>();
isExpanded = !expandAtStart;
Expand(expandAtStart);
}
public void ToggleExpand()
{
Expand(!isExpanded);
}
public void Expand(bool expand)
{
if (expand == isExpanded)
{
return;
}
for (int i = 0; i < childButtons.Count; i++)
{
if ((equipmentGUI.isIceEquipment || !equipmentGUI.tabsOnlyIce.Contains(childButtons[i]) || !expand) && (!equipmentGUI.isIceEquipment || !equipmentGUI.tabsOnlyNormal.Contains(childButtons[i]) || !expand))
{
childButtons[i].SetActive(expand);
}
}
arrowImage.rectTransform.localScale = new Vector3((!expand) ? 1f : (-1f), 1f, 1f);
arrowImage.enabled = expand;
if ((bool)separatorImage)
{
separatorImage.enabled = expand;
}
if ((bool)nameText)
{
nameText.rectTransform.anchoredPosition = new Vector2((!expand) ? 0f : 23f, 0f);
}
if (EventSystem.current != null)
{
EventSystem.current.SetSelectedGameObject(null);
}
base.transform.parent.GetComponent<LayoutDynamicFix>().Refresh();
isExpanded = expand;
}
}