using UnityEngine; using UnityEngine.UI; using TMPro; namespace AibisDream.MiniGame.Language { /// /// 分析模式网格单元格组件 /// [RequireComponent(typeof(RectTransform))] public class AnalysisGridCell : MonoBehaviour { [Header("UI 组件")] [SerializeField] private Image backgroundImage; [SerializeField] private TMP_Text contentText; [Header("样式配置")] [SerializeField] private Color normalBackgroundColor = new Color(0f, 0.04f, 0f, 0.2f); [SerializeField] private Color highlightBackgroundColor = new Color(0f, 0f, 0f, 0.8f); private void Awake() { // 自动查找组件 if (backgroundImage == null) { backgroundImage = GetComponent(); } if (contentText == null) { contentText = GetComponentInChildren(); } // 设置默认样式 if (backgroundImage != null) { backgroundImage.color = normalBackgroundColor; } if (contentText != null) { contentText.color = Color.white; contentText.fontSize = 13f; contentText.alignment = TextAlignmentOptions.Center; contentText.enableWordWrapping = false; contentText.overflowMode = TextOverflowModes.Overflow; } } /// /// 设置单元格文本 /// public void SetText(string text) { if (contentText != null) { contentText.text = text; } } /// /// 设置文本颜色 /// public void SetTextColor(Color color) { if (contentText != null) { contentText.color = color; } } /// /// 设置背景颜色 /// public void SetBackgroundColor(Color color) { if (backgroundImage != null) { backgroundImage.color = color; } } /// /// 设置字体样式 /// public void SetFontStyle(FontStyles style) { if (contentText != null) { contentText.fontStyle = style; } } /// /// 设置透明度 /// public void SetAlpha(float alpha) { if (contentText != null) { Color color = contentText.color; color.a = alpha; contentText.color = color; } } /// /// 重置为默认样式 /// public void ResetStyle() { if (backgroundImage != null) { backgroundImage.color = normalBackgroundColor; } if (contentText != null) { contentText.color = Color.white; contentText.fontStyle = FontStyles.Normal; } } } }