You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.6 KiB
73 lines
1.6 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.Text; |
|
|
|
namespace UniRx |
|
{ |
|
/// <summary> |
|
/// Notify boolean flag. |
|
/// </summary> |
|
public class BooleanNotifier : IObservable<bool> |
|
{ |
|
readonly Subject<bool> boolTrigger = new Subject<bool>(); |
|
|
|
bool boolValue; |
|
/// <summary>Current flag value</summary> |
|
public bool Value |
|
{ |
|
get { return boolValue; } |
|
set |
|
{ |
|
boolValue = value; |
|
boolTrigger.OnNext(value); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// Setup initial flag. |
|
/// </summary> |
|
public BooleanNotifier(bool initialValue = false) |
|
{ |
|
this.Value = initialValue; |
|
} |
|
|
|
/// <summary> |
|
/// Set and raise true if current value isn't true. |
|
/// </summary> |
|
public void TurnOn() |
|
{ |
|
if (Value != true) |
|
{ |
|
Value = true; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// Set and raise false if current value isn't false. |
|
/// </summary> |
|
public void TurnOff() |
|
{ |
|
if (Value != false) |
|
{ |
|
Value = false; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// Set and raise reverse value. |
|
/// </summary> |
|
public void SwitchValue() |
|
{ |
|
Value = !Value; |
|
} |
|
|
|
|
|
/// <summary> |
|
/// Subscribe observer. |
|
/// </summary> |
|
public IDisposable Subscribe(IObserver<bool> observer) |
|
{ |
|
return boolTrigger.Subscribe(observer); |
|
} |
|
} |
|
} |