57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using GCGame.Table;
|
|||
|
using Games.LogicObj;
|
|||
|
|
|||
|
public class DialogTipUI : MonoBehaviour {
|
|||
|
|
|||
|
|
|||
|
public Text m_DialogText;
|
|||
|
public LayoutElement m_Layout;
|
|||
|
public RectTransform m_Rect;
|
|||
|
|
|||
|
private float CloseTimes = 0;
|
|||
|
public int ServerId = -1;
|
|||
|
|
|||
|
public void ShowDialog(int ServerID,float showTime, string dialog)
|
|||
|
{
|
|||
|
int strLen = System.Text.Encoding.Default.GetBytes(dialog).Length;
|
|||
|
if (strLen % 2 != 0)
|
|||
|
strLen += 1;
|
|||
|
m_Layout.preferredWidth = (strLen+1) * m_DialogText.fontSize / 2;
|
|||
|
if (m_Layout.preferredWidth > 460)
|
|||
|
m_Layout.preferredWidth = 460;
|
|||
|
m_DialogText.text = dialog;
|
|||
|
CloseTimes = Time.realtimeSinceStartup + showTime;
|
|||
|
ServerId = ServerID;
|
|||
|
}
|
|||
|
|
|||
|
void LateUpdate()
|
|||
|
{
|
|||
|
if(ServerId==-1)
|
|||
|
{
|
|||
|
GameManager.gameManager.ActiveScene.DialogTipUIRoot.RemoveDiaLog(this);
|
|||
|
return;
|
|||
|
}
|
|||
|
Obj_Character obj = Singleton<ObjManager>.Instance.FindObjCharacterInScene(ServerId);
|
|||
|
if(obj==null)
|
|||
|
{
|
|||
|
GameManager.gameManager.ActiveScene.DialogTipUIRoot.RemoveDiaLog(this);
|
|||
|
return;
|
|||
|
}
|
|||
|
if(Time.realtimeSinceStartup>CloseTimes)
|
|||
|
{
|
|||
|
GameManager.gameManager.ActiveScene.DialogTipUIRoot.RemoveDiaLog(this);
|
|||
|
return;
|
|||
|
}
|
|||
|
if (UIManager.Instance() != null)
|
|||
|
{
|
|||
|
Vector3 pos = new Vector3(0, 2, 0) + obj.Position;
|
|||
|
var screenPoint = UIManager.Instance().WorldToUiPoint(pos);
|
|||
|
m_Rect.anchoredPosition = screenPoint;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|