From 3be2da602fb3c0d3f29889d27ab670a159f9f11b Mon Sep 17 00:00:00 2001
From: client_linchunjie <461730578@qq.com>
Date: 星期二, 06 十一月 2018 10:16:48 +0800
Subject: [PATCH] 4398 【1.2】聊天气泡框

---
 System/Chat/ChatBubbleBehaviour.cs |   80 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 70 insertions(+), 10 deletions(-)

diff --git a/System/Chat/ChatBubbleBehaviour.cs b/System/Chat/ChatBubbleBehaviour.cs
index 6e0e389..1d5f905 100644
--- a/System/Chat/ChatBubbleBehaviour.cs
+++ b/System/Chat/ChatBubbleBehaviour.cs
@@ -16,6 +16,9 @@
         [SerializeField] Image m_BubbleIcon;
         [SerializeField] bool left = false;
         [SerializeField] bool m_PreferredWidth = false;
+        [SerializeField] RectTransform m_ContainerVoice;
+
+        const float space = 5.0f;
 
         private int bubbleId = 0;
 
@@ -112,16 +115,67 @@
             {
                 return;
             }
+            bool nullContent = string.IsNullOrEmpty(m_Target.text);
+
             var targetRect = m_Target.rectTransform;
             var sizeDelta = targetRect.sizeDelta;
+
             var width = m_PreferredWidth || !Application.isPlaying ? m_Target.preferredWidth : sizeDelta.x;
+            if (nullContent)
+            {
+                width = 0f;
+            }
+            var height = sizeDelta.y;
+            if (nullContent)
+            {
+                height = 0;
+            }
+
+            if (m_ContainerVoice != null)
+            {
+                width = Mathf.Max(m_ContainerVoice.sizeDelta.x, width);
+                height += m_ContainerVoice.sizeDelta.y;
+                if (!nullContent)
+                {
+                    height += space;
+                }
+            }
+
             sizeDelta.x = width + m_Padding.left + m_Padding.right;
-            sizeDelta.y = sizeDelta.y + m_Padding.top + m_Padding.bottom;
+            sizeDelta.y = height + m_Padding.top + m_Padding.bottom;
             if (sizeDelta != rect.sizeDelta)
             {
                 rect.sizeDelta = sizeDelta;
             }
 
+            SetAnchor(m_Target.rectTransform);
+            if (m_ContainerVoice != null)
+            {
+                SetAnchor(m_ContainerVoice);
+            }
+
+            float top = padding.top;
+            Vector2 position = Vector2.zero;
+            position.x = left ? padding.left : -padding.right;
+            if (m_ContainerVoice != null)
+            {
+                position.y = -top;
+                if (m_ContainerVoice.anchoredPosition != position)
+                {
+                    m_ContainerVoice.anchoredPosition = position;
+                }
+                top = top + m_ContainerVoice.sizeDelta.y;
+                top += space;
+            }
+            position.y = -top;
+            if (targetRect.anchoredPosition != position)
+            {
+                targetRect.anchoredPosition = position;
+            }
+        }
+
+        void SetAnchor(RectTransform targetRect)
+        {
             if (!left)
             {
                 if (targetRect.anchorMin != Vector2.one)
@@ -152,14 +206,6 @@
                     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)
@@ -169,7 +215,21 @@
                 (m_Target as RichText).SetExtenalData(list);
             }
             m_Target.text = content;
-            return m_Target.preferredHeight + padding.top + padding.bottom;
+            var height = m_Target.preferredHeight;
+            bool nullContent = string.IsNullOrEmpty(content);
+            if (nullContent)
+            {
+                height = 0f;
+            }
+            if (m_ContainerVoice != null)
+            {
+                height += m_ContainerVoice.sizeDelta.y;
+                if (!nullContent)
+                {
+                    height += space;
+                }
+            }
+            return height + padding.top + padding.bottom;
         }
     }
 }

--
Gitblit v1.8.0