目录
* 作者:闪电Y黑客
* 日期: 2019.6.11
* 功能:状态标记
1.Edge 边缘检测:检测Switch是否发生变化,触发标记变成true一次 ; 用!Switch[与]运算过滤上下边缘
/// <summary>
/// 边缘检测:检测Switch是否发生变化,触发标记变成true一次 ; 用!Switch[与]运算过滤上下边缘
/// </summary>
/// <param name="Switch">主判断</param>
/// <param name="bit">标记位</param>
/// <returns>return : 触发标记</returns>
static public bool Edge(bool Switch, ref bool bit)
{
bool T = Switch && !bit;
bit = Switch;
return T;
}
2.Trigger T触发器:Switch间隔变成true,可改变触发标记状态(false/true)
/// <summary>
/// T触发器:Switch间隔变成true,可改变触发标记状态(false/true)
/// </summary>
/// <param name="Switch">主判断</param>
/// <param name="bit">标记位</param>
/// <param name="trigger">触发标记</param>
/// <returns>return : 触发标记</returns>
static public bool Trigger(bool Switch, ref bool bit, ref bool trigger)
{
if (Switch && !bit) trigger = !trigger;
bit = Switch;
return trigger;
}
3.Count 累加计数器:计算执行次数,需要手动清零
/// <summary>
/// 累加计数器:计算执行次数,需要手动清零
/// </summary>
/// <param name="count">计数位</param>
/// <param name="Tarcount">设定数</param>
/// <param name="Cumulative">累加数</param>
/// <returns>return : 触发标记</returns>
static public bool Count(ref float count, float Tarcount, float Cumulative)
{
if (count <= Tarcount)
{
count += Cumulative;
return false;
}
else
{
return true;
}
}
4.Clock 计时器:计算执行时间,需要手动清零
/// <summary>
/// 计时器:计算执行时间,需要手动清零
/// </summary>
/// <param name="seconds">计时位</param>
/// <param name="Tarseconds">定时位(秒)</param>
/// <returns>return : 触发标记</returns>
static public bool Clock(ref DateTime LastTime, float Tarseconds)
{
return ((DateTime.Now - LastTime).TotalSeconds > Tarseconds);
}
全篇:
using System;
/*
* 作者:闪电Y黑客
*
* 日期: 2019.6.11
*
* 功能:状态标记
*/
namespace SDHK_Tool.Static
{
/// <summary>
/// 标记器
/// </summary>
static public class SS_TriggerMarker
{
/// <summary>
/// 边缘检测:检测Switch是否发生变化,触发标记变成true一次 ; 用!Switch[与]运算过滤上下边缘
/// </summary>
/// <param name="Switch">主判断</param>
/// <param name="bit">标记位</param>
/// <returns>return : 触发标记</returns>
static public bool Edge(bool Switch, ref bool bit)
{
bool T = Switch && !bit;
bit = Switch;
return T;
}
/// <summary>
/// T触发器:Switch间隔变成true,可改变触发标记状态(false/true)
/// </summary>
/// <param name="Switch">主判断</param>
/// <param name="bit">标记位</param>
/// <param name="trigger">触发标记</param>
/// <returns>return : 触发标记</returns>
static public bool Trigger(bool Switch, ref bool bit, ref bool trigger)
{
if (Switch && !bit) trigger = !trigger;
bit = Switch;
return trigger;
}
/// <summary>
/// 累加计数器:计算执行次数,需要手动清零
/// </summary>
/// <param name="count">计数位</param>
/// <param name="Tarcount">设定数</param>
/// <param name="Cumulative">累加数</param>
/// <returns>return : 触发标记</returns>
static public bool Count(ref float count, float Tarcount, float Cumulative)
{
if (count <= Tarcount)
{
count += Cumulative;
return false;
}
else
{
return true;
}
}
/// <summary>
/// 计时器:计算执行时间,需要手动清零
/// </summary>
/// <param name="seconds">计时位</param>
/// <param name="Tarseconds">定时位(秒)</param>
/// <returns>return : 触发标记</returns>
static public bool Clock(ref DateTime LastTime, float Tarseconds)
{
return ((DateTime.Now - LastTime).TotalSeconds > Tarseconds);
}
}
}