using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TestSkillCD : MonoBehaviour
{
UIFilledSprite mSprCd;//显示CD条
float mfCDTime = 0;
float mfSkillCDTime = 25f;
private UILabel mShowTime;//显示倒计时时间
private int mCurTime = 0;
private float mCloseTime = 0f;
bool m_bIsCdTimer = false;
void ResetCD()
{
mSprCd.enabled = false;
mSprCd.fillAmount = 1.0f;
mfSkillCDTime = 25f;
mfCDTime = mfSkillCDTime;
mCurTime = (int)mfSkillCDTime;
}
bool UpdateCD()//在Update更新函数调用
{
if (mSprCd)
{
if (mfCDTime >= mfSkillCDTime)
{
mSprCd.enabled = false;
return true;
}
mfCDTime += Time.deltaTime;
mSprCd.fillAmount = Mathf.Max(1.0f - mfCDTime / mfSkillCDTime, 0.0f);
mSprCd.enabled = true;
}
return false;
}
void UpdateCdLabel ()//在Update更新函数调用
{
if (m_bIsCdTimer && mShowTime)
{
if ((Time.time - mCloseTime) > 1f && (mCloseTime > 0) && ( mCurTime > 0))
{
mCloseTime = Time.time;
mCurTime = mCurTime - 1;
if (!mShowTime.active)
mShowTime.gameObject.SetActive(true);
mShowTime.text = mCurTime.ToString();
OnCloseCdTimer();
}
}
}
void OnStartCdTimer()//在播放技能后置CD和倒计时开始
{
if (mShowTime)
{
mCloseTime = Time.time;
m_bIsCdTimer = true;
}
if(mSprCd)
{
mfCDTime = 0;
}
}
void OnCloseCdTimer()
{
if (mCurTime == 0)
{
m_bIsCdTimer = false;
mCurTime = (int) mfSkillCDTime;
mCloseTime = 0;
mShowTime.text = "";
if (mShowTime.active)
mShowTime.gameObject.SetActive(false);
}
}
}