- Text3DCtrl: SetName使用LocalizationManager.Get翻译,订阅LanguageChanged - StudentSub2EditorPanel: 未规划车辆提示中车辆名称用Get翻译+去除括号后缀
85 lines
2.0 KiB
C#
85 lines
2.0 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;
|
|
|
|
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;
|
|
textMesh.text = LocalizationManager.Get(text);
|
|
}
|
|
|
|
//选选取的时候 改变文字颜色
|
|
public void ChangeTextColor(Color newColor)
|
|
{
|
|
textMesh.color = newColor;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
LocalizationManager.LanguageChanged += OnLanguageChanged;
|
|
}
|
|
|
|
private void OnLanguageChanged()
|
|
{
|
|
if (!string.IsNullOrEmpty(sourceText))
|
|
textMesh.text = LocalizationManager.Get(sourceText);
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
LocalizationManager.LanguageChanged -= OnLanguageChanged;
|
|
}
|
|
}
|
|
|
|
public enum LookAtState
|
|
{
|
|
//看向目标
|
|
LookAt,
|
|
|
|
//看向目标 同时保持X轴
|
|
LookAtKeepX,
|
|
}
|