diff --git a/Assets/Scripts/GameObjectCtrl/CarCtrl.cs b/Assets/Scripts/GameObjectCtrl/CarCtrl.cs index cb4efac..2ff8303 100644 --- a/Assets/Scripts/GameObjectCtrl/CarCtrl.cs +++ b/Assets/Scripts/GameObjectCtrl/CarCtrl.cs @@ -332,14 +332,18 @@ public class CarCtrl : MonoBehaviour, IBindIcon,IShowName3DText //if (Text3DCtrl_Names == null) // Text3DCtrl_Names = this.GetComponentsInChildren(); - string textValue = data.carName; - if (!string.IsNullOrEmpty(inAreaName)) + string carName = data.carName; + string nameSuffix = ""; + int idx = carName.IndexOf('('); + if (idx > 0) { - textValue = $"{textValue}({inAreaName})"; + nameSuffix = carName.Substring(idx); + carName = carName.Substring(0, idx); } + string areaName = inAreaName; for (int i = 0; i < Text3DCtrl_Names.Length; i++) { - Text3DCtrl_Names[i]?.SetName(textValue); + Text3DCtrl_Names[i]?.SetName(carName, areaName, nameSuffix); } } diff --git a/Assets/Scripts/GameObjectCtrl/Text3DCtrl.cs b/Assets/Scripts/GameObjectCtrl/Text3DCtrl.cs index 9638fe7..87e236b 100644 --- a/Assets/Scripts/GameObjectCtrl/Text3DCtrl.cs +++ b/Assets/Scripts/GameObjectCtrl/Text3DCtrl.cs @@ -9,6 +9,8 @@ public class Text3DCtrl : MonoBehaviour Transform targetTrans; float angleX; string sourceText; + string extraText; + string suffixText; public void SetLayer(string LayerName) { @@ -48,9 +50,29 @@ public class Text3DCtrl : MonoBehaviour public void SetName(string text) { sourceText = text; + extraText = null; + suffixText = null; textMesh.text = LocalizationManager.Get(text); } + public void SetName(string text, string area, string suffix = null) + { + sourceText = text; + extraText = area; + suffixText = suffix; + UpdateDisplayText(); + } + + private void UpdateDisplayText() + { + string name = LocalizationManager.Get(sourceText); + if (!string.IsNullOrEmpty(suffixText)) + name += suffixText; + if (!string.IsNullOrEmpty(extraText)) + name = $"{name}({LocalizationManager.Get(extraText)})"; + textMesh.text = name; + } + //选选取的时候 改变文字颜色 public void ChangeTextColor(Color newColor) { @@ -65,7 +87,7 @@ public class Text3DCtrl : MonoBehaviour private void OnLanguageChanged() { if (!string.IsNullOrEmpty(sourceText)) - textMesh.text = LocalizationManager.Get(sourceText); + UpdateDisplayText(); } void OnDestroy()