Add Shop system with ShopManager, ShopUI, and ShopSlotUI; implement item purchasing and shop UI functionality

This commit is contained in:
2025-07-12 02:07:43 +02:00
parent 8f3a913b7e
commit ad02e07a87
15 changed files with 753 additions and 3 deletions

View File

@@ -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
}
}
}

View 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;
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 41ea29e7d7d04eb5be628e56520e9bbd
timeCreated: 1752271597