76 lines
2.3 KiB
C#
76 lines
2.3 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using System.Collections.Generic;
|
|
|
|
namespace AibisDream.MiniGame.HuoShan
|
|
{
|
|
/// <summary>
|
|
/// 文字节点类 - 管理单个文字的显示、状态和连接关系
|
|
/// </summary>
|
|
public class TextNode
|
|
{
|
|
public Vector2 Position { get; set; }
|
|
public string Text { get; set; }
|
|
public TextNodeState State { get; set; }
|
|
public float Brightness { get; set; } = 1f;
|
|
public float Scale { get; set; } = 1f;
|
|
public Color Color { get; set; } = Color.white;
|
|
public float Probability { get; set; } = 0f; // 候选文字的概率
|
|
|
|
// 连接关系
|
|
public List<TextNode> ConnectedNodes { get; private set; }
|
|
|
|
// UI组件引用
|
|
public TextMeshPro TextComponent { get; set; }
|
|
public GameObject GameObject { get; set; }
|
|
|
|
// 句子相关
|
|
public int SentenceIndex { get; set; } = -1; // 在句子中的索引,-1表示不在句子中
|
|
public bool IsStuck { get; set; } = false; // 是否处于卡壳状态
|
|
|
|
public TextNode(Vector2 position, string text)
|
|
{
|
|
Position = position;
|
|
Text = text;
|
|
State = TextNodeState.Random;
|
|
ConnectedNodes = new List<TextNode>();
|
|
}
|
|
|
|
public void AddConnection(TextNode node)
|
|
{
|
|
if (!ConnectedNodes.Contains(node))
|
|
{
|
|
ConnectedNodes.Add(node);
|
|
}
|
|
}
|
|
|
|
public void RemoveConnection(TextNode node)
|
|
{
|
|
ConnectedNodes.Remove(node);
|
|
}
|
|
|
|
public void UpdateVisual()
|
|
{
|
|
if (TextComponent != null)
|
|
{
|
|
TextComponent.text = Text;
|
|
TextComponent.color = Color * Brightness;
|
|
TextComponent.transform.localScale = Vector3.one * Scale;
|
|
TextComponent.transform.position = new Vector3(Position.x, Position.y, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 文字节点状态
|
|
/// </summary>
|
|
public enum TextNodeState
|
|
{
|
|
Random, // 随机变化状态
|
|
Selected, // 已选定的文字(句子中的字)
|
|
Candidate, // 候选文字
|
|
Stuck // 卡壳状态
|
|
}
|
|
}
|
|
|