Beispiel #1
0
    private void CacheChatItemObjs()
    {
        Log.LogGroup(GameDefine.LogGroup.User_ZCX, "CacheObjs: " + m_trans_chatroot.childCount);

        int childNum = m_trans_chatroot.childCount;

        while (childNum > 0)
        {
            SingleChatItem item = m_trans_chatroot.GetChild(0).GetComponent <SingleChatItem>();
            if (item != null)
            {
                m_lstChatItem.Add(item);
                item.Clear();
                item.transform.parent = transform;
                item.gameObject.SetActive(false);
                item.name = "cacheItem" + childNum.ToString();

                //Log.LogGroup(GameDefine.LogGroup.User_ZCX, "CacheObjs: " + item.name);
            }
            else
            {
                //查找好友的对象列表
                Transform t = m_trans_chatroot.GetChild(0);
                t.parent = transform;
                GameObject.Destroy(t.gameObject);
            }
            childNum = m_trans_chatroot.childCount;
        }
    }
Beispiel #2
0
    private void CacheChat()
    {
        InitPrefab();
        m_fTotalHeight = 0;
        m_scrollview_ChatScrollView.ResetPosition();
        int childNum = m_trans_ChatItemRoot.childCount;

        while (childNum > 0)
        {
            SingleChatItem item = m_trans_ChatItemRoot.GetChild(0).GetComponent <SingleChatItem>();
            if (item != null)
            {
                m_lstChatItem.Add(item);
                item.Clear();
                item.transform.parent = transform;
                item.gameObject.SetActive(false);
                item.name = "cacheItem" + childNum.ToString();

                //Log.LogGroup(GameDefine.LogGroup.User_ZCX, "CacheObjs: " + item.name);
            }
            else
            {
                //查找好友的对象列表
                Transform t = m_trans_ChatItemRoot.GetChild(0);
                t.parent = transform;
                GameObject.Destroy(t.gameObject);
            }
            childNum = m_trans_ChatItemRoot.childCount;
        }
    }
Beispiel #3
0
    private void OnAddText(IEnumerable <ChatInfo> textList)
    {
        var list = textList.TakeLast(MaxChatNum).ToList();

        Engine.Utility.Log.LogGroup("ZCX", "OnAddText : " + list.Count);

        if (list.Count <= 0)
        {
            return;
        }

        if (m_chatPanel == null)
        {
            //Engine.Utility.Log.Error("m_chatPanel为空!!!");
            return;
        }

        Vector3[] corners = m_chatPanel.worldCorners;

        for (int i = 0; i < 4; ++i)
        {
            Vector3 v = corners[i];
            v          = m_trans_chatroot.InverseTransformPoint(v);
            corners[i] = v;
        }

        float          totalheight = 0;
        Vector3        center      = Vector3.Lerp(corners[0], corners[2], 0.5f);
        SingleChatItem chatitem    = null;

        foreach (var item in list)
        {
            AddTimeTips(item.Timestamp);
            chatitem = AddChatItem(item, ref m_lstChatItem, m_chatItemPrefab);
            if (chatitem != null)
            {
                float height = chatitem.GetHeight();
                m_fTotalHeight += chatitem.GetHeight();

                Transform t        = chatitem.transform;
                float     distance = t.localPosition.y - center.y;
                float     offsetY  = chatitem.GetOffsetY() - distance - m_chatPanel.baseClipRegion.w * 0.5f + m_chatPanel.clipSoftness.y;
                if (offsetY > 0)
                {
                    totalheight = offsetY;
                }
                m_lstCurrChannel.Add(chatitem);
            }
        }

        if (totalheight > 0)
        {
            m_chatScrollView.MoveRelative(new Vector3(0, totalheight, 0));
        }
    }
Beispiel #4
0
    SingleChatItem AddChatItem(ChatInfo text, ref List <SingleChatItem> list, GameObject prefab)
    {
        SingleChatItem chatitem = GetChatItem(ref list, prefab);
        Transform      t        = chatitem.transform;

        t.parent        = m_trans_ChatItemRoot;
        t.localPosition = new Vector3(0, -m_fTotalHeight + 5f, 0);
        t.localScale    = Vector3.one;
        t.localRotation = Quaternion.identity;

        chatitem.SetChatInfo(Mathf.CeilToInt(m_chatPanel.baseClipRegion.z), text);
        return(chatitem);
    }
Beispiel #5
0
    SingleChatItem GetChatItem(ref List <SingleChatItem> list, GameObject prefab)
    {
        SingleChatItem chatItem = null;

        if (list.Count > 0)
        {
            chatItem = list[0];
            list.RemoveAt(0);
        }
        else
        {
            GameObject obj = GameObject.Instantiate(prefab) as GameObject;
            chatItem = obj.AddComponent <SingleChatItem>();
        }
        chatItem.gameObject.SetActive(true);
        return(chatItem);
    }
