61 lines
1.5 KiB
C#
61 lines
1.5 KiB
C#
|
|
using System.Text;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
[System.Serializable]
|
||
|
|
public class Ingredient
|
||
|
|
{
|
||
|
|
public ItemData item;
|
||
|
|
[Min(1)] public int amount = 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
[CreateAssetMenu(fileName = "NewRecipe", menuName = "Crafting/RecipeData")]
|
||
|
|
public class RecipeData : ScriptableObject
|
||
|
|
{
|
||
|
|
public string recipeId;
|
||
|
|
public string recipeName;
|
||
|
|
[TextArea(2, 4)] public string description;
|
||
|
|
public Ingredient[] ingredients;
|
||
|
|
public ItemData result;
|
||
|
|
[Min(1)] public int resultAmount = 1;
|
||
|
|
public bool unlockedByDefault = true;
|
||
|
|
|
||
|
|
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.itemName);
|
||
|
|
builder.Append(" x");
|
||
|
|
builder.Append(ingredient.amount);
|
||
|
|
}
|
||
|
|
|
||
|
|
return builder.Length == 0 ? "Без ингредиентов" : builder.ToString();
|
||
|
|
}
|
||
|
|
|
||
|
|
public string GetResultText()
|
||
|
|
{
|
||
|
|
if (result == null)
|
||
|
|
{
|
||
|
|
return "Нет результата";
|
||
|
|
}
|
||
|
|
|
||
|
|
return result.itemName + " x" + resultAmount;
|
||
|
|
}
|
||
|
|
}
|