Ader Alisma 01 8ecf5e0552 Ajout des Yield prefabs et de ResourceMaker
ResourceMaker détecte le click sur le Yield

Les yields font partis du ResourceTile
2023-06-11 10:45:01 -04:00

117 lines
2.6 KiB
C#

using UnityEngine;
using System.Collections;
/// <summary>
/// Sert d'inventaire et gère l'accès aux ressources
/// </summary>
public class ResourceManager : MonoBehaviour
{
private static ResourceManager _instance = null;
[SerializeField][Range(0.0f, 10.0f)]
private float _randoLimiter = 5.0f;
[SerializeField]
private GameObject _dropPrefab;
private int _rockAmount = 20;
private int _woodAmount = 20;
private int _foodAmount = 20;
public enum ResourceChoice
{
Rock,
Wood,
Food
};
public enum AddOrRemove
{
Add,
Remove
};
private const int MAX = 100;
private const int MIN = 0;
public ResourceManager() { }
public static ResourceManager Instance
{
get
{
return _instance;
}
}
private void Awake()
{
if (_instance != null && _instance != this)
{
Destroy(this);
}
else
{
_instance = this;
}
}
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;
}
public void SpawnResource(ResourceChoice type, Vector2 position)
{
//Instantiate prefab at random position
//var position = new Vector3(Random.Range(-10.0f, 10.0f), 0, Random.Range(-10.0f, 10.0f));
//Instantiate(prefab, position, Quaternion.identity);
Vector3 droppedPosition = new Vector3(Random.Range(-1.0f, 1.0f),-1.0f);
Instantiate(_dropPrefab, droppedPosition, Quaternion.identity);
}
}