added Game UI Controller

Show money on UI, buy items
This commit is contained in:
Vladimir Koshevarov
2022-10-18 16:55:38 +03:00
parent 32cdf47d4a
commit fc8393b29f
6 changed files with 78 additions and 17 deletions
+19 -3
View File
@@ -2770,7 +2770,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
_timeMultiplier: 2000
_startHour: 12
_timeText: {fileID: 2089282903}
_sunLight: {fileID: 705507994}
_sunriseHour: 7
_sunsetHour: 20.5
@@ -2839,6 +2838,7 @@ GameObject:
- component: {fileID: 329780515}
- component: {fileID: 329780514}
- component: {fileID: 329780513}
- component: {fileID: 329780517}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
@@ -2931,6 +2931,22 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &329780517
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 329780512}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2649ed9748ff3864880311f1c2aecdef, type: 3}
m_Name:
m_EditorClassIdentifier:
_dateTimeController: {fileID: 307039699}
_playerController: {fileID: 858145505}
_timeText: {fileID: 2089282903}
_moneyText: {fileID: 443940496}
--- !u!1 &353014637
GameObject:
m_ObjectHideFlags: 0
@@ -3152,7 +3168,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: New Text
m_text: Money
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
@@ -7466,7 +7482,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: New Text
m_text: TimeText
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
+7 -4
View File
@@ -2,14 +2,17 @@
{
public class Eat : BaseAction
{
private int energyPerTick;
public Eat(int duration, int energyPerTick, double cost) : base(duration)
private double _price;
private int _energyPerTick;
public Eat(int duration, int energyPerTick, double price) : base(duration)
{
this.energyPerTick = energyPerTick;
_price = price;
_energyPerTick = energyPerTick;
}
public override void ApplyAction(PlayerController playerController)
{
playerController.foodEnergy.increase(energyPerTick);
playerController.foodEnergy.increase(_energyPerTick);
playerController.money.deduct(_price);
}
}
}
+3 -9
View File
@@ -1,5 +1,4 @@
using System;
using TMPro;
using UnityEngine;
public class DateTimeController : MonoBehaviour
@@ -10,9 +9,6 @@ public class DateTimeController : MonoBehaviour
[SerializeField]
private float _startHour;
[SerializeField]
private TextMeshProUGUI _timeText;
[SerializeField]
private Light _sunLight;
@@ -43,6 +39,9 @@ public class DateTimeController : MonoBehaviour
private TimeSpan _sunsetTime;
private DateTime _currentTime;
public DateTime CurrentTime => _currentTime;
// Start is called before the first frame update
void Start()
{
@@ -61,11 +60,6 @@ public class DateTimeController : MonoBehaviour
private void UpdateTime()
{
_currentTime = _currentTime.AddSeconds(Time.deltaTime * _timeMultiplier);
if (_timeText != null)
{
_timeText.text = _currentTime.ToString("HH:mm");
}
}
private void RotateSun()
+37
View File
@@ -0,0 +1,37 @@
using TMPro;
using UnityEngine;
public class GameUIController : MonoBehaviour
{
[SerializeField]
private DateTimeController _dateTimeController;
[SerializeField]
private PlayerController _playerController;
[SerializeField]
private TextMeshProUGUI _timeText;
[SerializeField]
private TextMeshProUGUI _moneyText;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
_moneyText.text = $"Money: {_playerController.money.Value}$";
UpdateTime();
}
private void UpdateTime()
{
if (_timeText != null)
{
_timeText.text = _dateTimeController.CurrentTime.ToString("HH:mm");
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2649ed9748ff3864880311f1c2aecdef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+1 -1
View File
@@ -3,7 +3,7 @@ using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Stat money = new Stat("Money", 1000.00);
public Stat money = new Stat("Money", 100.00);
public Stat rentAccount = new Stat("Rent Account", 0);
public Stat foodEnergy = new Stat("Food Energy", 0);
public Stat restEnergy = new Stat("Rest Energy", 0);