Example #1
0
        // 设置经常使用英雄信息
        private void SetOftenUseHeroInfo(List <cmd_entity_hero_info> heroInfoList, GameObject heroGroup, ResNode heroIns, int nPDBID, bool bIsSelf)
        {
            if (heroInfoList.Count > 5 || heroIns == null)
            {
                return;
            }

            // 每次先清空HeroGroup内容
            int nChildCount = heroGroup.transform.childCount;

            for (int i = nChildCount - 1; i >= 0; --i)
            {
                GameObject go = heroGroup.transform.GetChild(i).gameObject;
                ResNode.DestroyRes(ref go);
            }

            bool bIsFirst   = true;
            int  nMaxUseNum = 0;

            // heroInfoList数据是按使用次数从大向小排序的
            foreach (var item in heroInfoList)
            {
                if (item.nHeroID == 0)
                {
                    return;
                }

                // 确定最大使用次数
                if (bIsFirst)
                {
                    bIsFirst   = false;
                    nMaxUseNum = item.nGameCount;
                }

                // 创建预制体并进行赋值显示
                GameObject inst = heroIns.InstanceMainRes();
                if (inst == null)
                {
                    continue;
                }
                inst.transform.SetParent(heroGroup.transform, false);

                HeroInfo heroInfo = inst.GetComponent <HeroInfo>();
                if (heroInfo == null)
                {
                    continue;
                }
                heroInfo.setRequestInfo(bIsSelf, nPDBID);
                heroInfo.setHeroInfo(item, nMaxUseNum);
            }
        }