Esempio n. 1
0
    void ShowBuffInfo(Transform container, bool bMainRole)
    {
        if (container == null)
        {
            return;
        }
        int       cellHegiht  = 100;
        Transform buffMessage = container.transform.Find("BuffMessage");

        if (buffMessage == null)
        {
            return;
        }

        ArrayList buffList = BuffManager.MainRoleBuffList;

        if (!bMainRole)
        {
            buffList = BuffManager.TargetBuffList;
        }
        if (buffList.Count == 0)
        {
            buffMessage.gameObject.SetActive(false);
        }
        else
        {
            //  buffMessage.gameObject.SetActive(true);
        }
        if (!buffMessage.gameObject.activeSelf)
        {
            return;
        }
        int       count       = buffList.Count < totalBuffIconCount ? buffList.Count : totalBuffIconCount;
        Transform scrollTrans = buffMessage.Find("ScrollView");

        if (scrollTrans == null)
        {
            return;
        }
        Transform bg = buffMessage.Find("Bg");

        if (bg == null)
        {
            return;
        }
        UIScrollView sv = scrollTrans.GetComponent <UIScrollView>();

        if (sv == null)
        {
            return;
        }
        UIPanel panel   = sv.GetComponent <UIPanel>();
        Vector4 baseVec = panel.baseClipRegion;

        panel.baseClipRegion = new Vector4(baseVec.x, -cellHegiht * (count) / 2 + cellHegiht / 2, baseVec.z, cellHegiht * count);
        panel.clipOffset     = new UnityEngine.Vector2(0, 0);
        UISprite spr = bg.GetComponent <UISprite>();

        if (spr != null)
        {
            spr.height = cellHegiht * count;
        }
        spr.transform.localPosition = new Vector3(0, -cellHegiht * (count - 1) / 2, 0);
        // sv.ResetPosition();


        // Transform gridTrans = scrollTrans.Find("BuffGrid");
        Transform gridTrans = scrollTrans;

        if (gridTrans == null)
        {
            return;
        }

        int childCount = gridTrans.childCount;

        for (int j = buffList.Count; j < childCount; j++)
        {
            string    buffItemName = GetBuffItemName(j);
            Transform itemTrans    = gridTrans.Find(buffItemName);
            if (itemTrans != null)
            {
                itemTrans.gameObject.SetActive(false);
            }
        }
        for (int i = 0; i < buffList.Count; i++)
        {
            Client.stAddBuff st = (Client.stAddBuff)buffList[i];

            BuffDataBase db = GameTableManager.Instance.GetTableItem <BuffDataBase>(st.buffid, (int)st.level);
            if (db != null)
            {
                GameObject buffItem     = null;
                string     buffItemName = GetBuffItemName(i);
                Transform  itemTrans    = gridTrans.Find(buffItemName);
                if (itemTrans != null)
                {
                    buffItem = itemTrans.gameObject;
                }
                else
                {
                    buffItem  = GameObject.Instantiate(m_trans_BuffItemInfo.gameObject) as GameObject;
                    itemTrans = buffItem.transform;
                }

                buffItem.transform.parent = sv.transform;//gridTrans;
                itemTrans.localScale      = Vector3.one;
                itemTrans.localRotation   = Quaternion.identity;
                itemTrans.localPosition   = new Vector3(0, -cellHegiht * i, 0);
                //  UIGrid grid = gridTrans.GetComponent<UIGrid>();

                buffItem.gameObject.SetActive(true);
                // grid.repositionNow = true;
                buffItem.name = buffItemName;
                UIDragScrollView dragScroll = buffItem.GetComponent <UIDragScrollView>();
                if (dragScroll == null)
                {
                    dragScroll = buffItem.AddComponent <UIDragScrollView>();
                }
                dragScroll.scrollView = sv;
                BuffItemInfo info = buffItem.GetComponent <BuffItemInfo>();
                if (info == null)
                {
                    info = buffItem.AddComponent <BuffItemInfo>();
                }

                info.InitBuffItemInfo(db, st.lTime);
            }
        }
    }