Files
aibis-dream/Assets/Scripts/FixSystemNew/Screen System/FixPanel/ScreenPanel.cs
T

71 lines
2.4 KiB
C#

using UnityEngine;
using AibisDream.UI;
using AibisDream.Framework;
using System;
using TMPro;
namespace AibisDream.FixSystem
{
public class ScreenPanel : MonoBehaviour, ILineView
{
private const string WarningCharacterKey = "Error";
private static readonly Color WarningRedColor = new(0.9607843f, 0.4235294f, 0.4235294f, 1f);
private static readonly Color AmberColor = new(0.9019608f, 0.6352941f, 0.2352941f, 1f);
private static readonly Color BodyTextColor = new(0.9196079f, 0.7009804f, 0.372549f, 1f);
[SerializeField] private TMP_Text title;
[SerializeField] private TerminalText logText;
private void Awake()
{
EnumEventSystem.Global.Register<ScreenEventEnum, GameObject>(ScreenEventEnum.Selected, OnSelected);
EnumEventSystem.Global.Register(EventEnum.PlugOut, ClearScreen);
logText?.SetTextColor(BodyTextColor);
}
private void OnDestroy()
{
EnumEventSystem.Global.UnRegister(ScreenEventEnum.Selected);
EnumEventSystem.Global.UnRegister(EventEnum.PlugOut);
}
private void OnSelected(GameObject obj)
{
gameObject.SetActive(obj == gameObject);
}
// ---------------------- 对话框功能 ----------------------
public void RunLine(LineSyncToken token)
{
if (logText != null)
{
EnumEventSystem.Global.Send(ScreenEventEnum.Selected, gameObject);
logText.PrepareForLine();
logText.OnTextShown += () => token.TextShown();
bool isWarning = string.Equals(token.lineInfo.character.key, WarningCharacterKey,
StringComparison.OrdinalIgnoreCase);
title.overrideColorTags = true;
title.color = isWarning ? WarningRedColor : AmberColor;
title.text = token.lineInfo.character.GetActorName();
logText.SetTypewriterSpeed(TextSpeedSettings.CurrentMultiplier);
token.TextStart();
logText.AddText(token.lineInfo.lineText);
}
else
{
Debug.LogError("UniversalScreen: logText 为空");
}
}
public void ClearScreen()
{
logText.Clear();
title.text = string.Empty;
}
}
}