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:
parent
4367e2e48c
commit
3e00af6067
File diff suppressed because it is too large
Load Diff
@ -4,8 +4,10 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class ResourceMaker : MonoBehaviour
|
public class ResourceMaker : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private int _resourceMakingAmount;
|
[SerializeField]
|
||||||
[SerializeField] private ResourceChoice _resourceChoice;
|
private int _resourceMakingAmount;
|
||||||
|
[SerializeField]
|
||||||
|
private ResourceChoice _resourceChoice;
|
||||||
|
|
||||||
private ResourceManager _resourceManager;
|
private ResourceManager _resourceManager;
|
||||||
private enum ResourceChoice
|
private enum ResourceChoice
|
||||||
@ -17,8 +19,8 @@ public class ResourceMaker : MonoBehaviour
|
|||||||
|
|
||||||
public void GenerateResource()
|
public void GenerateResource()
|
||||||
{
|
{
|
||||||
_resourceManager = ResourceManager.getInstance();
|
_resourceManager = ResourceManager.Instance;
|
||||||
Make();
|
StartCoroutine(Make());
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator Make()
|
private IEnumerator Make()
|
||||||
@ -37,7 +39,9 @@ public class ResourceMaker : MonoBehaviour
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
yield return new WaitForSecondsRealtime(3);
|
Debug.Log("Generating...");
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(3f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopGenerate()
|
public void StopGenerate()
|
||||||
|
|||||||
@ -14,6 +14,25 @@ public class ResourceManager : MonoBehaviour
|
|||||||
private const int MIN = 0;
|
private const int MIN = 0;
|
||||||
|
|
||||||
public ResourceManager() { }
|
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
|
public int RockAmount
|
||||||
{
|
{
|
||||||
@ -49,15 +68,6 @@ public class ResourceManager : MonoBehaviour
|
|||||||
get { return _foodAmount; }
|
get { return _foodAmount; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceManager getInstance()
|
|
||||||
{
|
|
||||||
if (_instance == null)
|
|
||||||
{
|
|
||||||
_instance = new ResourceManager();
|
|
||||||
}
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Remove(int rock, int wood, int food)
|
public void Remove(int rock, int wood, int food)
|
||||||
{
|
{
|
||||||
_rockAmount = _rockAmount - rock < MIN ? MIN : _rockAmount - rock;
|
_rockAmount = _rockAmount - rock < MIN ? MIN : _rockAmount - rock;
|
||||||
|
|||||||
@ -2,6 +2,7 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
|
using TMPro;
|
||||||
|
|
||||||
public class ResourceRemover : MonoBehaviour
|
public class ResourceRemover : MonoBehaviour
|
||||||
{
|
{
|
||||||
@ -16,24 +17,14 @@ public class ResourceRemover : MonoBehaviour
|
|||||||
private int _food;
|
private int _food;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Button _button;
|
private TextMeshProUGUI _text;
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
private TextField _text;
|
|
||||||
|
|
||||||
private ResourceManager _resourceManager;
|
private ResourceManager _resourceManager;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
_resourceManager = ResourceManager.getInstance();
|
_resourceManager = ResourceManager.Instance;
|
||||||
|
|
||||||
_button.clicked += () =>
|
|
||||||
{
|
|
||||||
//Will remove resources as well as execute placement action defined in the Editors
|
|
||||||
_resourceManager.Remove(_rock, _wood, _food);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// 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
|
//checks if player has enough resources then chooses state of button's availability
|
||||||
|
|
||||||
StyleColor textColor = _text.style.color;
|
if (_resourceManager.EnoughFor(_rock, _wood, _food))
|
||||||
if (_resourceManager.EnoughFor(_rock, _wood, _food) && textColor == Color.red)
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
Assets/Scripts/ResourceText.cs
Normal file
31
Assets/Scripts/ResourceText.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/ResourceText.cs.meta
Normal file
11
Assets/Scripts/ResourceText.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3ced676faf99a7648b5650ee8a1c60bd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user