void OnUpateItem(GameObject go, int index, int realIndex, List <ItemDataManager.ItemData> dataList, Dictionary <int, PropsItem> dataDic) { int index_ = 0; int indexList = Mathf.Abs(realIndex); PropsItem Item1 = go.transform.Find("item1").GetComponent <PropsItem>(); Item1.Init(dataList[indexList * 2]); if (!dataDic.ContainsKey(dataList[indexList * 2].id)) { dataDic.Add(dataList[indexList * 2].id, Item1); } index_ = indexList * 2 + 1; int tankCount = dataList.Count; if (index_ > (tankCount - 1)) { PropsItem tankItem2 = go.transform.Find("item2").GetComponent <PropsItem>(); tankItem2.gameObject.SetActive(false); } else { PropsItem Item2 = go.transform.Find("item2").GetComponent <PropsItem>(); Item2.gameObject.SetActive(true); Item2.Init(dataList[index_]); if (!dataDic.ContainsKey(dataList[index_].id)) { dataDic.Add(dataList[index_].id, Item2); } } }
IEnumerator CreateUnit(UIGrid grid, List <ItemDataManager.ItemData> unitData, Dictionary <int, PropsItem> dataDic) { yield return(new WaitForSeconds(0.01f)); if (grid != null) { grid.DestoryAllChildren(); } int tankCount = unitData.Count; int itemCount = 0; if (tankCount % 2 == 0) { itemCount = tankCount / 2; } else { itemCount = tankCount / 2 + 1; } for (int i = 0; i < itemCount; i++) { if (grid.gameObject != null) { int index_ = 0; GameObject tankItem = (GameObject)Resources.Load(AppConfig.FOLDER_PROFAB_UI + "warehouse/props_items"); GameObject item = NGUITools.AddChild(grid.gameObject, tankItem); item.name = "0" + i; PropsItem tankItem1 = item.transform.Find("item1").GetComponent <PropsItem>(); tankItem1.Init(unitData[i * 2]); dataDic.Add(unitData[i * 2].id, tankItem1); PropsItem tankItem2 = item.transform.Find("item2").GetComponent <PropsItem>(); index_ = i * 2 + 1; if (index_ > (tankCount - 1)) { NGUITools.Destroy(tankItem2.gameObject); } else { tankItem2.Init(unitData[index_]); dataDic.Add(unitData[index_].id, tankItem2); } } } grid.repositionNow = true; grid.Reposition(); }