Permet la gestion, la création et la prise en charge du cout des resources respectivement.
78 lines
1.7 KiB
C#
78 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Sert d'inventaire et gère l'accès aux ressources
|
|
/// </summary>
|
|
public class ResourceManager : MonoBehaviour
|
|
{
|
|
private static ResourceManager _instance = null;
|
|
private int _rockAmount = 0;
|
|
private int _woodAmount = 0;
|
|
private int _foodAmount = 0;
|
|
|
|
private const int MAX = 100;
|
|
private const int MIN = 0;
|
|
|
|
public ResourceManager() { }
|
|
|
|
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 static ResourceManager getInstance()
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = new ResourceManager();
|
|
}
|
|
return _instance;
|
|
}
|
|
|
|
public void Remove(int rock, int wood, int food)
|
|
{
|
|
_rockAmount = _rockAmount - rock < MIN ? MIN : _rockAmount - rock;
|
|
_rockAmount = _rockAmount - wood < MIN ? MIN : _rockAmount - wood;
|
|
_foodAmount = _foodAmount - food < MIN ? MIN : _foodAmount - food;
|
|
}
|
|
|
|
public bool EnoughFor(int rock, int wood, int food = 0)
|
|
{
|
|
if (rock > _rockAmount || wood > _woodAmount || food > _foodAmount)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|