Pull request #8: Feature/gestionRessource

Merge in CGD/gather-and-defend from feature/gestionRessource to main

* commit 'd8490535960e2f99e8ea37e87fefeddb83736391':
  SUppression de ResourceMaker et mise à jour de la scène de test des ressources
  Changer le comportement de ResourceMaker et ajout de commentaires
  Avancement sur coroutine de génération de ressources.
  Update sur scene de TestResource
  Debut de la scene de TestResource
  Creation de ResourceManager, ResourceMaker et ResourceRemover
This commit is contained in:
Ader Alisma 01 2023-05-27 13:46:41 +00:00
commit 7851a46c7f
8 changed files with 2159 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 904f54d590ea9a542b03b82ca0aa1a01
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,96 @@
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;
private int _rockAmount = 20;
private int _woodAmount = 20;
private int _foodAmount = 20;
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;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 45e6e814b8c91334ca1d6d0e7f530fef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,69 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using TMPro;
/// <summary>
/// Gère le retrait de ressources et l'état du bouton
/// Si les ressources nécessaires sont atteints, ce script change la disponibilité du bouton
/// et vice-versa
/// </summary>
public class ResourceRemover : MonoBehaviour
{
[SerializeField]
private int _rock;
[SerializeField]
private int _wood;
[SerializeField]
private int _food;
[SerializeField]
private TextMeshProUGUI _text;
private ResourceManager _resourceManager;
// Start is called before the first frame update
void Start()
{
_resourceManager = ResourceManager.Instance;
}
// Update is called once per frame
void Update()
{
ChangeAvailability();
}
private void ChangeAvailability()
{
//checks if player has enough resources then changes the state of button's availability
if (_resourceManager.EnoughFor(_rock, _wood, _food))
{
if (_text.color != Color.green)
{
_text.color = Color.green;
Debug.Log("Changed to green...");
}
}
else if (_text.color != Color.red)
{
_text.color = Color.red;
Debug.Log("Changed to red...");
}
}
public void Remove()
{
if (_text.color == Color.green)
{
Debug.Log("Removed items...");
_resourceManager.Remove(_rock, _wood, _food);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: adc0c9da23034d342aec05775f0bd941
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
/// <summary>
/// Gère l'affichage des resources
/// </summary>
public class ResourceText : MonoBehaviour
{
[SerializeField]
private TextMeshProUGUI _rockText;
[SerializeField]
private TextMeshProUGUI _woodText;
[SerializeField]
private TextMeshProUGUI _foodText;
private ResourceManager _resourceManager;
// Start is called before the first frame update
void Start()
{
_resourceManager = ResourceManager.Instance;
}
// Update is called once per frame
void Update()
{
_rockText.text = _resourceManager.RockAmount.ToString();
_woodText.text = _resourceManager.WoodAmount.ToString();
_foodText.text = _resourceManager.FoodAmount.ToString();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3ced676faf99a7648b5650ee8a1c60bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: