using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TcgEngine; namespace TcgEngine.UI { /// /// Changes the color of a unity ui toggle text /// public class ToggleText : MonoBehaviour { public Color on_color = Color.yellow; public Color off_color = Color.white; public int on_size = 42; public int off_size = 36; [Header("判断启用文字颜色选中还是文字大小选中")] public bool is_color = true; private Toggle toggle; private Text toggle_txt; private bool previous = false; void Awake() { toggle = GetComponent(); toggle_txt = GetComponentInChildren(); } private void Start() { on_size = toggle_txt.fontSize; off_size = (int)(toggle_txt.fontSize * 0.8f); Refresh(); } void Update() { if (previous != toggle.isOn) Refresh(); } private void Refresh() { if (is_color) { toggle_txt.color = toggle.isOn ? on_color : off_color; } else { toggle_txt.fontSize = toggle.isOn ? on_size : off_size; toggle_txt.fontStyle = toggle.isOn ? FontStyle.Bold : FontStyle.Normal; } previous = toggle.isOn; } } }