Files
2026-03-04 10:03:45 +08:00

63 lines
1.3 KiB
C#

using UnityEngine;
using UnityEngine.UI;
namespace Gaia
{
[ExecuteInEditMode]
public class UIConfiguration : MonoBehaviour
{
[Header("UI Settings")]
[Tooltip("Sets the UI text color")]
public Color32 m_uiTextColor = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
[Tooltip("Button used to toggle the UI on and off")]
public KeyCode m_uiToggleButton = KeyCode.U;
private Text m_textContent;
private Color32 storedColor;
private bool storedUIStatus = true;
private void Start()
{
storedColor = m_uiTextColor;
if (m_textContent != null)
{
m_textContent.color = storedColor;
}
}
private void OnEnable()
{
if (m_textContent == null)
{
GameObject gameObject = GameObject.Find("Control Text");
if (gameObject != null)
{
m_textContent = gameObject.GetComponent<Text>();
}
}
}
private void LateUpdate()
{
storedColor = m_uiTextColor;
if (storedUIStatus && Input.GetKeyDown(m_uiToggleButton))
{
m_textContent.enabled = false;
storedUIStatus = false;
}
else if (!storedUIStatus && Input.GetKeyDown(m_uiToggleButton))
{
m_textContent.enabled = true;
storedUIStatus = true;
}
if (m_textContent.color != storedColor && m_textContent != null)
{
m_textContent.color = storedColor;
}
}
}
}