Files
JJBB/Assets/Project/Script/GUI/Chat/ChatBubbleLogic.cs
2024-08-23 15:49:34 +08:00

88 lines
2.3 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Games.ChatHistory;
using GCGame;
using GCGame.Table;
using System;
using Games.GlobeDefine;
public class ChatBubbleLogic : UIControllerBase<ChatBubbleLogic>
{
public ChatInfoLogItem _ChatLogItem;
public LayoutElement m_Layout;
private ChatHistoryItem m_CurrShowChatHistory = null;
private float m_HideTime = 0;
public void Show(ChatHistoryItem history)
{
if (gameObject.activeSelf)
{
ClearBubble();
}
if (!gameObject.activeSelf)
{
gameObject.SetActive(true);
}
if(!gameObject.activeInHierarchy)
{
m_HideTime = Time.realtimeSinceStartup + (history.Duration > 0 ? history.Duration : 5);
m_CurrShowChatHistory = history;
return;
}
m_CurrShowChatHistory = null;
m_HideTime = 0;
if (_ChatLogItem.SetChatLog(history)==false)
{
ClearBubble();
gameObject.SetActive(false);
return;
}
//string dialogStr = _ChatLogItem._ChatInfo.text;
//int strLen = System.Text.Encoding.Default.GetBytes(dialogStr).Length;
//if (strLen % 2 != 0)
// strLen += 1;
//if(m_Layout != null)
//{
//m_Layout.preferredWidth = strLen * _ChatLogItem._ChatInfo.fontSize / 2 + _ChatLogItem._ChatInfo.fontSize;
//if (m_Layout.preferredWidth > 460)
// m_Layout.preferredWidth = 460;
//}
m_HideTime = Time.realtimeSinceStartup + (history.Duration > 0 ? history.Duration : 5);
m_CurrShowChatHistory = history;
}
void OnEnable()
{
if(m_HideTime>Time.realtimeSinceStartup && m_CurrShowChatHistory!=null)
{
Show(m_CurrShowChatHistory);
}
}
//修改像宠物冒泡等在显示时间没到时被隐藏里面又出现的情况 导致显示不正确的问题
void Update()
{
if (m_CurrShowChatHistory == null || m_HideTime <= 0)
return;
if (Time.realtimeSinceStartup - m_HideTime >= 0)
{
m_CurrShowChatHistory = null;
m_HideTime = 0;
ClearBubble();
gameObject.SetActive(false);
}
}
void ClearBubble()
{
_ChatLogItem.ClearChat();
}
}