Files
MRArcadia/Assets/_Arcadia/Scripts/Item/CoinManager.cs
2026-03-27 17:18:46 +08:00

97 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using DragonLi.Core;
using UnityEngine;
/// <summary>
/// 硬币管理器
/// </summary>
public class CoinManager : MonoBehaviour
{
public static CoinManager Ins { get; private set; }
[Header("硬币总数")]
[SerializeField] private int totalCoins = 8;
[Header("硬币台")]
[SerializeField] private CoinPlatform coinPlatform;
private int nextSlotIndex = 0;
private int collectedCount = 0;
private void Awake()
{
Ins = this;
}
private void Start()
{
// 查找硬币台
if (coinPlatform == null)
{
coinPlatform = FindObjectOfType<CoinPlatform>();
if (coinPlatform == null)
{
Debug.LogWarning("场景中未找到CoinPlatform");
}
}
}
/// <summary>
/// 获取下一个可用插槽索引
/// </summary>
public int GetNextSlotIndex()
{
if (nextSlotIndex >= totalCoins)
{
Debug.LogWarning("所有硬币插槽已被占用!");
return -1;
}
int index = nextSlotIndex;
nextSlotIndex++;
collectedCount++;
return index;
}
/// <summary>
/// 获取已收集的硬币数量
/// </summary>
public int GetCollectedCount()
{
return collectedCount;
}
/// <summary>
/// 获取剩余硬币数量
/// </summary>
public int GetRemainingCount()
{
return totalCoins - collectedCount;
}
/// <summary>
/// 检查是否收集满
/// </summary>
public bool IsFullyCollected()
{
return collectedCount >= totalCoins;
}
/// <summary>
/// 重置硬币系统
/// </summary>
public void ResetCoinSystem()
{
nextSlotIndex = 0;
collectedCount = 0;
Debug.Log("硬币系统已重置");
}
/// <summary>
/// 获取硬币台
/// </summary>
public CoinPlatform GetCoinPlatform()
{
return coinPlatform;
}
}