97 lines
2.0 KiB
C#
97 lines
2.0 KiB
C#
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;
|
||
}
|
||
} |