lcy
2025-12-03 b9a6e7e896b451e9c915e782a1789b2afe079cc9
Main/System/Chat/ChatBubbleBehaviour.cs
@@ -1,8 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
    [DisallowMultipleComponent]
    [RequireComponent(typeof(RectTransform))]
    [ExecuteAlways]
@@ -10,15 +9,10 @@
    {
        [SerializeField] Text m_Target;
        [SerializeField] RectOffset m_Padding;
        [SerializeField] FlipImage m_Flip;
        [SerializeField] Image m_BubbleIcon;
    [SerializeField] ImageEx m_BubbleIcon;
    [SerializeField] UIFrame m_UIFrame;
        [SerializeField] bool left = false;
        [SerializeField] bool m_PreferredWidth = false;
        [SerializeField] RectTransform m_ContainerVoice;
        const float space = 5.0f;
        private int bubbleId = 0;
        RectTransform m_Rect;
        RectTransform rect
@@ -51,25 +45,13 @@
            }
            left = _left;
            m_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;
                    m_PreferredWidth = false;
                }
                else
                {
                    m_Target.alignment = TextAnchor.UpperRight;
                }
            }
            if (richText != null)
            {
                richText.AutoNewLine = true;
@@ -77,12 +59,10 @@
            Refresh();
        }
        public void DisplayBubble(int id)
    public void DisplaySysBubble(int id, Color color)
        {
            bubbleId = id;
            ChatBubbleManager.ChatBubble bubble;
            if (ChatBubbleManager.Instance.TryGetBubble(id, out bubble))
        ChatBubbleData bubble;
        if (ChatManager.Instance.TryGetBubble(id, out bubble))
            {
                var bubblePadding = left ? bubble.leftPadding : bubble.rifhtPadding;
                padding.top = bubblePadding.top;
@@ -90,33 +70,49 @@
                padding.right = bubblePadding.right;
                padding.bottom = bubblePadding.bottom;
                bool requireFlip = false;
                var iconKey = bubble.GetBubbleIcon(left, ref requireFlip);
                
                //m_BubbleIcon.SetSprite(iconKey);
            int resourceType = PhantasmPavilionManager.Instance.GetResourceType(PhantasmPavilionType.ChatBox, id);
            string resourceValue = PhantasmPavilionManager.Instance.GetResourceValue(PhantasmPavilionType.ChatBox, id);
            PhantasmPavilionManager.Instance.ShowChatBox(m_BubbleIcon, m_UIFrame, resourceType, resourceValue);
            m_Target.color = color;
                UIFrame frame = m_BubbleIcon.GetComponent<UIFrame>();
                if (UIFrameMgr.Inst.ContainsDynamicImage(iconKey))
            var position = rect.anchoredPosition;
            if (rect.anchoredPosition != position)
                {
                    if (frame == null)
                        frame = m_BubbleIcon.gameObject.AddComponent<UIFrame>();
                    frame.ResetFrame(iconKey);
                    frame.enabled = true;
                rect.anchoredPosition = position;
            }
            Refresh();
        }
    }
    public void DisplayBubble(int id, int playerId)
    {
        ChatBubbleData bubble;
        if (ChatManager.Instance.TryGetBubble(id, out bubble))
        {
            var bubblePadding = left ? bubble.leftPadding : bubble.rifhtPadding;
            padding.top = bubblePadding.top;
            padding.left = bubblePadding.left;
            padding.right = bubblePadding.right;
            padding.bottom = bubblePadding.bottom;
            int resourceType = PhantasmPavilionManager.Instance.GetResourceType(PhantasmPavilionType.ChatBox, id);
            string resourceValue = PhantasmPavilionManager.Instance.GetResourceValue(PhantasmPavilionType.ChatBox, id);
            PhantasmPavilionManager.Instance.ShowChatBox(m_BubbleIcon, m_UIFrame, resourceType, resourceValue);
            if (playerId == PlayerDatas.Instance.PlayerId)
            {
                m_Target.color = bubble.myColor;
                }
                else
                {
                    if (frame != null)
                        frame.enabled = false;
                    m_BubbleIcon.SetSprite(iconKey);
                m_Target.color = bubble.otherColor;
                }
                m_Flip.flipHorizontal = requireFlip;
                m_Target.color = bubble.color;
                var position = rect.anchoredPosition;
                // TODO YYL
                // ChatBubbleBoxConfig config = ChatBubbleBoxConfig.Get(bubbleId);
                // position.y = -config.top;
            position.y = -bubble.top;
                if (rect.anchoredPosition != position)
                {
                    rect.anchoredPosition = position;
@@ -154,16 +150,6 @@
                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 = height + m_Padding.top + m_Padding.bottom;
            if (sizeDelta != rect.sizeDelta)
@@ -172,24 +158,11 @@
            }
            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)
            {
@@ -244,14 +217,7 @@
            {
                height = 0f;
            }
            if (m_ContainerVoice != null)
            {
                height += m_ContainerVoice.sizeDelta.y;
                if (!nullContent)
                {
                    height += space;
                }
            }
        //Debug.Log($"GetBubbleHeight {height + padding.top + padding.bottom} height {height} padding.top {padding.top} padding.bottom {padding.bottom}");
            return height + padding.top + padding.bottom;
        }
    }