- 新增Archive相关资源和预制体 - 新增SalesSystem销售系统基础 - 添加火山美术资源文件夹 Co-Authored-By: Claude Code <noreply@anthropic.com>
126 lines
3.2 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|