//添加item到列表 public bool AddItemToList(PickInfo send, BaseItem it, string prefabPath) { GameObject obj = ResManager.Instance.LoadPrefabFromRes(prefabPath, true); Sprite sprite = ResManager.Instance.LoadSpriteFromRes(it.imageName); //用gameobject的唯一标识符作为字典的索引 int index = send.Instance.GetInstanceID(); EquipListItem listItem = new EquipListItem(it, obj, send.Instance); m_collectView.ChangeListHeight(m_collectModel.ListCount()); //初始化prefab的各个子物体 Transform numberObj = obj.transform.GetChild(0); Text number = numberObj.GetComponent <Text>(); number.text = it.count.ToString(); Image img = obj.transform.GetChild(1).GetComponent <Image>(); img.sprite = sprite; listItem.sprite = sprite; Text name = obj.transform.GetChild(2).GetComponent <Text>(); name.text = it.name; Text discribe = obj.transform.GetChild(3).GetComponent <Text>(); discribe.text = it.discribe; obj.transform.GetComponent <BagItemController>().SetDicKey(index); //初始化完成 m_collectModel.AddItemToList(index, listItem); m_collectView.MountItem(listItem.obj.transform); return(true); }
//插入item到列表 public void AddItemToList(int key, EquipListItem it) { equipList.Add(key, it); }