using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DrawEquipItem : MonoBehaviour { private Transform content; private GameObject equipItem; private const string imagepath="UI/EquipImage/"; // Use this for initialization void Start () { equipItem = Resources.Load("UI/EquipUI/EquipItemToggle") as GameObject; content = transform.Find("Viewport/Content"); for (int i = 0; i < EquipSelect.GetInstance. Equips.Count; i++) { if (EquipSelect.GetInstance. Equips[i].Type ==name&& EquipSelect.GetInstance.Equips[i].Group.Contains(transform.parent.name)) { Draw(EquipSelect.GetInstance.Equips[i].PicName); } } SetToggleGroup(); } private void Draw(string equipname) { GameObject item = Instantiate(equipItem,content); item.transform.Find("Image").GetComponent().sprite = Resources.Load(imagepath+equipname, typeof(Sprite)) as Sprite; item.transform.Find("Label").GetComponent().text = equipname; item.name = equipname; } private void SetToggleGroup() { for (int i = 0; i < content.childCount; i++) { Equip eq = EquipSelect.GetInstance.GetInitInfoByName(content.GetChild(i).name); if (eq.IsSelectMore) { content.GetChild(i).GetComponent().group = content.GetComponent(); } } } }