Skip to content

Instantly share code, notes, and snippets.

@sunny352
Created August 17, 2015 07:15
Show Gist options
  • Save sunny352/46b22202b03ea230d4e7 to your computer and use it in GitHub Desktop.
Save sunny352/46b22202b03ea230d4e7 to your computer and use it in GitHub Desktop.
Combo计数器
using UnityEngine;
public class ComboCounter
{
public static float CurrentTime { get { return Time.fixedTime; } }
public System.Action onBegin;
public System.Action<int> onIncrease;
public System.Action<int> onEnd;
public float Duration = 1.0f;
private int m_count;
private float m_lastRecordTime;
public void Record()
{
if (0 == m_count)
{
OnBegin();
}
m_lastRecordTime = CurrentTime;
m_count++;
OnIncrease(m_count);
}
public void FixedUpdate()
{
if (0 == m_count)
{
return;
}
if (CurrentTime - m_lastRecordTime > Duration)
{
OnEnd(m_count);
m_count = 0;
m_lastRecordTime = 0.0f;
}
}
private void OnBegin()
{
if (null != onBegin)
{
onBegin();
}
}
private void OnIncrease(int current)
{
if (null != onIncrease)
{
onIncrease(current);
}
}
private void OnEnd(int current)
{
if (null != onEnd)
{
onEnd(current);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment