Problem : Les unités et bâtiments ne coutaient rien à construire Solution : J'ai link le système de drag and drop au resource manager. Note : J'ai déshérité le ResourceManager de MonoBehaviour aussi, vu que c'est pas une fonctionalité qui nécessite d'être updaté par frame vraiment, c'est plus du stockage. J'ai testé dans l'éditeur et tout semble fonctionel *fingers crossed*
66 lines
1.5 KiB
C#
66 lines
1.5 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Sert d'inventaire et gère l'accès aux ressources
|
|
/// </summary>
|
|
public class ResourceManager : Singleton<ResourceManager>
|
|
{
|
|
private static ResourceManager _instance = null;
|
|
private int _rockAmount = 20;
|
|
private int _woodAmount = 20;
|
|
private int _foodAmount = 20;
|
|
|
|
private const int MAX = 100;
|
|
private const int MIN = 0;
|
|
|
|
public int RockAmount
|
|
{
|
|
set
|
|
{
|
|
if (_rockAmount + value < MAX)
|
|
{
|
|
_rockAmount += value;
|
|
}
|
|
}
|
|
get { return _rockAmount; }
|
|
}
|
|
public int WoodAmount
|
|
{
|
|
set
|
|
{
|
|
if (_woodAmount + value < MAX)
|
|
{
|
|
_woodAmount += value;
|
|
}
|
|
}
|
|
get { return _woodAmount; }
|
|
}
|
|
public int FoodAmount
|
|
{
|
|
set
|
|
{
|
|
if (_foodAmount + value < MAX)
|
|
{
|
|
_foodAmount += value;
|
|
}
|
|
}
|
|
get { return _foodAmount; }
|
|
}
|
|
|
|
public void Remove(int rock, int wood, int food)
|
|
{
|
|
_rockAmount = (_rockAmount - rock) < MIN ? MIN : _rockAmount - rock;
|
|
_woodAmount = (_woodAmount - wood) < MIN ? MIN : _woodAmount - wood;
|
|
_foodAmount = (_foodAmount - food) < MIN ? MIN : _foodAmount - food;
|
|
}
|
|
|
|
public bool EnoughFor(int rock, int wood, int food = 0)
|
|
{
|
|
if (_rockAmount >= rock && _woodAmount >= wood && _foodAmount >= food)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|