コード例 #1
0
        internal void AddItem(Item item, int amount)
        {
            if (item == null)
            {
                Debug.LogError("Cannot add null as an item");
                return;
            }
            bool canDo = (this.item == null);

            if (!canDo)
            {
                canDo = item.Equals(this.item);
            }
            if (canDo)
            {
                GetSlotFromSlot(this).item    = item;
                GetSlotFromSlot(this).amount += amount;
                if (model.items.ContainsKey(item))
                {
                    model.items[item] += amount;
                }
                else
                {
                    model.items.Add(item, amount);
                }
                model.NotifyViews();
            }
            else
            {
                Debug.LogError("Trying to add a different kind of item in a slot");
            }
        }
コード例 #2
0
ファイル: Slot.cs プロジェクト: DeadPoolP/legendary-lamp
        internal void AddItem(Item item, int amount)
        {
            model.FreeSlotReservation(this);
            if (item == null)
            {
                Debug.LogError("Cannot add null as an item");
                return;
            }
            bool canDo = (this.item == null);

            if (!canDo)
            {
                canDo = item.Equals(this.item);
            }
            if (canDo)
            {
                int posThis = this.model.slots.IndexOf(this);
                model.slots.Remove(this);
                this.item    = item;
                this.amount += amount;
                if (model.items.ContainsKey(item))
                {
                    model.items[item] += amount;
                }
                else
                {
                    model.items.Add(item, amount);
                }
                this.model.slots.Insert(posThis, this);
                model.NotifyViews();
            }
            else
            {
                Debug.LogError("Trying to add a different kind of item in a slot");
            }
        }