Skip to content

Instantly share code, notes, and snippets.

@muit
Last active August 29, 2015 14:18
Show Gist options
  • Save muit/650a56ef29ab96c4211b to your computer and use it in GitHub Desktop.
Save muit/650a56ef29ab96c4211b to your computer and use it in GitHub Desktop.
Trigger util class on c#
/** If using Unity, remove this commentary
* [System.Serializable]
**/
public class Trigger{
public bool value;
public Trigger(bool value = true) {
this.value = value;
}
public bool get()
{
bool _value = value;
value = false;
return _value;
}
public static bool operator true(Trigger x)
{
return x.get();
}
public static bool operator false(Trigger x)
{
return !x.get();
}
public static bool operator ==(Trigger x, bool y)
{
return x.get() == y;
}
public static bool operator ==(Trigger x, Trigger y)
{
return x.get() == y.get();
}
public static bool operator !=(Trigger x, bool y)
{
return x.get() != y;
}
public static bool operator !=(Trigger x, Trigger y)
{
return x.get() != y.get();
}
public static implicit operator Trigger(bool value)
{
return new Trigger(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment