/// <summary> /// �������� �������� ������� � ��������� /// </summary> /// <param name="item">����������� �������</param> /// <returns>���������� ����� �� ������������ �����������, ���� ������� �� ��� ��������� ��������. 0 - ���� ������� ������� ��������</returns> public int addItem(List<RectangleSlot> slots, Item item) { foreach (RectangleSlot slot in slots) { // ���������� ��� ����� foreach (ItemSlot i in slot.Items) { // �������� ����� ���������� �������� � ����������� ���������� �� if (i.item.Equals(item) && !i.item.isFullCount()) { // ���� ������� ���������, � �� �� ��������� ������������� if (item.getCount()!=0) // ���� � ��� ���� ������� �����������, ������� ���� ��������� item.setCount(i.item.incCount(item.getCount())); if (item.getCount()==0) // ���������� ���������, ����� �������� return 0; } } for(int y=1;y<=slot.position.CellsYCount;y++){ // �������� ����� ��������� �������, � �������� ������� ������� (�� ��������) for(int x=1;x<=slot.position.CellsXCount;x++){ bool result = true; foreach(ItemSlot i in slot.Items){ if(x>=i.getPosition().X && x<i.getPosition().X+i.item.getSize().getWidth() && y>=i.getPosition().Y && y<i.getPosition().Y+i.item.getSize().getHeight()){ result=false; break; } } if(result){ // �������� ����� ��������� �������� slot.Items.Add(new ItemSlot(item.Clone(), new ItemPosition(x, y))); return 0; } } } } return item.getCount(); // ���������� ����� ����������� (�� �������) ��������� }
public static bool AddInInventory(Item item) { UInventory inventory = SingletonNames.getInventory().GetComponent<UInventory>(); if (inventory!=null) { if(inventory.addItem(item.Clone())!=0) return false; return true; } else { Debug.LogError("Ссылка на инвентарь не верна! ["+SingletonNames.Constants.GUI.INVENTORY+"]"); return false; } }
/// <summary> /// Пытается добавить предмет item в слот slotData /// </summary> /// <param name="slotData">Сумка, в которую пытаются добавить предмет</param> /// <param name="item">Добавляемый предмет</param> /// <returns>Возвращает число экземпляров item НЕ ДОБАВЛЕННЫХ в слот</returns> public int AddItem(SlotData slotData, Item item) { foreach (ItemSlot i in slotData.Items) { // пытаемся найти идентичные предметы и попробовать объединить их if (i.item.Equals(item) && !i.item.isFullCount()) { // если предмет идентичен, и он не полностью укомплектован if (item.getCount() != 0) // пока у нас есть остаток экземпляров, которые надо раскидать item.setCount(i.item.incCount(item.getCount())); if (item.getCount() == 0) // экземпляры кончились, можно выходить return 0; } } for (int y = 1; y <= slotData.position.CellsYCount; y++) { // пытаемся найти свободную область, и засунуть предмет целиком (не разделяя) for (int x = 1; x <= slotData.position.CellsXCount; x++) { bool result = true; foreach (ItemSlot i in slotData.Items) { if (x >= i.getPosition().X && x < i.getPosition().X + i.item.getSize().getWidth() && y >= i.getPosition().Y && y < i.getPosition().Y + i.item.getSize().getHeight()) { result = false; break; } } if (result) { // предметы можно полностью добавить slotData.Items.Add(new ItemSlot(item.Clone(), new ItemPosition(x, y))); return 0; } } } return item.getCount(); }
public void OnItemSelect(Item selected) { inventory.addItem(selected.Clone()); inventory.initListItems.Add(selected.resource.files.itemName); Repaint(); }
public void OnItemSelect(Item item) { inventory.addItem(item.Clone()); }