69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using System.Globalization;
|
|
using System.Linq;
|
|
using AibisDream.UI;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
public class UniversalScreen : MonoBehaviour, ILineView
|
|
{
|
|
[Header("是否为对话容器")]
|
|
[SerializeField] private bool IsLineView = false;
|
|
[SerializeField] private TerminalText logText;
|
|
|
|
[Header("其他字段")]
|
|
[SerializeField] private TMP_Text[] textFields;
|
|
[SerializeField] private Image[] imageFields;
|
|
|
|
public void SetText(string fieldName, string text)
|
|
{
|
|
var targetField = textFields.FirstOrDefault(t => t.name == fieldName);
|
|
if (targetField != null)
|
|
{
|
|
targetField.text = text;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"UniversalScreen: 未找到字段{fieldName}");
|
|
}
|
|
}
|
|
|
|
public void SetImage(string fieldName, Sprite image)
|
|
{
|
|
var targetField = imageFields.FirstOrDefault(t => t.name == fieldName);
|
|
if (targetField != null)
|
|
{
|
|
targetField.sprite = image;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"UniversalScreen: 未找到字段{fieldName}");
|
|
}
|
|
}
|
|
|
|
// ---------------------- 对话框功能 ----------------------
|
|
public void RunLine(LineSyncToken token)
|
|
{
|
|
if (logText != null)
|
|
{
|
|
logText.OnTextShown += () => token.TextShown();
|
|
|
|
logText.SetTypewriterSpeed(GetTextSpeedValue());
|
|
logText.AddText(token.lineInfo.lineText);
|
|
token.TextStart();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("UniversalScreen: logText 为空");
|
|
}
|
|
}
|
|
|
|
private float GetTextSpeedValue()
|
|
{
|
|
var textSpeedStr = SettingLoader.Instance.TryRead("TextSpeed", out string textSpeed) ? textSpeed : "1";
|
|
return float.TryParse(textSpeedStr, NumberStyles.Float, CultureInfo.InvariantCulture, out float result) ? result : 1f;
|
|
}
|
|
}
|
|
} |