- Text3DCtrl: 新增SetName(text, area, suffix)重载,各部分独立翻译 - CarCtrl.Update3DText: 从carName中分离(1)等后缀,纯名称查翻译表 - 修复车辆展开后名称含中文问题(组合字符串无法匹配翻译表) - 修复收起/展开后文字不刷新问题(LanguageChanged事件重建文本)
107 lines
2.6 KiB
C#
107 lines
2.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Text3DCtrl : MonoBehaviour
|
|
{
|
|
public TextMesh textMesh;
|
|
public LookAtState LookAtState = LookAtState.LookAt;
|
|
Transform targetTrans;
|
|
float angleX;
|
|
string sourceText;
|
|
string extraText;
|
|
string suffixText;
|
|
|
|
public void SetLayer(string LayerName)
|
|
{
|
|
this.gameObject.layer = LayerMask.NameToLayer(LayerName);
|
|
}
|
|
|
|
public void SetLookTarget(Transform transform)
|
|
{
|
|
targetTrans = transform;
|
|
angleX = this.transform.localEulerAngles.x;
|
|
}
|
|
|
|
public void SetTextSize(float size)
|
|
{
|
|
if (size != 0)
|
|
textMesh.characterSize = size;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (targetTrans&&transform.gameObject.activeSelf)
|
|
{
|
|
transform.LookAt(transform.position + targetTrans.rotation * Vector3.forward,
|
|
targetTrans.rotation * Vector3.up);
|
|
if (LookAtState == LookAtState.LookAtKeepX)//保持X轴 只旋转Y轴
|
|
{
|
|
Vector3 eulerAngles = this.transform.localEulerAngles;
|
|
eulerAngles.x = 0;
|
|
eulerAngles.z = 0;
|
|
this.transform.localEulerAngles = eulerAngles;
|
|
}
|
|
}
|
|
//this.transform.eulerAngles += new Vector3(0,180,0);
|
|
}
|
|
|
|
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)
|
|
{
|
|
textMesh.color = newColor;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
LocalizationManager.LanguageChanged += OnLanguageChanged;
|
|
}
|
|
|
|
private void OnLanguageChanged()
|
|
{
|
|
if (!string.IsNullOrEmpty(sourceText))
|
|
UpdateDisplayText();
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
LocalizationManager.LanguageChanged -= OnLanguageChanged;
|
|
}
|
|
}
|
|
|
|
public enum LookAtState
|
|
{
|
|
//看向目标
|
|
LookAt,
|
|
|
|
//看向目标 同时保持X轴
|
|
LookAtKeepX,
|
|
}
|