37 lines
1019 B
C#
37 lines
1019 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
public class TimerMgr : MonoBehaviour
|
|
{
|
|
public static TimerMgr Instance { get; private set; }
|
|
public GameObject cooldownTimerPrefab; // 在Inspector中拖入计时器预制体
|
|
private GameObject timerpos;
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject); // 保证管理器在场景之间不被销毁
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
timerpos = GameObject.Find("Canvas");
|
|
|
|
}
|
|
|
|
public void StartCooldown(float cooldownTime, Action onFinished)
|
|
{
|
|
GameObject timer = Instantiate(cooldownTimerPrefab);
|
|
timer.transform.SetParent(timerpos.transform,false);
|
|
SkillCoolDownUI cooldownTimer = timer.GetComponent<SkillCoolDownUI>();
|
|
cooldownTimer.OnCooldownFinished += onFinished; // 订阅冷却结束事件
|
|
cooldownTimer.StartCooldown(cooldownTime);
|
|
}
|
|
|
|
|
|
|
|
}
|