using UnityEngine.UI;
namespace UnityEngine.Rendering.UI
{
/// Foldout in the DebugMenu
[ExecuteAlways]
public class UIFoldout : Toggle
{
/// Contents inside the toggle
public GameObject content;
/// Arror in state opened
public GameObject arrowOpened;
/// Arror in state closed
public GameObject arrowClosed;
/// Start of this GameObject lifecicle
protected override void Start()
{
base.Start();
onValueChanged.AddListener(SetState);
SetState(isOn);
}
#pragma warning disable 108,114
void OnValidate()
{
SetState(isOn, false);
}
#pragma warning restore 108,114
/// Change the state of this foldout
/// The new State
public void SetState(bool state)
{
SetState(state, true);
}
/// Change the state of this foldout
/// The new State
/// If True, the layout will be rebuild
public void SetState(bool state, bool rebuildLayout)
{
if (arrowOpened == null || arrowClosed == null || content == null)
return;
if (arrowOpened.activeSelf != state)
arrowOpened.SetActive(state);
if (arrowClosed.activeSelf == state)
arrowClosed.SetActive(!state);
if (content.activeSelf != state)
content.SetActive(state);
if (rebuildLayout)
LayoutRebuilder.ForceRebuildLayoutImmediate(transform.parent as RectTransform);
}
}
}