コード例 #1
0
        protected ItemTrack GetNewItem()
        {
            ItemTrack itemTrack = new ItemTrack();

            itemTrack.Reset();
            return(itemTrack);
        }
コード例 #2
0
        public void AddItem(ItemID itemID)
        {
            int type = GetItemType(itemID.classItem);

            itemID.type = type;
#if UNITY_EDITOR
            PreDebugLog("Adding Item", "Adding for type: ", type, itemID.item);
#endif
            Dictionary <string, ItemTrack> dictionary = GetType(type);
            ItemTrack newTrack = null;
            if (dictionary[LINK_MAP].capacity - dictionary[LINK_MAP].occupiedSpace == 0 && dictionary[LINK_MAP].capacity != -1)
            {
                newTrack = PopItem(type);
            }
            if (newTrack != null)
            {
                newTrack.Reset();
            }
            else
            {
                newTrack = GetNewItem();
            }
            newTrack.itemID = itemID.item;
            newTrack.item   = itemID;
            dictionary.Add(this.counter.ToString(), newTrack);
            newTrack.localNext = this.counter;
            ItemTrack itemTrack = null;
            if (!dictionary.ContainsKey(itemID.item))   //item index not found - New Item in TYPE
            {
                itemTrack = GetNewItem();
                dictionary.Add(itemID.item, itemTrack);
                if (dictionary[LINK_MAP].globalNext == -99 && dictionary[LINK_MAP].globalPrevious == -99)  //first item in TYPE
                {
                    dictionary[LINK_MAP].globalPrevious = this.counter;
                    dictionary[LINK_MAP].globalNext     = this.counter;
                }
                itemTrack.item          = itemID;
                itemTrack.localPrevious = this.counter;
                itemTrack.localNext     = this.counter;
                itemTrack.occupiedSpace = 0;
                itemTrack.capacity      = dictionary[LINK_MAP].capacity;
            }
            else
            {
                itemTrack = dictionary[itemID.item];
            }
            newTrack.localPrevious  = itemTrack.localNext;
            newTrack.globalPrevious = dictionary[LINK_MAP].globalNext;
            newTrack.globalNext     = this.counter;

            newTrack.occupiedSpace = 1; //occupied space is 1 for each item
            newTrack.capacity      = 1; //capacity is 1 for each item

            dictionary[itemTrack.localNext.ToString()].localNext = this.counter;
            dictionary[dictionary[LINK_MAP].globalNext.ToString()].globalNext = this.counter;

            itemTrack.localNext             = this.counter;
            dictionary[LINK_MAP].globalNext = this.counter;

            itemTrack.occupiedSpace++;
            dictionary[LINK_MAP].occupiedSpace++;
#if UNITY_EDITOR
            PostDebugLog("Added Item", type, itemID.item, dictionary);
#endif
            this.counter++;

            if (OnAdd != null)
            {
                OnAdd(itemID);
            }
            if (OnUpdate != null)
            {
                OnUpdate(GetItems(dictionary));
            }
        }