See the design doc first for more info on the design of the system.
The crafting system script handle storing all possible recipe.
Recipes are organised in an efficient manner that allow to search very fast through them, given we know the target of the recipe and the name of the interaction to execute it.
It's using the following structure :
The system starts by looking for all recipes in the recipe asset database and fill the structure.
Both client and server have access to the full recipe list.
The other major element of the system is the crafting interaction abstract class. When you want to add a new interaction, inherit from it, as it will provide the basis for what you need, if you want to implement a new interaction that will result in crafting something.
You can use the SliceInteraction.cs
script as an implementation example. Notice how the code override the CanCraft method, so it can add its own conditions to allow this specific crafting.
For a crafting interaction to work in game, the interaction needs to be put on an item that will act as the source of that interaction.
In the case of the slice interaction, we could add it to a knife, or any other slicy item. For that, we create a new script that inherits from IInteractionSource :
Just put that script on your knife game object and you're good to go. See how it creates a new sliceInteraction.
Recipes are simple scriptable objects in Assets/Content/Data/Recipes currently. Easy to set up.
Creating a new recipe is very simple :
You can then fill up the recipe with everything it needs. Should be explicit enough.
If you want your recipe to be accessible in game though, you'll need to add it to the recipe asset database.