Update sur scene de TestResource

Ajout de ResourceText. Permet de montrer l'inventaire des ressources dynamiquement.

Modification de la gestion d'instance dans ResourceManager

Changement des boutons pour la version TextMeshPro

Debut de la coroutine de ResourceMaker
This commit is contained in:
Ader Alisma 01 2023-05-20 18:50:27 -04:00
parent 4367e2e48c
commit 3e00af6067
6 changed files with 673 additions and 666 deletions

File diff suppressed because it is too large Load Diff

View File

@ -4,8 +4,10 @@ using UnityEngine;
public class ResourceMaker : MonoBehaviour
{
[SerializeField] private int _resourceMakingAmount;
[SerializeField] private ResourceChoice _resourceChoice;
[SerializeField]
private int _resourceMakingAmount;
[SerializeField]
private ResourceChoice _resourceChoice;
private ResourceManager _resourceManager;
private enum ResourceChoice
@ -17,8 +19,8 @@ public class ResourceMaker : MonoBehaviour
public void GenerateResource()
{
_resourceManager = ResourceManager.getInstance();
Make();
_resourceManager = ResourceManager.Instance;
StartCoroutine(Make());
}
private IEnumerator Make()
@ -37,7 +39,9 @@ public class ResourceMaker : MonoBehaviour
default:
break;
}
yield return new WaitForSecondsRealtime(3);
Debug.Log("Generating...");
yield return new WaitForSeconds(3f);
}
public void StopGenerate()

View File

@ -14,6 +14,25 @@ public class ResourceManager : MonoBehaviour
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
{
@ -49,15 +68,6 @@ public class ResourceManager : MonoBehaviour
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;

View File

@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using TMPro;
public class ResourceRemover : MonoBehaviour
{
@ -16,24 +17,14 @@ public class ResourceRemover : MonoBehaviour
private int _food;
[SerializeField]
private Button _button;
[SerializeField]
private TextField _text;
private TextMeshProUGUI _text;
private ResourceManager _resourceManager;
// Start is called before the first frame update
void Start()
{
_resourceManager = ResourceManager.getInstance();
_button.clicked += () =>
{
//Will remove resources as well as execute placement action defined in the Editors
_resourceManager.Remove(_rock, _wood, _food);
};
_resourceManager = ResourceManager.Instance;
}
// Update is called once per frame
@ -46,14 +37,27 @@ public class ResourceRemover : MonoBehaviour
{
//checks if player has enough resources then chooses state of button's availability
StyleColor textColor = _text.style.color;
if (_resourceManager.EnoughFor(_rock, _wood, _food) && textColor == Color.red)
if (_resourceManager.EnoughFor(_rock, _wood, _food))
{
textColor = Color.green;
if (_text.color == Color.red)
{
_text.color = Color.green;
Debug.Log("Changed to green...");
}
}
else if (textColor == Color.green)
else if (_text.color == Color.green)
{
textColor = 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,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
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: