77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace AibisDream.MiniGame.Language
|
|
{
|
|
/// <summary>
|
|
/// 背景浮动文字粒子
|
|
/// </summary>
|
|
public class FloatingTextParticle : TextParticle
|
|
{
|
|
private Color baseColor = new Color(0.7f, 0.78f, 1f, 1f); // 默认颜色
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
// 背景文字特性
|
|
baseAlpha = Random.Range(0.04f, 0.1f); // 0-1 范围的透明度
|
|
alpha = baseAlpha;
|
|
size = Random.Range(1.5f, 2.5f);
|
|
velocity = new Vector2(Random.Range(-1.2f, 1.2f), Random.Range(-1.2f, 1.2f));
|
|
changeInterval = Random.Range(0.2f, 0.3f);
|
|
|
|
if (textMesh != null)
|
|
{
|
|
textMesh.fontSize = size;
|
|
textMesh.color = new Color(baseColor.r, baseColor.g, baseColor.b, alpha);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置粒子颜色
|
|
/// </summary>
|
|
public void SetColor(Color color)
|
|
{
|
|
baseColor = color;
|
|
if (textMesh != null)
|
|
{
|
|
textMesh.color = new Color(baseColor.r, baseColor.g, baseColor.b, alpha);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 背景粒子从干扰短句(笑话等)字符中随机显示单字。
|
|
/// </summary>
|
|
protected override string GetNextDisplayChar()
|
|
{
|
|
return GetRandomCharFromPhrases();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置字体大小
|
|
/// </summary>
|
|
public void SetFontSize(float fontSize)
|
|
{
|
|
size = fontSize;
|
|
if (textMesh != null)
|
|
{
|
|
textMesh.fontSize = size;
|
|
}
|
|
}
|
|
|
|
protected override void UpdateVisuals()
|
|
{
|
|
if (textMesh != null)
|
|
{
|
|
Color color = new Color(baseColor.r, baseColor.g, baseColor.b, alpha);
|
|
textMesh.color = color;
|
|
}
|
|
|
|
if (glowSprite != null)
|
|
{
|
|
glowSprite.color = new Color(baseColor.r, baseColor.g, baseColor.b, alpha * 0.3f);
|
|
}
|
|
}
|
|
}
|
|
}
|