Add Shop system with ShopManager, ShopUI, and ShopSlotUI; implement item purchasing and shop UI functionality
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
using Interfaces;
|
||||
using Sirenix.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
public class EnemyDeathBehavior : MonoBehaviour, IDeathBehavior
|
||||
{
|
||||
[OdinSerialize, SerializeField] private int expReward = 5;
|
||||
[OdinSerialize, SerializeField] private int coinReward = 1;
|
||||
|
||||
public void Die()
|
||||
{
|
||||
GameManager.Instance.Player.attributes.ModifyExperience(expReward);
|
||||
GameManager.Instance.AddCoins(coinReward);
|
||||
Destroy(gameObject);
|
||||
|
||||
// later let's add particle effects, sound effects, etc.
|
||||
// and give player experience points
|
||||
}
|
||||
}
|
||||
}
|
88
Assets/Scripts/Systems/GameManager.cs
Normal file
88
Assets/Scripts/Systems/GameManager.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Data;
|
||||
using Sirenix.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
private float timer;
|
||||
|
||||
public static GameManager Instance { get; private set; }
|
||||
|
||||
[OdinSerialize, SerializeField] private int currentRound = 1;
|
||||
[OdinSerialize, SerializeField] private int coins = 0;
|
||||
[OdinSerialize, SerializeField] private float roundTime = 60f;
|
||||
[OdinSerialize, SerializeField] private int maxRounds = 20;
|
||||
|
||||
[OdinSerialize, SerializeField] private Character player;
|
||||
|
||||
public Character Player => player;
|
||||
public int Coins => coins;
|
||||
public int CurrentRound => currentRound;
|
||||
public float RoundTime => roundTime;
|
||||
public int MaxRounds => maxRounds;
|
||||
public bool StoreIsClosed { get; set; } = true;
|
||||
|
||||
public event Action<int> OnRoundStart;
|
||||
public event Action<int> OnRoundEnd;
|
||||
public event Action OnStoreOpen;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartCoroutine(RoundLoop());
|
||||
}
|
||||
|
||||
private IEnumerator RoundLoop()
|
||||
{
|
||||
OnStoreOpen?.Invoke();
|
||||
yield return new WaitUntil(() => StoreIsClosed);
|
||||
|
||||
for (currentRound = 1; currentRound <= maxRounds; currentRound++)
|
||||
{
|
||||
OnRoundStart?.Invoke(currentRound);
|
||||
timer = roundTime;
|
||||
|
||||
while (timer > 0)
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
OnRoundEnd?.Invoke(currentRound);
|
||||
StoreIsClosed = false;
|
||||
OnStoreOpen?.Invoke();
|
||||
yield return new WaitUntil(() => StoreIsClosed);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddCoins(int amount)
|
||||
{
|
||||
coins += amount;
|
||||
}
|
||||
|
||||
public void SpendCoins(int amount)
|
||||
{
|
||||
if (coins >= amount)
|
||||
{
|
||||
coins -= amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Systems/GameManager.cs.meta
Normal file
3
Assets/Scripts/Systems/GameManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41ea29e7d7d04eb5be628e56520e9bbd
|
||||
timeCreated: 1752271597
|
Reference in New Issue
Block a user