Files
aibis-dream/Assets/Scripts/MiniGame/HuoShan/Language/AnalysisMode/AnalysisGridCell.cs
T
2025-12-09 21:42:49 +08:00

126 lines
3.2 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace AibisDream.MiniGame.Language
{
/// <summary>
/// 分析模式网格单元格组件
/// </summary>
[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<Image>();
}
if (contentText == null)
{
contentText = GetComponentInChildren<TMP_Text>();
}
// 设置默认样式
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;
}
}
/// <summary>
/// 设置单元格文本
/// </summary>
public void SetText(string text)
{
if (contentText != null)
{
contentText.text = text;
}
}
/// <summary>
/// 设置文本颜色
/// </summary>
public void SetTextColor(Color color)
{
if (contentText != null)
{
contentText.color = color;
}
}
/// <summary>
/// 设置背景颜色
/// </summary>
public void SetBackgroundColor(Color color)
{
if (backgroundImage != null)
{
backgroundImage.color = color;
}
}
/// <summary>
/// 设置字体样式
/// </summary>
public void SetFontStyle(FontStyles style)
{
if (contentText != null)
{
contentText.fontStyle = style;
}
}
/// <summary>
/// 设置透明度
/// </summary>
public void SetAlpha(float alpha)
{
if (contentText != null)
{
Color color = contentText.color;
color.a = alpha;
contentText.color = color;
}
}
/// <summary>
/// 重置为默认样式
/// </summary>
public void ResetStyle()
{
if (backgroundImage != null)
{
backgroundImage.color = normalBackgroundColor;
}
if (contentText != null)
{
contentText.color = Color.white;
contentText.fontStyle = FontStyles.Normal;
}
}
}
}