Esempio n. 1
0
        private void AddLineObject(IChatItem item, List <LineObjCache> curLineObject)
        {
            LineObjCache objCache;

            objCache.width           = item.GetItemWidth();
            objCache.height          = item.GetItemHeight();
            objCache.trans           = item.GetTransform();
            objCache.trans.sizeDelta = new Vector2(objCache.width, objCache.height);
            curLineObject.Add(objCache);
        }
Esempio n. 2
0
        public void SetData(ChatContentItemData data)
        {
            RectTransform selfTrans = this.transform as RectTransform;

            m_curWidth = selfTrans.rect.width;

            // 删除现有子对象
            for (int i = 0; i < currChatBoxItem.Count; i++)
            {
                IChatItem itm = currChatBoxItem[i];
                itm.Destroy();
                //itm.Clear();
                GameObject temp = itm.GetTransform().gameObject;
                ResNode.DestroyRes(ref temp);
            }

            currChatBoxItem.Clear();
            float width   = selfTrans.rect.width;
            float offsetX = 0f;
            float offsetY = 0f;

            // TODO: 如果使用了自动布局,可以不计算位置
            List <LineObjCache> curLineObject = new List <LineObjCache>();

            if (data.objList != null)
            {
                foreach (var obj in data.objList)
                {
                    CreateSubItem(obj, width, ref offsetX, ref offsetY, curLineObject);
                }
            }
            AlignLineObject(ref offsetX, ref offsetY, curLineObject);

            data.Height         = -offsetY;
            selfTrans.sizeDelta = new Vector2(selfTrans.sizeDelta.x, data.Height);

            m_Height = data.Height;
        }