| System/Chat/ChatBubbleBehaviour.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| System/Chat/ChatBubbleBehaviour.cs.meta | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| System/Chat/ChatContentBehaviour.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| System/Chat/ChatMineVoiceCell.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| System/Chat/ChatOtherVoiceCell.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| System/Chat/ChatPlayerMineCell.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| System/Chat/ChatPlayerOtherCell.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
System/Chat/ChatBubbleBehaviour.cs
New file @@ -0,0 +1,150 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { [DisallowMultipleComponent] [RequireComponent(typeof(RectTransform))] [ExecuteInEditMode] public class ChatBubbleBehaviour : MonoBehaviour { [SerializeField] Text m_Target; [SerializeField] RectOffset m_Padding; [SerializeField] bool left = false; RectTransform m_Rect; RectTransform rect { get { if (m_Rect == null) { m_Rect = transform as RectTransform; } return m_Rect; } } public RectOffset padding { get { return m_Padding; } } private bool preferredWidth = false; private void OnEnable() { Refresh(); } public void DisplayContent(string content, bool _left = false) { if (m_Target == null) { return; } left = _left; preferredWidth = true; var targetRect = m_Target.rectTransform; var richText = m_Target as RichText; if (richText != null && !left) { richText.AutoNewLine = false; } m_Target.text = content; if (!left) { if (m_Target.preferredWidth > targetRect.rect.width) { m_Target.alignment = TextAnchor.UpperLeft; preferredWidth = false; } else { m_Target.alignment = TextAnchor.UpperRight; } } if (richText != null) { richText.AutoNewLine = true; } Refresh(); } [ExecuteInEditMode] private void LateUpdate() { Refresh(); } void Refresh() { if (m_Target == null) { return; } var targetRect = m_Target.rectTransform; var sizeDelta = targetRect.sizeDelta; var width = preferredWidth || !Application.isPlaying ? m_Target.preferredWidth : sizeDelta.x; sizeDelta.x = width + m_Padding.left + m_Padding.right; sizeDelta.y = sizeDelta.y + m_Padding.top + m_Padding.bottom; if (sizeDelta != rect.sizeDelta) { rect.sizeDelta = sizeDelta; } if (!left) { if (targetRect.anchorMin != Vector2.one) { targetRect.anchorMin = Vector2.one; } if (targetRect.anchorMax != Vector2.one) { targetRect.anchorMax = Vector2.one; } if (targetRect.pivot != Vector2.one) { targetRect.pivot = Vector2.one; } } else { if (targetRect.anchorMin != Vector2.up) { targetRect.anchorMin = Vector2.up; } if (targetRect.anchorMax != Vector2.up) { targetRect.anchorMax = Vector2.up; } if (targetRect.pivot != Vector2.up) { targetRect.pivot = Vector2.up; } } var position = targetRect.anchoredPosition; position.x = left ? padding.left : -padding.right; position.y = -padding.top; if (targetRect.anchoredPosition != position) { targetRect.anchoredPosition = position; } } public float GetBubbleHeight(string content, ArrayList list) { if (m_Target is RichText) { (m_Target as RichText).SetExtenalData(list); } m_Target.text = content; return m_Target.preferredHeight + padding.top + padding.bottom; } } } System/Chat/ChatBubbleBehaviour.cs.meta
New file @@ -0,0 +1,12 @@ fileFormatVersion: 2 guid: 3c276a7c4ec66ff4aa7e131b74286d9a timeCreated: 1541123752 licenseType: Pro MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: System/Chat/ChatContentBehaviour.cs
@@ -4,13 +4,12 @@ using System.Text.RegularExpressions; using UnityEngine; using UnityEngine.UI; using EnhancedUI.EnhancedScroller; namespace Snxxz.UI { public class ChatContentBehaviour : MonoBehaviour { [SerializeField] ScrollerController m_ChatContentControl; [SerializeField] RichText m_DestText; [SerializeField] RichText m_DestSysText; [SerializeField] RichText m_DestTipText; [SerializeField] RectTransform m_ContaienrNewInfo; @@ -20,6 +19,12 @@ [SerializeField] Image m_LockAreaCheck; [SerializeField, Header("显示区域大小")] float m_ContentDisplaySize = 630; [SerializeField, Header("锁定当前区域比例"), Range(0, 1)] float m_Percent = 0.3f; [SerializeField] ChatPlayerMineCell m_ChatMineCell; [SerializeField] ChatPlayerOtherCell m_ChatOtherCell; [SerializeField] ChatMineVoiceCell m_ChatMineVoiceCell; [SerializeField] ChatOtherVoiceCell m_ChatOtherVoiceCell; private ChatInfoType m_ChatType = ChatInfoType.System; public ChatInfoType chatType { @@ -62,10 +67,6 @@ m_LockAreaBtn.onClick.AddListener(OnLockAreaBtn); m_ChatContentControl.mScrollRect.onValueChanged.AddListener(OnScrollValChange); if (m_DestText.font == null) { m_DestText.font = FontUtility.preferred; } if (m_DestSysText.font == null) { m_DestSysText.font = FontUtility.preferred; @@ -370,17 +371,21 @@ switch (_type) { case ScrollerDataType.Header: _height = m_ChatMineCell.GetHeight(chat.content, chat.infoList); return true; case ScrollerDataType.Normal: _height = 90; break; _height = m_ChatOtherCell.GetHeight(chat.content, chat.infoList); return true; case ScrollerDataType.Extra1: case ScrollerDataType.Tail: _height = 30; break; case ScrollerDataType.Extra2: _height = m_ChatMineVoiceCell.GetHeight(chat.content, chat.infoList); return true; case ScrollerDataType.Extra3: _height = chat.content.Equals(string.Empty) ? 80 : 110; break; _height = m_ChatOtherVoiceCell.GetHeight(chat.content, chat.infoList); return true; } OnGetChatDynamicHeight(chat.content, ref _height, _type, chat.infoList); return true; @@ -402,20 +407,6 @@ m_DestTipText.text = _content; _textHeight = Mathf.Max(m_DestTipText.preferredHeight, m_DestTipText.fontSize); _height += Mathf.Max(0, _textHeight - 23); } else if (_type == ScrollerDataType.Extra2 || _type == ScrollerDataType.Extra3) { m_DestText.SetExtenalData(_infoList); m_DestText.text = _content; _textHeight = Mathf.Max(m_DestText.preferredHeight, m_DestText.fontSize); _height += Mathf.Max(0, _textHeight - 8); } else { m_DestText.SetExtenalData(_infoList); m_DestText.text = _content; _textHeight = Mathf.Max(m_DestText.preferredHeight, m_DestText.fontSize); _height += Mathf.Max(0, _textHeight - 30); } } System/Chat/ChatMineVoiceCell.cs
@@ -8,15 +8,14 @@ { public class ChatMineVoiceCell : ScrollerUI { [SerializeField] Text m_VoiceTxt; [SerializeField] Button m_VoiceBtn; [SerializeField] RichText m_ChatTxt; [SerializeField] Image m_ChatBubble; [SerializeField] Text vipText; [SerializeField] Text playerNameText; [SerializeField] Text m_VoiceTimes; [SerializeField] Button m_Voice; [SerializeField] ChatBubbleBehaviour m_ChatBubble; [SerializeField] Text m_VipLevel; [SerializeField] Text m_PlayerName; [SerializeField] Text m_ChatTime; [SerializeField] Image m_ChatIcon; [SerializeField] ImageFitterText m_Fitter; [SerializeField] float spacing = 15.0f; ChatCenter m_ChatCenter; ChatCenter chatCenter @@ -33,36 +32,23 @@ { return; } #region 更新高度 m_ChatTxt.AutoNewLine = false; m_ChatTxt.text = _data.content; if (m_ChatTxt.preferredWidth > m_ChatTxt.rectTransform.rect.width) { m_ChatTxt.alignment = TextAnchor.UpperLeft; } else { m_ChatTxt.alignment = TextAnchor.UpperRight; } m_Fitter.FiterRealTxtWidth = m_ChatTxt.alignment == TextAnchor.UpperRight; m_Fitter.gameObject.SetActive(!string.IsNullOrEmpty(_data.content)); m_ChatTxt.AutoNewLine = true; #endregion m_ChatBubble.DisplayContent(_data.content); m_ChatBubble.gameObject.SetActive(!string.IsNullOrEmpty(_data.content)); m_ChatIcon.SetSprite(GeneralDefine.GetJobHeadPortrait(_data.job, 0)); playerNameText.text = _data.name; m_PlayerName.text = _data.name; m_ChatTime.text = _data.createTime.ToString("yyyy-MM-dd HH:mm"); if (_data.vipLv > 0) { vipText.text = string.Format("V{0}", _data.vipLv); m_VipLevel.text = string.Format("V{0}", _data.vipLv); } else { vipText.text = string.Empty; m_VipLevel.text = string.Empty; } m_VoiceBtn.onClick.RemoveAllListeners(); m_VoiceTxt.text = _data.soundLength.ToString("0.0"); m_VoiceBtn.onClick.AddListener(() => m_Voice.onClick.RemoveAllListeners(); m_VoiceTimes.text = _data.soundLength.ToString("0.0"); m_Voice.onClick.AddListener(() => { OnVoiceClick(_data, Mathf.Min(8.0f, _data.soundLength)); }); @@ -75,6 +61,17 @@ chatCenter.PlaySpeech(_chat.player, _chat.soundTick, _length); } } public float GetHeight(string content, ArrayList list) { var minHeight = m_ChatIcon.rectTransform.sizeDelta.y; var chatHeight = m_ChatBubble.GetBubbleHeight(content, list) + Mathf.Abs(m_ChatBubble.transform.localPosition.y); if (string.IsNullOrEmpty(content)) { chatHeight = 0; } return (chatHeight > minHeight ? chatHeight : minHeight) + spacing; } } } System/Chat/ChatOtherVoiceCell.cs
@@ -8,16 +8,15 @@ { public class ChatOtherVoiceCell : ScrollerUI { [SerializeField] Text m_VoiceTxt; [SerializeField] Button m_VoiceBtn; [SerializeField] RichText m_ChatTxt; [SerializeField] Image m_ChatBubble; [SerializeField] Text vipText; [SerializeField] Text playerNameText; [SerializeField] Text m_VoiceTimes; [SerializeField] Button m_Voice; [SerializeField] ChatBubbleBehaviour m_ChatBubble; [SerializeField] Text m_VipLevel; [SerializeField] Text m_PlayerName; [SerializeField] Text m_ChatTime; [SerializeField] Image m_ChatIcon; [SerializeField] ImageFitterText m_Fitter; [SerializeField] Button m_ViewPlayer; [SerializeField] Button m_Func; [SerializeField] float spacing = 15.0f; ChatCenter m_ChatCenter; ChatCenter chatCenter @@ -29,32 +28,32 @@ } public override void Refresh(CellView cell) { m_ViewPlayer.RemoveAllListeners(); m_Func.RemoveAllListeners(); ChatUeseData _data = chatCenter.GetChatData(ChatCtrl.Inst.presentChatType, cell.index) as ChatUeseData; if (_data == null) { return; } m_ViewPlayer.onClick.AddListener(() => m_Func.onClick.AddListener(() => { ViewPlayer(_data); }); m_ChatTxt.text = _data.content; m_Fitter.gameObject.SetActive(!string.IsNullOrEmpty(_data.content)); m_ChatBubble.DisplayContent(_data.content, true); m_ChatBubble.gameObject.SetActive(!string.IsNullOrEmpty(_data.content)); m_ChatIcon.SetSprite(GeneralDefine.GetJobHeadPortrait(_data.job, 0)); playerNameText.text = _data.name; m_PlayerName.text = _data.name; m_ChatTime.text = _data.createTime.ToString("yyyy-MM-dd HH:mm"); if (_data.vipLv > 0) { vipText.text = string.Format("V{0}", _data.vipLv); m_VipLevel.text = string.Format("V{0}", _data.vipLv); } else { vipText.text = string.Empty; m_VipLevel.text = string.Empty; } m_VoiceBtn.onClick.RemoveAllListeners(); m_VoiceTxt.text = _data.soundLength.ToString("0.0"); m_VoiceBtn.onClick.AddListener(() => m_Voice.onClick.RemoveAllListeners(); m_VoiceTimes.text = _data.soundLength.ToString("0.0"); m_Voice.onClick.AddListener(() => { OnVoiceClick(_data, Mathf.Min(8.0f, _data.soundLength)); }); @@ -77,6 +76,17 @@ } HrefAnalysis.Inst.ExcuteHrefEvent(string.Format("showplayer={0}", user.player)); } public float GetHeight(string content, ArrayList list) { var minHeight = m_ChatIcon.rectTransform.sizeDelta.y; var chatHeight = m_ChatBubble.GetBubbleHeight(content, list) + Mathf.Abs(m_ChatBubble.transform.localPosition.y); if (string.IsNullOrEmpty(content)) { chatHeight = 0; } return (chatHeight > minHeight ? chatHeight : minHeight) + spacing; } } } System/Chat/ChatPlayerMineCell.cs
@@ -11,9 +11,9 @@ [SerializeField] Text m_VipLv; [SerializeField] Text m_PlayerName; [SerializeField] Text m_ChatTime; [SerializeField] RichText m_Chat; [SerializeField] ImageFitterText m_Fitter; [SerializeField] ChatBubbleBehaviour m_ChatBubble; [SerializeField] Button m_Func; [SerializeField] float spacing = 5.0f; ChatCenter m_ChatCenter; ChatCenter chatCenter @@ -32,24 +32,8 @@ } var chatUserData = data as ChatUeseData; #region 更新高度 m_Chat.AutoNewLine = false; m_Chat.text = data.content; if (type == ScrollerDataType.Header) { if (m_Chat.preferredWidth > m_Chat.rectTransform.rect.width) { m_Chat.alignment = TextAnchor.UpperLeft; } else { m_Chat.alignment = TextAnchor.UpperRight; } m_Fitter.FiterRealTxtWidth = m_Chat.alignment == TextAnchor.UpperRight; } m_Chat.AutoNewLine = true; m_ChatBubble.DisplayContent(data.content); m_ChatIcon.SetSprite(GeneralDefine.GetJobHeadPortrait(chatUserData.job, 0)); #endregion m_Func.onClick.RemoveAllListeners(); m_Func.onClick.AddListener(() => @@ -83,6 +67,13 @@ } HrefAnalysis.Inst.ExcuteHrefEvent(string.Format("showplayer={0}", user.player)); } public float GetHeight(string content, ArrayList list) { var minHeight = m_ChatIcon.rectTransform.sizeDelta.y; var chatHeight = m_ChatBubble.GetBubbleHeight(content, list) + Mathf.Abs(m_ChatBubble.transform.localPosition.y); return (chatHeight > minHeight ? chatHeight : minHeight) + spacing; } } } System/Chat/ChatPlayerOtherCell.cs
@@ -5,81 +5,75 @@ using UnityEngine.UI; using System; using Snxxz.UI; public class ChatPlayerOtherCell : ScrollerUI { [SerializeField] Image m_ChatIcon; [SerializeField] Text m_VipLv; [SerializeField] Text m_PlayerName; [SerializeField] Text m_ChatTime; [SerializeField] RectTransform m_Bottom; [SerializeField] RichText m_Chat; [SerializeField] Button m_Func; ChatCenter m_ChatCenter; ChatCenter chatCenter { get { return m_ChatCenter ?? (m_ChatCenter = ModelCenter.Instance.GetModel<ChatCenter>()); } } public override void Refresh(CellView cell) { var data = chatCenter.GetChatData(ChatCtrl.Inst.presentChatType, cell.index); if (data == null) { return; } #region 更新高度 if (type == ScrollerDataType.Header) { if (m_Chat.preferredWidth > m_Chat.rectTransform.rect.width) { m_Chat.alignment = TextAnchor.UpperLeft; } else { m_Chat.alignment = TextAnchor.UpperRight; } } #endregion var chatUserData = data as ChatUeseData; m_Func.onClick.RemoveAllListeners(); m_Func.onClick.AddListener(() => { OnFunc(cell); }); m_ChatIcon.SetSprite(GeneralDefine.GetJobHeadPortrait(chatUserData.job, 0)); m_PlayerName.text = chatUserData.name; m_ChatTime.text = data.createTime.ToString("yyyy-MM-dd HH:mm"); if (chatUserData.vipLv > 0) { m_VipLv.text = string.Format("V{0}", chatUserData.vipLv); } else { m_VipLv.text = string.Empty; } m_Chat.AutoNewLine = true; m_Chat.text = data.content; } private void OnFunc(CellView cell) { int index = cell.index; ChatData _data = chatCenter.GetChatData(ChatCtrl.Inst.presentChatType, index); if (_data == null) { return; } ChatUeseData user = _data as ChatUeseData; if (user.player == PlayerDatas.Instance.baseData.PlayerID) namespace EnhancedUI.EnhancedScroller { public class ChatPlayerOtherCell : ScrollerUI { [SerializeField] Image m_ChatIcon; [SerializeField] Text m_VipLv; [SerializeField] Text m_PlayerName; [SerializeField] Text m_ChatTime; [SerializeField] ChatBubbleBehaviour m_ChatBubble; [SerializeField] Button m_Func; [SerializeField] float spacing = 5.0f; ChatCenter m_ChatCenter; ChatCenter chatCenter { return; } HrefAnalysis.Inst.ExcuteHrefEvent(string.Format("showplayer={0}", user.player)); } get { return m_ChatCenter ?? (m_ChatCenter = ModelCenter.Instance.GetModel<ChatCenter>()); } } public override void Refresh(CellView cell) { var data = chatCenter.GetChatData(ChatCtrl.Inst.presentChatType, cell.index); if (data == null) { return; } var chatUserData = data as ChatUeseData; m_Func.onClick.RemoveAllListeners(); m_Func.onClick.AddListener(() => { OnFunc(cell); }); m_ChatIcon.SetSprite(GeneralDefine.GetJobHeadPortrait(chatUserData.job, 0)); m_PlayerName.text = chatUserData.name; m_ChatTime.text = data.createTime.ToString("yyyy-MM-dd HH:mm"); if (chatUserData.vipLv > 0) { m_VipLv.text = string.Format("V{0}", chatUserData.vipLv); } else { m_VipLv.text = string.Empty; } m_ChatBubble.DisplayContent(data.content, true); } private void OnFunc(CellView cell) { int index = cell.index; ChatData _data = chatCenter.GetChatData(ChatCtrl.Inst.presentChatType, index); if (_data == null) { return; } ChatUeseData user = _data as ChatUeseData; if (user.player == PlayerDatas.Instance.baseData.PlayerID) { return; } HrefAnalysis.Inst.ExcuteHrefEvent(string.Format("showplayer={0}", user.player)); } public float GetHeight(string content, ArrayList list) { var minHeight = m_ChatIcon.rectTransform.sizeDelta.y; var chatHeight = m_ChatBubble.GetBubbleHeight(content, list) + Mathf.Abs(m_ChatBubble.transform.localPosition.y); return (chatHeight > minHeight ? chatHeight : minHeight) + spacing; } } }