Beispiel #6
0
    bool CheckCanUpdateMsg(SingleChatItem chatitem, float centerY)
    {
        if (chatitem == null)
        {
            return(true);
        }

        float height = chatitem.GetHeight();

        Transform t        = chatitem.transform;
        float     distance = t.localPosition.y - centerY;
        float     offsetY  = chatitem.GetOffsetY() - distance - m_chatPanel.baseClipRegion.w * 0.5f + m_chatPanel.clipSoftness.y;

        if (offsetY > height * 0.5f)//如果在panel外不能移动
        {
            return(false);
        }
        return(true);
    }
Beispiel #7
0
    /// <summary>
    /// 新添加
    /// </summary>
    /// <param name="textList"></param>
    private void OnAddText(IEnumerable <ChatInfo> textList)
    {
        if (!gameObject.activeSelf)
        {
            m_lsttextList.AddRange(textList);
            return;
        }
        var list = textList.TakeLast(MaxChatNum).ToList();

        foreach (var item in list)
        {
            if (item.IsRedPacket)
            {//红包不显示
                continue;
            }
            UIXmlRichText xmlText;
            if (!RemoveOverfloorChat(out xmlText))
            {
                GameObject go = GameObject.Instantiate(m_chatItemPrefab) as GameObject;
                xmlText = go.transform.Find("richtext").GetComponent <UIXmlRichText>();
                go.GetComponent <UIWidget>().width = (int)m_UIPanel.baseClipRegion.z - 10;
                xmlText.UrlClicked += OnClickUrl;
            }
            xmlText.fontSize = 20;
            Transform root = xmlText.transform.parent;
            root.gameObject.SetActive(true);
            xmlText.AddXml(item.Title + item.Content);
            xmlText.gameObject.SetActive(true);
            Transform t = xmlText.transform;
            root.parent        = m_trans_chatItemRoot;
            root.localPosition = Vector3.zero;
            root.localScale    = Vector3.one;
            root.localRotation = Quaternion.identity;

            UILabel[] uilabelArray = t.GetComponentsInChildren <UILabel>();
            if (uilabelArray.Length > 0)
            {
                UILabel lableTitle = uilabelArray[0];
                if (lableTitle != null)
                {
                    UISpriteEx spriteBg = root.transform.Find("titlebg").GetComponent <UISpriteEx>();

                    if (spriteBg != null)
                    {
                        spriteBg.ChangeSprite(SingleChatItem.GetChannelIndex(item.Channel));
                    }

                    // spriteBg.transform.parent = title;
                    spriteBg.pivot = lableTitle.pivot;
                    spriteBg.transform.localPosition = new Vector3(lableTitle.transform.localPosition.x - 3, lableTitle.transform.localPosition.y, 0);
                    spriteBg.height = lableTitle.height + 5;
                    spriteBg.width  = lableTitle.width + 3;
                }
            }

            float height = xmlText.GetTotalHeight() + 5;
            foreach (var moveItem in m_lstxmlText)
            {
                Vector3 pos = moveItem.transform.parent.localPosition;
                pos.y -= height;
                moveItem.transform.parent.localPosition = pos;

                xmlText.name = pos.y.ToString();
            }
            m_lstxmlText.Add(xmlText);
        }

        float offsetY = m_chatScrollview.panel.clipOffset.y + 1;

        if (offsetY < 0)
        {
            m_chatScrollview.MoveRelative(new Vector3(0, offsetY));//取反 往下相对移动
        }
    }
