public virtual void ToCollection(ItemCollectionBase collection) { collection.Resize((uint)items.Length); if (collection.useReferences) { for (int i = 0; i < items.Length; i++) { var item = items[i]; var c = ItemCollectionBase.FindByName(item.collectionName); if (item.amount > 0 && item.itemID >= 0) { collection[i].item = c.Find((uint)item.itemID); collection[i].Repaint(); } } } else { var deserializedItems = items.Select(o => o.ToItem()).ToArray(); for (int i = 0; i < deserializedItems.Length; i++) { collection[i].item = deserializedItems[i]; collection[i].Repaint(); if (deserializedItems[i] != null) { deserializedItems[i].gameObject.SetActive(false); deserializedItems[i].transform.SetParent(collection.container); } } } // Handle equippable items; Make sure the reference to the equippable collection is set. foreach (var item in collection) { var eq = item.item as EquippableInventoryItem; var charCollection = collection as ICharacterCollection; if (eq != null && charCollection != null) { eq.equippedToCollection = charCollection; eq.NotifyItemEquipped(charCollection.equippableSlots[eq.index], eq.currentStackSize); } } collection.UnRegisterCurrencyEvents(); collection.currenciesGroup = new CurrencyDecoratorCollection(false); var deserializedCurrencies = currencies.Select(o => o.ToCurrencyDecorator()); foreach (var c in deserializedCurrencies) { collection.currenciesGroup.AddCurrency(c); } collection.RegisterCurrencyEvents(); }
public T FindElement <T>(string collectionName, bool warnWhenNotFound) where T : ItemCollectionBase { if (string.IsNullOrEmpty(collectionName)) { return(null); } var a = ItemCollectionBase.FindByName <T>(collectionName); if (a == null && warnWhenNotFound) { Debug.LogWarning("Player instantiation :: Collection with name (" + collectionName + ") not found!"); } return(a); }
public virtual InventoryItemBase ToItem() { if (itemID < 0 || itemID > ItemManager.database.items.Length - 1) { // DevdogLogger.LogWarning("ItemID is out of range, trying to deserialize item " + itemID); return(null); } var item = ItemManager.database.items[itemID]; var inst = UnityEngine.Object.Instantiate <InventoryItemBase>(item); var s = this.stats.Select(o => o.ToStat()).ToArray(); inst.currentStackSize = amount; inst.stats = s; if (string.IsNullOrEmpty(collectionName) == false) { inst.itemCollection = ItemCollectionBase.FindByName(collectionName); } return(inst); }