63 lines
1.0 KiB
C#
63 lines
1.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SetGlobalColor : MonoBehaviour
|
|
{
|
|
public bool onUpdate;
|
|
|
|
public int colorId;
|
|
|
|
public int colorHoverId = 5;
|
|
|
|
public int colorPressedId = 6;
|
|
|
|
public bool setAlpha = true;
|
|
|
|
public float colorAlpha = 255f;
|
|
|
|
private Image sprite;
|
|
|
|
private Text label;
|
|
|
|
private Button button;
|
|
|
|
private void Start()
|
|
{
|
|
sprite = base.gameObject.GetComponent<Image>();
|
|
label = base.gameObject.GetComponent<Text>();
|
|
button = base.gameObject.GetComponent<Button>();
|
|
Refresh();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (onUpdate)
|
|
{
|
|
Refresh();
|
|
}
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
if (!(GUIManager.Instance == null))
|
|
{
|
|
sprite = base.gameObject.GetComponent<Image>();
|
|
label = base.gameObject.GetComponent<Text>();
|
|
button = base.gameObject.GetComponent<Button>();
|
|
Color color = GUIManager.Instance.colors[colorId];
|
|
if (setAlpha)
|
|
{
|
|
color.a = colorAlpha / 255f;
|
|
}
|
|
if ((bool)sprite)
|
|
{
|
|
sprite.color = color;
|
|
}
|
|
if ((bool)label)
|
|
{
|
|
label.color = color;
|
|
}
|
|
}
|
|
}
|
|
}
|