70 lines
1.9 KiB
C#
70 lines
1.9 KiB
C#
|
|
using System;
|
||
|
|
using System.Text;
|
||
|
|
using OTGIntegrated.Items;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace OTGIntegrated.Crafting
|
||
|
|
{
|
||
|
|
[Serializable]
|
||
|
|
public sealed class Ingredient
|
||
|
|
{
|
||
|
|
public ItemData item;
|
||
|
|
[Min(1)] public int amount = 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
[CreateAssetMenu(fileName = "RecipeData", menuName = "OTG Integrated/Recipe Data")]
|
||
|
|
public sealed class RecipeData : ScriptableObject
|
||
|
|
{
|
||
|
|
public string recipeId;
|
||
|
|
public string displayName;
|
||
|
|
[TextArea(2, 5)] public string description;
|
||
|
|
public Ingredient[] ingredients;
|
||
|
|
public ItemData resultItem;
|
||
|
|
[Min(1)] public int resultAmount = 1;
|
||
|
|
|
||
|
|
private void OnValidate()
|
||
|
|
{
|
||
|
|
if (string.IsNullOrWhiteSpace(recipeId))
|
||
|
|
{
|
||
|
|
recipeId = name;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (string.IsNullOrWhiteSpace(displayName))
|
||
|
|
{
|
||
|
|
displayName = recipeId;
|
||
|
|
}
|
||
|
|
|
||
|
|
resultAmount = Mathf.Max(1, resultAmount);
|
||
|
|
}
|
||
|
|
|
||
|
|
public string GetIngredientsText()
|
||
|
|
{
|
||
|
|
if (ingredients == null || ingredients.Length == 0)
|
||
|
|
{
|
||
|
|
return "Без ингредиентов";
|
||
|
|
}
|
||
|
|
|
||
|
|
StringBuilder builder = new StringBuilder();
|
||
|
|
for (int i = 0; i < ingredients.Length; i++)
|
||
|
|
{
|
||
|
|
Ingredient ingredient = ingredients[i];
|
||
|
|
if (ingredient == null || ingredient.item == null)
|
||
|
|
{
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (builder.Length > 0)
|
||
|
|
{
|
||
|
|
builder.Append(", ");
|
||
|
|
}
|
||
|
|
|
||
|
|
builder.Append(ingredient.item.displayName);
|
||
|
|
builder.Append(" x");
|
||
|
|
builder.Append(ingredient.amount);
|
||
|
|
}
|
||
|
|
|
||
|
|
return builder.Length == 0 ? "Без ингредиентов" : builder.ToString();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|