public void Insert() { if (recipient) { CollectionData[] cdata = recipient.GetComponents <CollectionData>(); for (int i = 0; i < cdata.Length; i++) { CollectionData coldat = cdata[i]; // find the collection we should insert into, by name if (coldat.name == collectionName) { coldat.Insert(this); // really, only activate passive aspects if we // successfully inserted into inventory IsPassive pas = GetComponent <IsPassive>(); if (pas) { pas.Activate(); pas.SetRecipient(this.GetRecipient()); } Hide(); break; } } } }
public bool AddToInventory(GameObject newParent) { InventoryData[] inventories = newParent.GetComponentsInChildren <InventoryData>(); for (int i = 0; i < inventories.Length; i++) { if (inventories[i].inventoryName == this.inventoryName) { CollectionData collection = inventories[i].GetCollectionByName(collectionName); if (collection != null) { collection.Insert(this); this.gameObject.SetActive(false); // check for other mixins here? IsEquipable equipable = this.GetComponent <IsEquipable>(); if (equipable) { equipable.AttachToSlot(newParent); } return(true); } else { Debug.Log("No collection " + collectionName + " on touched GameObject " + newParent.name + "."); return(false); } } } Debug.Log("No inventory " + inventoryName + " on touched GameObject " + newParent.name + "."); return(false); }