- IconBase: 修复(N)后缀车辆名翻译, 添加OnDestroy取消订阅防止MissingReference - AnserWindowCtrl: 添加LanguageChanged订阅, 障碍提示实时翻译 - PlanningPlaneCtrl: 修复路径检查Count<0改为<1, 允许单段路径 - CarAIExtendCtrl: 空wayPoints数组防护 - GameObjectCreater: 重复key用索引赋值替代Add - NetHelper: 优先返回10.x/192.168.x局域网IP, 跳过WSL虚拟网卡 - 海岛/沙漠/丘陵: Terrain Layer设为Floor(8), NavigationStatic - 沙漠: TerrainLayer smoothness设为0 - 新增本地化条目: 携带装备/搭载人员/装备名称/空袭/维修厂等
85 lines
2.0 KiB
C#
85 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Text.RegularExpressions;
|
|
|
|
public class IconBase : MonoBehaviour
|
|
{
|
|
public IconType iconType;
|
|
public Text text_IconName;
|
|
public Image image_Icon;
|
|
private string rawName; // original name before localization
|
|
private string nameSuffix; // e.g. "(2)" if name was "5吨火炮拆装车(2)"
|
|
private bool subscribed;
|
|
|
|
void OnEnable()
|
|
{
|
|
if (!subscribed)
|
|
{
|
|
LocalizationManager.LanguageChanged += OnLanguageChanged;
|
|
subscribed = true;
|
|
}
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
Unsubscribe();
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
Unsubscribe();
|
|
}
|
|
|
|
private void Unsubscribe()
|
|
{
|
|
if (subscribed)
|
|
{
|
|
LocalizationManager.LanguageChanged -= OnLanguageChanged;
|
|
subscribed = false;
|
|
}
|
|
}
|
|
|
|
private void OnLanguageChanged()
|
|
{
|
|
if (this == null || !gameObject.activeInHierarchy) return;
|
|
if (text_IconName == null) return;
|
|
UpdateLocalizedText();
|
|
}
|
|
|
|
private void UpdateLocalizedText()
|
|
{
|
|
if (string.IsNullOrEmpty(rawName) || text_IconName == null) return;
|
|
|
|
Match m = Regex.Match(rawName, @"\(\d+\)$");
|
|
nameSuffix = m.Success ? m.Value : "";
|
|
string baseName = m.Success ? rawName.Substring(0, m.Index) : rawName;
|
|
|
|
string translated = LocalizationManager.Get(baseName);
|
|
if (!string.IsNullOrEmpty(nameSuffix))
|
|
translated += nameSuffix;
|
|
|
|
text_IconName.text = translated;
|
|
}
|
|
|
|
//设置显示名称和物体名称一致
|
|
public void SetName(string nameStr)
|
|
{
|
|
rawName = nameStr;
|
|
UpdateLocalizedText();
|
|
this.transform.name = nameStr;
|
|
}
|
|
|
|
public void SetSprite(Sprite sprite)
|
|
{
|
|
if (image_Icon != null)
|
|
image_Icon.sprite = sprite;
|
|
}
|
|
|
|
public virtual void SetUpdateIconMsg(object msg,string msgType = "")
|
|
{
|
|
|
|
}
|
|
}
|