我想创建一个类似于触发器的自定义布尔结构,如果我将其设置为true,则在细节上,如果将其设置为false,则仅在第一次“检查”时才为true。
我刚刚快速创建了一个类来模拟我想达到的目的,以便更好地理解。
是否有可能?谢谢你。
public class Trigger
{
private bool trigger;
private bool trigger_ctrl;
public void Set(bool value)
{
this.trigger = value;
}
public void Reset()
{
this.trigger_ctrl = false;
}
public bool IsTriggered()
{
if (!this.trigger)
{
return false;
}
if (this.trigger_ctrl)
{
return false;
}
this.trigger_ctrl = true;
return true;
}
}
public class MyTrigger
{
private bool _trigger;
public bool Trigger
{
get
{
var val = _trigger;
_trigger = false;
return val;
}
set { _trigger = value; }
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句