Beispiel #8
0
    /// <summary>
    /// 添加聊天信息
    /// </summary>
    /// <param name="textList"></param>
    private void OnAddText(IEnumerable <ChatInfo> textList)
    {
        var list = textList.TakeLast(MaxChatNum).ToList();
        //TODO 移除超出的聊天
        float totalheight = 0;

        Vector3[] corners = m_chatPanel.worldCorners;

        for (int i = 0; i < 4; ++i)
        {
            Vector3 v = corners[i];
            v          = m_trans_ChatItemRoot.InverseTransformPoint(v);
            corners[i] = v;
        }

        //         float extents = 0;
        int childNum = m_lstCurrChannel.Count;
        //         for (int i = 0; i < childNum; i++)
        //         {
        //             SingleChatItem item = m_lstCurrChannel[i];
        //             if (item != null)
        //             {
        //                 extents += item.GetHeight();
        //             }
        //         }
        //缓存最后一个 用于判断是否可以刷新
        SingleChatItem lastChatItem = null;

        if (childNum > 0)
        {
            lastChatItem = m_lstCurrChannel[childNum - 1];
        }
        //  extents *= 0.5f;

        Vector3 center = Vector3.Lerp(corners[0], corners[2], 0.5f);
        //bool allWithinRange = true;
        //float ext2 = extents * 2f;
        bool           flag     = false;
        SingleChatItem chatitem = null;

        for (int i = 0; i < list.Count; i++)
        {
            var item = list[i];
            chatitem = AddChatItem(item, ref m_lstChatItem, m_chatItemPrefab);

            if (chatitem != null)
            {
                m_fTotalHeight += chatitem.GetHeight();
                Engine.Utility.Log.LogGroup("ZCX", "m_fTotalHeight :{0}", m_fTotalHeight);
                Transform t        = chatitem.transform;
                float     distance = t.localPosition.y - center.y;
                float     offsetY  = chatitem.GetOffsetY() - distance - m_chatPanel.baseClipRegion.w * 0.5f + m_chatPanel.clipSoftness.y;
                if (offsetY > 0)
                {
                    totalheight = offsetY;
                }
                m_lstCurrChannel.Add(chatitem);
            }
        }

        if (totalheight > 0)
        {
            //可以立即刷新
            if (CheckCanUpdateMsg(lastChatItem, center.y))
            {
                Engine.Utility.Log.LogGroup("ZCX", "MoveRelative :{0}", totalheight);
                m_scrollview_ChatScrollView.MoveRelative(new Vector3(0, totalheight, 0));
            }
        }
        if (null != m_scrollview_ChatScrollView)
        {
            NGUITools.MarkParentAsChanged(m_scrollview_ChatScrollView.gameObject);
        }
    }
Beispiel #9
0
    /// <summary>
    /// 添加聊天信息
    /// </summary>
    /// <param name="textList"></param>
    private void OnAddText(IEnumerable <ChatInfo> textList)
    {
        var list = textList.TakeLast(MaxChatNum).ToList();

        //TODO 移除超出的聊天
        Log.LogGroup(GameDefine.LogGroup.User_ZCX, "TextList count " + list.Count);
        float totalheight = 0;

        Vector3[] corners = m_panel.worldCorners;

        for (int i = 0; i < 4; ++i)
        {
            Vector3 v = corners[i];
            v          = m_trans_ChatItemRoot.InverseTransformPoint(v);
            corners[i] = v;
        }

        //         float extents = 0;
        int childNum = m_lstCurrChannel.Count;
        //         for (int i = 0; i < childNum; i++)
        //         {
        //             SingleChatItem item = m_lstCurrChannel[i];
        //             if (item != null)
        //             {
        //                 extents += item.GetHeight();
        //             }
        //         }
        //缓存最后一个 用于判断是否可以刷新
        SingleChatItem lastChatItem = null;

        if (childNum > 0)
        {
            lastChatItem = m_lstCurrChannel[childNum - 1];
        }
        //  extents *= 0.5f;

        Vector3 center = Vector3.Lerp(corners[0], corners[2], 0.5f);
        //bool allWithinRange = true;
        //float ext2 = extents * 2f;
        bool           flag     = false;
        SingleChatItem chatitem = null;

        for (int i = 0; i < list.Count; i++)
        {
            var item = list[i];
            chatitem = AddChatItem(item, ref m_lstChatItem, m_chatItemPrefab);

            if (chatitem != null)
            {
                chatitem.m_parent = this;
                //float height = chatitem.GetHeight();
                m_fTotalHeight += chatitem.GetHeight();
                Engine.Utility.Log.LogGroup("ZCX", "m_fTotalHeight :{0}", m_fTotalHeight);
                Transform t        = chatitem.transform;
                float     distance = t.localPosition.y - center.y;
                float     offsetY  = chatitem.GetOffsetY() - distance - m_panel.baseClipRegion.w * 0.5f + m_panel.clipSoftness.y;
                if (offsetY > 0)
                {
                    totalheight = offsetY;
                }
                m_lstCurrChannel.Add(chatitem);

                if (!flag && chatitem.m_chatdata != null && m_chatManager.IsCanAutoPlayVoice(chatitem.m_chatdata.Channel) && !chatitem.m_chatdata.played && !GVoiceManger.Instance.IsPlaying)
                {
                    flag = true;
                    chatitem.PlayeVoice();
                }
            }
        }

        if (totalheight > 0)
        {
            //可以立即刷新
            if (CheckCanUpdateMsg(lastChatItem, center.y))
            {
                Engine.Utility.Log.LogGroup("ZCX", "MoveRelative :{0}", totalheight);
                m_scrollview_ChatScrollView.MoveRelative(new Vector3(0, totalheight, 0));
            }
            else
            {
                m_fMoveTotalHeight = totalheight;
                m_noreadMsg       += list.Count;
                UpdateNoReadMsgTips(m_noreadMsg);
            }
        }
    }