добил ресурсы. Теперь правильно привязаны к ресурсам. начал делать скрипты на строения домов
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
[System.Serializable]
|
||||
public class ResourceCost
|
||||
{
|
||||
public ResourceType type;
|
||||
public float amount;
|
||||
}
|
||||
[CreateAssetMenu(fileName = "NewBuilding", menuName = "Game/Building Data")]
|
||||
public class BuildingData : ScriptableObject
|
||||
{
|
||||
[Header("Основное")]
|
||||
public string buildingName;
|
||||
public Sprite icon;
|
||||
public GameObject prefab;
|
||||
|
||||
[Header("Требования")]
|
||||
[Tooltip("Необходимый уровень ратуши")]
|
||||
public int requiredTowmHallLevel = 1;
|
||||
|
||||
[Header("Стоимость")]
|
||||
public ResourceCost[] cost;
|
||||
|
||||
// Проверка - хватает ли ресурсов? (только проверяет)
|
||||
public bool CanAfford()
|
||||
{
|
||||
if (ResourceManager.Instance == null) return false;
|
||||
|
||||
foreach (var c in cost)
|
||||
{
|
||||
if (!ResourceManager.Instance.HasEnough(c.type, c.amount))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Списывает стоимость постройки. Вызывать только после CanAfford() == true
|
||||
public void PayCost()
|
||||
{
|
||||
foreach (var c in cost)
|
||||
{
|
||||
ResourceManager.Instance.TrySpend(c.type, c.amount);
|
||||
}
|
||||
}
|
||||
|
||||
// Текст стоимости для UI, например "50 Wood, 20 Stone"
|
||||
public string GetCostText()
|
||||
{
|
||||
string result = "";
|
||||
for (int i = 0; i < cost.Length; i++)
|
||||
{
|
||||
result += $"{cost[i].amount} {cost[i].type}";
|
||||
if (i < cost.Length - 1) result += ", ";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user