using System;
using System.Collections.Generic;
using System.Text;
namespace UniRx
{
///
/// Notify boolean flag.
///
public class BooleanNotifier : IObservable
{
readonly Subject boolTrigger = new Subject();
bool boolValue;
/// Current flag value
public bool Value
{
get { return boolValue; }
set
{
boolValue = value;
boolTrigger.OnNext(value);
}
}
///
/// Setup initial flag.
///
public BooleanNotifier(bool initialValue = false)
{
this.Value = initialValue;
}
///
/// Set and raise true if current value isn't true.
///
public void TurnOn()
{
if (Value != true)
{
Value = true;
}
}
///
/// Set and raise false if current value isn't false.
///
public void TurnOff()
{
if (Value != false)
{
Value = false;
}
}
///
/// Set and raise reverse value.
///
public void SwitchValue()
{
Value = !Value;
}
///
/// Subscribe observer.
///
public IDisposable Subscribe(IObserver observer)
{
return boolTrigger.Subscribe(observer);
}
}
}