/// <summary>
/// Crafting Recipe with currency included.
/// </summary>
[OverrideCraftingIngredients(typeof(CraftingIngredientsWithCurrency))]
public class CraftingRecipeWithCurrency : CraftingRecipe
{
/// <summary>
/// Makes sure that the ingredients are of the correct type.
/// </summary>
protected override void DeserializeIngredientsInternal()
{
if (m_Ingredients.GetType() == typeof(CraftingIngredientsWithCurrency)) { return; }
var previousIngredients = m_Ingredients;
m_Ingredients = new CraftingIngredientsWithCurrency();
ReflectionUtility.ObjectCopy(previousIngredients, m_Ingredients);
}
}
public class CraftingRecipeWithTime : CraftingRecipe
{
[SerializeField] protected float m_CraftTime;
public float CraftTime => m_CraftTime;
}
var craftinRecipeWithTime = recipe as CraftingRecipeWithTime;
if(craftinRecipeWithTime != null){
var craftTime = craftinRecipeWithTime.CraftTime;
//Do the crafting using time
}
//var output = CreateCraftingOutput(recipe, inventory, quantity);
// Example using the scheduler to call the function after 2 seconds.
// () => {} is called a lambda function. You can learn more about lambda and delegates online.
Scheduler.Schedule(2f, () => CreateCraftingOutput(recipe, inventory, quantity));
// You can't know the result right now because the crafting hasn't finished.
// You could predict the result if you need to, but i don't think you will. So just return success with no crafting output.
return new CraftingResult(null, true);
hiii, Thanks! think i managed to get the processor working using the default craft UI atm after trying for a while, it removes the ingredients then waits then gives the item in Inventory, not sure if this is fully correct but seems to work so far...Just like cptscrimshaw asked before above. What you need is to run a loop asynchonsouly. Here I explained three solutions
How to craft items with using time?
I want to craft a items using crafting cool time like Minecraft. Can I do that with UIS?opsive.com
You'll need a custom UI for this. You can either write it from scratch or inherit Crafting Menu and override the different functions
In steps
1) Start crafting process if can start (don't actually craft yet, just remove the items)
2) Run a wait time loop aysnchonrously using coroutine
3) Use an image with a fill amount showing the percentage progress
4) Actually craft the item after the time has passed
It is up to you if you want to only have item item crafting at any time and if you can stop the crafting mid way.
Note that this requires a faire amount of custom code. So start simple and add things bit by bit as things start to work and make sense.
using Opsive.Shared.Game;
using Opsive.Shared.Utility;
using Opsive.UltimateInventorySystem.Core.DataStructures;
using Opsive.UltimateInventorySystem.Core.InventoryCollections;
using Opsive.UltimateInventorySystem.Crafting;
using Opsive.UltimateInventorySystem.Crafting.Processors;
public class SmeltingProcessor : SimpleCraftingProcessor
{
private float craftTime;
private float progressPercent;
protected override CraftingResult CraftInternal(CraftingRecipe recipe, IInventory inventory,
ListSlice<ItemInfo> selectedIngredients, int quantity)
{
if (CanCraftInternal(recipe, inventory, selectedIngredients, quantity) == false)
{
return new CraftingResult(null, false);
}
else
{
if (RemoveIngredients(inventory, selectedIngredients) == false)
{
return new CraftingResult(null, false);
}
if(recipe is SmeltingRecipe smeltingRecipe)
{
craftTime = smeltingRecipe.CraftTime;
}
Scheduler.Schedule(craftTime, () => CreateCraftingOutput(recipe, inventory, quantity));
return new CraftingResult(null, true);
}
}
}