Exemple #1
0
        /// <summary>
        /// Initializes specifed container with a set
        /// </summary>
        /// <param name="setName"></param>
        /// <param name="container"></param>
        public void FillContainer(string setName, SlotContainer <ContainedSlot> container)
        {
            SlotContainer <BlueprintSlot> set;

            if (Config.ContainerSets.TryGetValue(setName, out set))
            {
                if (container.GridSize.X < set.GridSize.X || container.GridSize.Y < set.GridSize.Y)
                {
                    throw new InvalidOperationException("Destination container is smaller than the set");
                }

                container.Clear();

                foreach (var blueprintSlot in set)
                {
                    try
                    {
                        var item = (Item)CreateFromBluePrint(blueprintSlot.BlueprintId);
                        container.PutItem(item, blueprintSlot.GridPosition, blueprintSlot.ItemsCount);
                    }
                    catch (Exception x)
                    {
                        logger.Error("Unable to create the item from blueprint {0}: {1}", blueprintSlot.BlueprintId, x.Message);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Draws the content of the inventory (slots and icons)
        /// </summary>
        protected virtual void DrawInventoryContent()
        {
            if (SlotContainer != null)
            {
                SlotContainer.Clear();
            }
            else
            {
                SlotContainer = new List <GameObject>();
            }
            // we initialize our sprites
            if (EmptySlotImage == null)
            {
                InitializeSprites();
            }
            // we remove all existing slots
            foreach (InventorySlot slot in transform.GetComponentsInChildren <InventorySlot>())
            {
                if (Application.isEditor)
                {
                    DestroyImmediate(slot.gameObject);
                }
                else
                {
                    Destroy(slot.gameObject);
                }
            }
            // for each slot we create the slot and its content
            for (int i = 0; i < TargetInventory.Content.Length; i++)
            {
                DrawSlot(i);
            }
            DestroyImmediate(_slotPrefab);

            if (EnableNavigation)
            {
                SetupSlotNavigation();
            }
        }