public void EditorGenerateEmptyInventory() { inventory.Clear(); inventory.TrimExcess(); for (int i = 0; i < inventoryMaxSize; i++) { Unit_Item newItem = ScriptableObject.CreateInstance <Unit_Item>(); newItem.Initialize(); #if UNITY_EDITOR AssetDatabase.AddObjectToAsset(newItem, inventory_Path); #endif inventory.Add(newItem); } }
public void EditorStractureIntoSubAssets() { bool equals = inventoryStracture.Count != inventory.Count; foreach (Unit_Item item in inventoryStracture) { if (equals) { Unit_Item newItem = ScriptableObject.CreateInstance <Unit_Item>(); newItem.name = item.name; newItem.Initialize(item.item_Icon, item.item_Text, item.isWearable, item.basePrice); #if UNITY_EDITOR AssetDatabase.AddObjectToAsset(newItem, inventory_Path); #endif inventory.Add(newItem); equals = inventoryStracture.Count != inventory.Count; } } }
public static void TradeItem(Unit_Item item, Unit_InventoryReader removeFromInv, Unit_InventoryReader addToInv) { Unit_Item tempItem = (Unit_Item)Resources.Load("Items/" + item.name); tempItem.name = item.name; tempItem.Initialize(item.item_Icon, item.item_Text, item.isWearable, item.basePrice); int invIndex = removeFromInv.inventory.FindIndex(i => i.name == item.name); int strIndex = removeFromInv.inventoryStracture.FindIndex(i => i.name == item.name); removeFromInv.inventory[invIndex].ResetItem(); removeFromInv.inventoryStracture.RemoveAt(strIndex); foreach (Unit_Item i in addToInv.inventory) { if (string.IsNullOrWhiteSpace(i.name)) { i.Initialize(tempItem.item_Icon, tempItem.item_Text, tempItem.isWearable, tempItem.basePrice); break; } } addToInv.inventoryStracture.Add((Unit_Item)Resources.Load("Items/" + tempItem.name)); }