//道具查看与更新 public void itemupdate() { bool upD = true; for (int i = 0; i < magic.getItemList().Count; ++i) { if (i < items.Count) { if (items[i] != magic.getItemList()[i]) { upD = false; break; } } else { upD = false; break; } } if (!upD) { //删 for (int i = 0; i < itemGameObjectlist.Count; ++i) { GameObject.Destroy(itemGameObjectlist[i]); } itemGameObjectlist.Clear(); //修 items.Clear(); for (int i = 0; i < magic.getItemList().Count; ++i) { items.Add(magic.getItemList()[i]); } //新建 Sprite nowSprite = new Sprite(); itemLists.GetComponent <RectTransform>().sizeDelta = new Vector2(120 * items.Count, 100); for (itemCount = 0; itemCount < items.Count; ++itemCount) { GameObject item = GameObject.Instantiate(itemPerb, itemLists.transform); itemGameObjectlist.Add(item); if (items.Count % 2 == 0) { item.transform.localPosition = new Vector3(120 * itemCount - 60, 0, 0); } else { item.transform.localPosition = new Vector3(120 * itemCount - 120, 0, 0); } item.name = items[itemCount].ToString(); string[] lines = Itemtext.text.Split("\n"[0]); string englishName = null; for (int i = 0; i < lines.Length; ++i) { string[] parts = lines[i].Split(" "[0]); if (parts[1] == item.name) { englishName = parts[0]; break; } } nowSprite = LoadResources.Instance.itemSp.nameToSprite(englishName); item.GetComponent <Image>().sprite = nowSprite; item.transform.localScale = new Vector3(1, 1, 1); } } }