示例#1
0
        /// <summary>
        /// Initializes the ItemCollection reference. This is useful if the ItemCollection is assigned after Awake is called.
        /// </summary>
        /// <param name="itemCollection">The ItemCollection to initialize.</param>
        private void InitializeItemCollection(ItemCollection itemCollection)
        {
            // The ItemCollection has already been initialized.
            if (m_Inventory != null)
            {
                return;
            }

            if (itemCollection == null)
            {
                return;
            }

            m_ItemCollection = itemCollection;

            m_GameObject = gameObject;
            m_Inventory  = m_GameObject.GetCachedComponent <InventoryBase>();
            if (m_CategoryItemSets.Length == 0 && m_ItemCollection.Categories.Length > 0)
            {
                m_CategoryItemSets = new CategoryItemSet[m_ItemCollection.Categories.Length];
            }

            m_ActiveItemSetIndex = new int[m_CategoryItemSets.Length];
            m_NextItemSetIndex   = new int[m_ActiveItemSetIndex.Length];
            for (int i = 0; i < m_CategoryItemSets.Length; ++i)
            {
                m_ActiveItemSetIndex[i] = -1;
                m_NextItemSetIndex[i]   = -1;
                if (m_CategoryItemSets[i] == null)
                {
                    m_CategoryItemSets[i] = new CategoryItemSet(m_ItemCollection.Categories[i].ID);
                }
            }

            // Store the category index value within the ItemType to prevent the index from having to be retrieved every time the ID is used.
            var itemTypes = m_ItemCollection.ItemTypes;

            for (int i = 0; i < itemTypes.Length; ++i)
            {
                var indices = new int[itemTypes[i].CategoryIDs.Length];
                for (int j = 0; j < itemTypes[i].CategoryIDs.Length; ++j)
                {
                    var categoryID = itemTypes[i].CategoryIDs[j];
                    for (int k = 0; k < m_CategoryItemSets.Length; ++k)
                    {
                        if (m_CategoryItemSets[k].CategoryID == categoryID)
                        {
                            indices[j] = k;
                            break;
                        }
                    }
                }
                itemTypes[i].CategoryIndices = indices;
            }

            if (Application.isPlaying)
            {
                EventHandler.RegisterEvent <Item>(gameObject, "OnInventoryAddItem", OnAddItem);
            }
        }
示例#2
0
        /// <summary>
        /// Initialize the ItemCollection and ItemSet.
        /// </summary>
        private void Awake()
        {
            m_GameObject = gameObject;
            m_Inventory  = m_GameObject.GetCachedComponent <InventoryBase>();

            Initialize(true);

            EventHandler.RegisterEvent <Item>(m_GameObject, "OnInventoryAddItem", OnAddItem);
        }