版权声明:本博客一本正经胡说八道,文章内容仅供参考。本文为博主原创文章,未经博主允许不得转载。该博客所用图片资源均作学习分享用途,仅供参考,请勿用于商业行为。传播者自负。 如果本博客所写文章侵犯到您的权益,请主动联系留言,我们将及时删除相关内容。 https://blog.csdn.net/BuladeMian/article/details/85068367
鼠标悬浮 3D 物体,显示 3D物体 的提示框,并本地化文本。
遇到 鼠标悬浮 3D 物体 无响应,基本 是相关文章1,2的解决办法。把影响遮挡 的物体 移走就行。
本地化 使用的是 相关文章4里面的 Simple Language Localization,里面的 使用手册 简单易用,非常棒。
Tooltip_3DGO.cs
/// <summary>
/// 当鼠标 移动到 3D 物体的时候,显示 提示内容。_TooltipManage
/// </summary>
public class Tooltip_3DGO : MonoBehaviour
{
[SerializeField]
/// <summary>
/// LocalizationManager//LangFile文件对应的Key
/// </summary>
private string key;
void OnMouseEnter()
{
Vector3 pos = Input.mousePosition;
Debug.Log("Hello///" + key);
if (key != null)
{
_TooltipManage.instance.ToolTipUI3DGO(key, true, pos);
}
}
void OnMouseExit()
{
Vector3 pos = Input.mousePosition;
Debug.Log("Bye///"+key);
_TooltipManage.instance.ToolTipUI3DGO(null, false, pos);
}
}
_TooltipManage.cs
using UnityEngine;
public class _TooltipManage : MonoBehaviour {
#region Singleton
public static _TooltipManage instance;
private void Awake()
{
instance = this;
}
#endregion
#region Tooltip_3DGO
[SerializeField]
/// <summary>
///
///
/// </summary>
private TooltipUI_3DGO UItrans_3DGO;
/// <summary>
///
/// </summary>
/// <param name="key"></param>
public void ToolTipUI3DGO(string key,bool isShow,Vector3 vector3)
{
if(UItrans_3DGO != null
&& isShow == true)
{
UItrans_3DGO.showUI(key, vector3);
}
if (UItrans_3DGO != null
&& isShow == false)
{
UItrans_3DGO.hideUI();
}
}
#endregion
}
TooltipUI_3DGO.cs
using UnityEngine;
using UnityEngine.UI;
public class TooltipUI_3DGO : MonoBehaviour {
[SerializeField]
/// <summary>
///
/// </summary>
private Transform UI_Plane;
[SerializeField]
/// <summary>
/// 显示 LangFile 对应 Key 的 对应 Word
/// </summary>
private Transform UI_Text;
/// <summary>
/// 当鼠标 悬浮 3D物体 显示 对应的指示框。
/// </summary>
public void showUI(string key_str,Vector3 vector3)
{
if (UI_Plane != null)
{
UI_Plane.localScale = new Vector3(1,1,1);
if (UI_Text != null)
{
string lan = GameSetting.instance.language.ToString();
string word_str = LocalizationManager.instance.GetWord(lan, key_str);
UI_Text.GetComponent<Text>().text = word_str;
UI_Plane.position = vector3;
}
}
}
/// <summary>
/// 当鼠标 悬浮 离开 3D物体 隐藏 对应的指示框。
/// </summary>
public void hideUI()
{
if (UI_Plane != null)
{
UI_Plane.localScale = new Vector3(0,0,0);
}
}
}
相关文章:
1.unity3d中OnMouseEnter事件没有反应的解决办法
2.Unity 被遮挡Collider如何触发OnMouseEnter事件
3.
[Unity][射线检测]3DCube方块最简单的射线检测OnMouseEnter
4.[Unity插件]Localization本地化多语言翻译插件
5.