unityzgy/Assets/Scripts/UIScripts/ThisProjectPublic/PromptTextCtrl.cs
ayuan9957 31a3fb4f30 fix: 翻译完善 + 预制体verticalOverflow + 连续训练相机修复
- PromptTextCtrl: 新增SetPromptLocalized支持3秒内实时翻译
- StudentSub2EditorPanel: 3处SetPrompt改SetPromptLocalized
- AppraiseSliderCtrl: 评价指标名称用Get()翻译
- WaitResultPanel: 评价等级用Get()翻译避免先闪中文
- EditorAppraiser: 厂区距离提示中厂区名称先Get()翻译
- GameObjectManager: 距离提示用Get()翻译
- StudentSub2EditorPanel: Text_terrainName同步地形名+实时翻译
- SubStart: 车辆列表为空时回退CameraPos定位相机
- 所有UI预制体verticalOverflow改为Overflow(322处)
- LocalizationManager/LoginPanel/HistoryPanel/VRTooltip: 移除强制Overflow
- 分组错误提示用Get()翻译+新增4条翻译
- 山地作为林地别名在代码回退字典中
2026-08-04 10:33:05 +08:00

97 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//提示文字控制类
public class PromptTextCtrl : MonoBehaviour
{
Text text;
string currentKey; // 本地化key用于语言切换时重新翻译
object[] currentArgs; // 格式参数
bool isLocalized; // 是否使用本地化模式
bool subscribed;
void Awake()
{
text = this.GetComponent<Text>();
HideText();
}
void OnEnable()
{
if (!subscribed)
{
LocalizationManager.LanguageChanged += OnLanguageChanged;
subscribed = true;
}
}
void OnDisable()
{
if (subscribed)
{
LocalizationManager.LanguageChanged -= OnLanguageChanged;
subscribed = false;
}
CancelInvoke();
HideText();
}
private void OnLanguageChanged()
{
if (isLocalized && !string.IsNullOrEmpty(currentKey) && text != null && !string.IsNullOrEmpty(text.text))
{
if (currentArgs != null && currentArgs.Length > 0)
text.text = LocalizationManager.Format(LocalizationManager.Get(currentKey), currentArgs);
else
text.text = LocalizationManager.Get(currentKey);
}
}
/// <summary>
/// 设置本地化提示文字,语言切换时自动重新翻译
/// </summary>
public void SetPromptLocalized(string key, Color textColor, float time = 0, params object[] args)
{
isLocalized = true;
currentKey = key;
currentArgs = args;
if (text == null)
text = this.GetComponent<Text>();
text.color = textColor;
if (args != null && args.Length > 0)
text.text = LocalizationManager.Format(LocalizationManager.Get(key), args);
else
text.text = LocalizationManager.Get(key);
if (time != 0)
{
if (IsInvoking("HideText"))
CancelInvoke("HideText");
Invoke("HideText", time);
}
}
public void SetPrompt(string msg, Color textColor, float time = 0)
{
isLocalized = false;
currentKey = null;
currentArgs = null;
if (text == null)
text = this.GetComponent<Text>();
text.color = textColor;
text.text = msg;
if (time != 0)
{
if (IsInvoking("HideText"))
CancelInvoke("HideText");
Invoke("HideText", time);
}
}
private void HideText()
{
if (text != null)
text.text = "";
}
}