12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace UniRx
- {
-
-
-
- public class BooleanNotifier : IObservable<bool>
- {
- readonly Subject<bool> boolTrigger = new Subject<bool>();
- bool boolValue;
-
- public bool Value
- {
- get { return boolValue; }
- set
- {
- boolValue = value;
- boolTrigger.OnNext(value);
- }
- }
-
-
-
- public BooleanNotifier(bool initialValue = false)
- {
- this.Value = initialValue;
- }
-
-
-
- public void TurnOn()
- {
- if (Value != true)
- {
- Value = true;
- }
- }
-
-
-
- public void TurnOff()
- {
- if (Value != false)
- {
- Value = false;
- }
- }
-
-
-
- public void SwitchValue()
- {
- Value = !Value;
- }
-
-
-
- public IDisposable Subscribe(IObserver<bool> observer)
- {
- return boolTrigger.Subscribe(observer);
- }
- }
- }
|