Exemplo n.º 1
0
        private void ContainerOnContentsChanged(Container container, IEnumerable <Item> items, Container.ContainerChangeType type)
        {
            switch (type)
            {
            case Container.ContainerChangeType.Add:
                foreach (Item item in items)
                {
                    Vector2Int position = container.PositionOf(item);
                    CreateItemDisplay(item, position);
                }
                break;

            case Container.ContainerChangeType.Remove:
                foreach (Item item in items)
                {
                    for (var i = 0; i < gridItems.Count; i++)
                    {
                        ItemGridItem gridItem = gridItems[i];
                        if (gridItem.Item == item)
                        {
                            gridItems.RemoveAt(i);
                            Destroy(gridItem.gameObject);
                            break;
                        }
                    }
                }
                break;

            case Container.ContainerChangeType.Move:
                foreach (Item item in items)
                {
                    foreach (ItemGridItem gridItem in gridItems)
                    {
                        if (gridItem.Item == item)
                        {
                            Vector2Int position = container.PositionOf(item);
                            MoveToSlot(gridItem.transform, position);
                            break;
                        }
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Exemplo n.º 2
0
 public void RemoveGridItem(ItemGridItem item)
 {
     gridItems.Remove(item);
 }