Beispiel #1
0
        /// Open container UI panel.
        public void OpenContainer(Gameplay.ItemContainer itemContainer)
        {
            if (IsOpen)
            {
                CloseContainer();
            }
            IsOpen = true;
            _slots = new List <KeyValuePair <ItemSlot, UIItemSlot> >();
            //TODO sort
            //Sorting items in container
            // if (_items.Count > 0)
            // {
            //     _items.Sort();
            // }

            hidablePanel.SetActive(true);

            //Subscribe on SyncList update
            itemContainer.Items.Callback += OnContainerUpdated;

            // Loop through each item in the given items list and instantiate a new UIItemSlot prefab for each one.
            for (int i = 0; i < itemContainer.Items.Count; i++)
            {
                CreateUISlot(i, itemContainer.Items[i]);
            }

            OpenedItemContainer = itemContainer;
        }
Beispiel #2
0
        public void CloseContainer()
        {
            // Loop through each slot, detatch it from its ItemSlot and delete the GameObject.
            foreach (var slot in _slots)
            {
                Destroy(slot.Value.gameObject);
            }

            if (!(OpenedItemContainer is null))
            {
                OpenedItemContainer.Items.Callback -= OnContainerUpdated;
            }

            OpenedItemContainer = null;
            // Clear the list and deactivate the container window.
            _slots.Clear();
            hidablePanel.SetActive(false);
            IsOpen = false;
        }