Currently for this crafting system I've got two lists, one containing the list of output objects and one holding a scriptable object that points to the object prefab for that item, with a dictionary mapping different crafting methods to these items. However I really don't like how I'm assigning the dictionaries, as changing the list in the inspector in any way, will ruin the whole thing. Is there some better approach to take here so that crafting is consistent and doesn't require as much reopening and editing to change?
using Inventory.Model;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CraftingManager : MonoBehaviour
{
public InventoryManager inventoryManager;
public RawInventorySO rawInventory;
public ProcessedInventorySO processedInventory;
public List<ImmutableItemSO> itemPrefabs = new List<ImmutableItemSO>();
public List<ProcessedItemSO> outputItems = new List<ProcessedItemSO>();
public Dictionary<CraftMethod, ProcessedItemSO> craftToItem = new Dictionary<CraftMethod, ProcessedItemSO>();
public List<ImmutableItemSO> itemTemplates = new List<ImmutableItemSO>();
public Dictionary<CraftMethod, ImmutableItemSO> craftToTemplate = new Dictionary<CraftMethod, ImmutableItemSO>();
public static CraftMethod craftMethod;
void Start()
{
craftToItem.Add(CraftMethod.RodCraft, outputItems[1]);
craftToItem.Add(CraftMethod.CuboidCraft, outputItems[0]);
craftToItem.Add(CraftMethod.PlateCraft, outputItems[2]);
craftToTemplate.Add(CraftMethod.RodCraft, itemTemplates[1]);
craftToTemplate.Add(CraftMethod.CuboidCraft, itemTemplates[0]);
craftToTemplate.Add(CraftMethod.PlateCraft, itemTemplates[2]);
}
public void ProcessInput(GameObject inputObject)
{
if (inputObject.CompareTag("RawMaterial"))
{
switch (craftMethod)
{
case CraftMethod.RodCraft:
ProcessedItemSO newRodItem = craftToItem[CraftMethod.RodCraft];
newRodItem.itemTemplate = craftToTemplate[CraftMethod.RodCraft];
processedInventory.AddItem(craftToItem[CraftMethod.RodCraft], 1);
Destroy(inputObject);
break;
case CraftMethod.CuboidCraft:
ProcessedItemSO newCuboidItem = craftToItem[CraftMethod.CuboidCraft];
newCuboidItem.itemTemplate = craftToTemplate[CraftMethod.CuboidCraft];
processedInventory.AddItem(craftToItem[CraftMethod.CuboidCraft], 1);
Destroy(inputObject);
break;
case CraftMethod.PlateCraft:
ProcessedItemSO newPlateItem = craftToItem[CraftMethod.PlateCraft];
newPlateItem.itemTemplate = craftToTemplate[CraftMethod.PlateCraft];
processedInventory.AddItem(craftToItem[CraftMethod.PlateCraft], 1);
Destroy(inputObject);
break;
default:
Destroy(inputObject);
break;
}
}
}
}