Beispiel #1
0
 private void ReleaseGrid()
 {
     if (null != lastShowGrids)
     {
         UIAwardItemGrid tempGrid = null;
         for (int i = 0, max = lastShowGrids.Count; i < max; i++)
         {
             tempGrid = lastShowGrids[i];
             if (null != tempGrid)
             {
                 tempGrid.Release();
             }
         }
     }
 }
Beispiel #2
0
    private void CreateAwardUI(List <CommonAwardData> awardDatas)
    {
        if (null != m_trans_AwardContent && null != m_trans_UIAwardItemGrid)
        {
            int cacheNum  = (null != lastShowGrids) ? lastShowGrids.Count : 0;
            int createNum = (null != awardDatas) ? awardDatas.Count : 0;
            List <UIAwardItemGrid> tempCacheGrid = new List <UIAwardItemGrid>();
            if (null != lastShowGrids && lastShowGrids.Count > 0)
            {
                tempCacheGrid.AddRange(lastShowGrids);
            }

            Vector3 startPos = Vector3.zero;
            int     div      = createNum / 2;
            if (createNum % 2 == 0)
            {
                startPos.x = -((div - 1) * gridGap.x + 0.5f * gridGap.x + (div - 1) * size.x + 0.5f * size.x);
            }
            else
            {
                startPos.x = -(div * (gridGap.x + size.x));
            }

            int             loopCount     = Mathf.Max(cacheNum, createNum);
            UIAwardItemGrid tempAwardGrid = null;
            GameObject      cloneObj      = null;
            for (int i = 0; i < loopCount; i++)
            {
                if (i < createNum)
                {
                    if (i < cacheNum)
                    {
                        tempAwardGrid = tempCacheGrid[i];
                    }
                    else
                    {
                        cloneObj = GameObject.Instantiate(m_trans_UIAwardItemGrid.gameObject);
                        if (null == cloneObj)
                        {
                            continue;
                        }
                        tempAwardGrid = cloneObj.AddComponent <UIAwardItemGrid>();
                        tempAwardGrid.CacheTransform.parent     = m_trans_AwardContent;
                        tempAwardGrid.CacheTransform.localScale = Vector3.one;
                        if (null == lastShowGrids)
                        {
                            lastShowGrids = new List <UIAwardItemGrid>();
                        }
                        lastShowGrids.Add(tempAwardGrid);
                    }

                    tempAwardGrid.CacheTransform.localPosition = startPos;
                    tempAwardGrid.SetGridData(awardDatas[i].BaseId, awardDatas[i].Num);
                    startPos.x += (gridGap.x + size.x);
                }
                else
                {
                    tempAwardGrid = tempCacheGrid[i];
                    if (null != tempAwardGrid)
                    {
                        tempAwardGrid.Release();
                        tempAwardGrid.SetVisible(false);
                    }
                }
            }
        }
    }