Example #1
0
    void OnInitItem(LoopItemObject item, LoopItemData data)
    {
        chatItemData myData   = data as chatItemData;
        chatItem     itemComp = item.widget.GetComponent <chatItem>();

        itemComp.showItemByType(myData.ItemType);

        switch (myData.ItemType)
        {
        case 1:
            itemComp.selfContent.text       = myData.content;
            itemComp.selfUserNameLabel.text = myData.username;
            break;

        case 2:
            itemComp.otherContent.text       = myData.content;
            itemComp.ohterUserNameLabel.text = myData.username;
            GameObject go = itemComp.transform.FindChild("otherChatItem/headImgBg/headImg").gameObject;
            //go.name = "headImg" + myData.uid;
            UIEventListener.Get(go).onClick
                = (g) => { print(myData.uid); };
            break;

        case 3:
            itemComp.timeLable.text = myData.content;

            break;
        }
    }
Example #2
0
    void OnItemInit(LoopItemObject item, LoopItemData data)
    {
        chatItemData myData   = data as chatItemData;
        chatItem     itemComp = item.widget.GetComponent <chatItem>();

        itemComp.showItemByType(myData.ItemType);
        itemComp.otherContent.text = myData.content;
        itemComp.selfContent.text  = myData.content;
        itemComp.timeLable.text    = myData.content;
        item.gameObject.name       = "Item" + item.dataIndex;
        //item.widget.gameObject.SetActive(false);
        //print(myData.content +"  " +item.widget.isVisible);
    }
Example #3
0
    public void UpdateInBack(int uid, string username, string content, string time, int type)
    {
        //myLoopSV.datasList


        LoopItemData data = new chatItemData(uid, username, content, time, type);

        this.datasList.Insert(0, data);
        //this.datasList.Add(data);
        if (this.itemsList != null)
        {
            foreach (LoopItemObject lio in itemsList)
            {
                lio.dataIndex++;
            }

            if (firstItem != null && firstItem.dataIndex == 1)
            {
                //float distance = -panelHeight / 2 - (firstItem.transform.localPosition.y + scrollView.transform.localPosition.y)+gapDis;
                //float distance = -scrollView.transform.localPosition.y; //-panelHeight/2 + gapDis - firstItem.transform.localPosition.y;//+scrollView.transform.localPosition.y; //第一个距离底部的高
                //print("distance:" + distance);
                //往上面顶
                foreach (LoopItemObject lio in itemsList)
                {
                    if (type == 3)
                    {
                        lio.transform.localPosition = new Vector3(0, lio.transform.localPosition.y + 30 + 10, 0);
                    }
                    else
                    {
                        lio.transform.localPosition = new Vector3(0, lio.transform.localPosition.y + 100 + 10, 0);
                    }
                    //scrollView.ResetPosition();
                }
            }
        }
        //UITable
    }
Example #4
0
    public void UpdateInFront(int uid, string username, string content, string time, int type)
    {
        LoopItemData data = new chatItemData(uid, username, content, time, type);

        this.datasList.Add(data);
    }
Example #5
0
    /// <summary>
    /// 检验items的两端是否要补上或删除
    /// </summary>
    void Validate()
    {
        if (datasList == null || datasList.Count == 0)
        {
            return;
        }

        // 如果itemsList还不存在
        if (itemsList == null || itemsList.Count == 0)
        {
            itemsList = new List <LoopItemObject>();

            LoopItemObject item = GetItemFromLoop();

            Vector3      v3 = new Vector3(0, itemStartPos.y, 0);
            chatItemData d  = datasList[0] as chatItemData;
            if (d.ItemType != 3)
            {
                itemStartPos = new Vector3(0, itemStartPos.y + 50, 0);
            }

            InitItem(item, 0, datasList[0]);
            itemStartPos = v3;//还原
            firstItem    = lastItem = item;
            itemsList.Add(item);

            //Validate();
        }

        //
        bool all_invisible = true;

        foreach (LoopItemObject item in itemsList)
        {
            if (item.widget.isVisible == true)
            {
                all_invisible = false;
            }
        }
        if (all_invisible == true)
        {
            return;
        }

        // 先判断前端是否要增减
        if (firstItem.widget.isVisible)
        {
            // 判断要不要在它的前面补充一个item
            if (firstItem.dataIndex > 0)
            {
                LoopItemObject item = GetItemFromLoop();

                // 初化:数据索引、大小、位置、显示
                int index = firstItem.dataIndex - 1;
                //InitItem(item, index, datasList[index]);
                AddToFront(firstItem, item, index, datasList[index]);
                firstItem = item;
                itemsList.Insert(0, item);

                //Validate();
                //SpringPanel.Begin
            }
        }
        else
        {
            // 判断要不要将它移除
            // 条件:自身是不可见的;且它后一个item也是不可见的(或被被裁剪过半的).
            //      这有个隐含条件是itemsList.Count>=2.
            if (itemsList.Count >= 2 &&
                itemsList[0].widget.isVisible == false &&
                itemsList[1].widget.isVisible == false)
            {
                itemsList.Remove(firstItem);
                PutItemToLoop(firstItem);
                firstItem = itemsList[0];

                //Validate();
            }
        }

        // 再判断后端是否要增减
        if (lastItem.widget.isVisible)
        {
            // 判断要不要在它的后面补充一个item
            if (lastItem.dataIndex < datasList.Count - 1)
            {
                LoopItemObject item = GetItemFromLoop();

                // 初化:数据索引、大小、位置、显示
                int index = lastItem.dataIndex + 1;
                AddToBack(lastItem, item, index, datasList[index]);
                lastItem = item;
                itemsList.Add(item);

                //Validate();
            }
        }
        else
        {
            // 判断要不要将它移除
            // 条件:自身是不可见的;且它前一个item也是不可见的(或被被裁剪过半的).
            //      这有个隐含条件是itemsList.Count>=2.
            if (itemsList.Count >= 2 &&
                itemsList[itemsList.Count - 1].widget.isVisible == false &&
                itemsList[itemsList.Count - 2].widget.isVisible == false)
            {
                itemsList.Remove(lastItem);
                PutItemToLoop(lastItem);
                lastItem = itemsList[itemsList.Count - 1];
                //UIGrid ug =new UIGrid();
                //Validate();
            }
        }

        //防止还没到底的时候就回弹BUG(效果不好)
        if (firstItem.dataIndex != 0 && lastItem.dataIndex != datasList.Count - 1)
        {
            SpringPanel sp = gameObject.GetComponent <SpringPanel>();
            if (sp != null)
            {
                sp.enabled = false;
            }
        }
    }