├── .gitignore
├── .nuget
├── NuGet.Config
├── NuGet.exe
├── NuGet.targets
├── UniRx.nuspec
├── pack.bat
└── push.bat
├── Analyzer
└── UniRxAnalyzer
│ ├── UniRxAnalyzer.Test
│ ├── HandleObservableAnalyzerTest.cs
│ ├── Helpers
│ │ ├── CodeFixVerifier.Helper.cs
│ │ ├── DiagnosticResult.cs
│ │ └── DiagnosticVerifier.Helper.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── UniRxAnalyzer.Test.csproj
│ ├── Verifiers
│ │ ├── CodeFixVerifier.cs
│ │ └── DiagnosticVerifier.cs
│ └── packages.config
│ ├── UniRxAnalyzer.Vsix
│ ├── UniRxAnalyzer.Vsix.csproj
│ └── source.extension.vsixmanifest
│ └── UniRxAnalyzer
│ ├── Diagnostic.nuspec
│ ├── HandleObservableAnalyzer.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── UniRxAnalyzer.csproj
│ ├── packages.config
│ └── tools
│ ├── install.ps1
│ └── uninstall.ps1
├── Assets
├── AssetStoreTools.meta
├── AssetStoreTools
│ └── Editor
│ │ ├── DroidSansMono.ttf
│ │ └── icon.png
├── ObjectTest.meta
├── ObjectTest
│ ├── Button.controller
│ ├── Button.controller.meta
│ ├── Clicker.cs
│ ├── Clicker.cs.meta
│ ├── CountOnly.cs
│ ├── CountOnly.cs.meta
│ ├── DispatcherCullingTest.cs
│ ├── DispatcherCullingTest.cs.meta
│ ├── EditorBehaviourTest.cs
│ ├── EditorBehaviourTest.cs.meta
│ ├── GameObjectDisplacer.cs
│ ├── GameObjectDisplacer.cs.meta
│ ├── IntervalTest.cs
│ ├── IntervalTest.cs.meta
│ ├── LoadLevelTest.cs
│ ├── LoadLevelTest.cs.meta
│ ├── MyStateMachine.cs
│ ├── MyStateMachine.cs.meta
│ ├── New Animator Controller.controller
│ ├── New Animator Controller.controller.meta
│ ├── RotateGameObject.cs
│ ├── RotateGameObject.cs.meta
│ ├── Sandbox2.cs
│ ├── Sandbox2.cs.meta
│ ├── SimpleMultiline.cs
│ ├── SimpleMultiline.cs.meta
│ ├── UniRxTestSandbox.cs
│ ├── UniRxTestSandbox.cs.meta
│ ├── WorkerThreadTest.cs
│ ├── WorkerThreadTest.cs.meta
│ ├── YieldTest.cs
│ ├── YieldTest.cs.meta
│ ├── clicker.jpg
│ └── clicker.jpg.meta
├── Scenes.meta
├── Scenes
│ ├── Clean.unity
│ ├── Clean.unity.meta
│ ├── LoadLevelTest.unity
│ ├── LoadLevelTest.unity.meta
│ ├── LoadLevelTestAdditive.unity
│ ├── LoadLevelTestAdditive.unity.meta
│ ├── LoadLevelTestNew.unity
│ ├── LoadLevelTestNew.unity.meta
│ ├── MultipleDispatchersTest.unity
│ ├── MultipleDispatchersTest.unity.meta
│ ├── NextSandBox.unity
│ ├── NextSandBox.unity.meta
│ ├── TestSandbox.unity
│ ├── TestSandbox.unity.meta
│ ├── UnitAssertion.unity
│ ├── UnitAssertion.unity.meta
│ ├── WorkerThreadTest.unity
│ └── WorkerThreadTest.unity.meta
├── UniRx.meta
├── UniRx
│ ├── Examples
│ │ ├── Sample01_ObservableWWW.cs
│ │ ├── Sample01_ObservableWWW.cs.meta
│ │ ├── Sample02_ObservableTriggers.cs
│ │ ├── Sample02_ObservableTriggers.cs.meta
│ │ ├── Sample03_GameObjectAsObservable.cs
│ │ ├── Sample03_GameObjectAsObservable.cs.meta
│ │ ├── Sample04_ConvertFromUnityCallback.cs
│ │ ├── Sample04_ConvertFromUnityCallback.cs.meta
│ │ ├── Sample05_ConvertFromCoroutine.cs
│ │ ├── Sample05_ConvertFromCoroutine.cs.meta
│ │ ├── Sample06_ConvertToCoroutine.cs
│ │ ├── Sample06_ConvertToCoroutine.cs.meta
│ │ ├── Sample07_OrchestratIEnumerator.cs
│ │ ├── Sample07_OrchestratIEnumerator.cs.meta
│ │ ├── Sample08_DetectDoubleClick.cs
│ │ ├── Sample08_DetectDoubleClick.cs.meta
│ │ ├── Sample09_EventHandling.cs
│ │ ├── Sample09_EventHandling.cs.meta
│ │ ├── Sample10_MainThreadDispatcher.cs
│ │ ├── Sample10_MainThreadDispatcher.cs.meta
│ │ ├── Sample11_Logger.cs
│ │ ├── Sample11_Logger.cs.meta
│ │ ├── Sample12Scene.unity
│ │ ├── Sample12Scene.unity.meta
│ │ ├── Sample12_ReactiveProperty.cs
│ │ ├── Sample12_ReactiveProperty.cs.meta
│ │ ├── Sample13Scene.unity
│ │ ├── Sample13Scene.unity.meta
│ │ ├── Sample13_ToDoApp.cs
│ │ ├── Sample13_ToDoApp.cs.meta
│ │ ├── Sample13_ToDoItem.prefab
│ │ ├── Sample13_ToDoItem.prefab.meta
│ │ ├── Sample14Scene.unity
│ │ ├── Sample14Scene.unity.meta
│ │ ├── Sample14_CubeLevel1.cs
│ │ ├── Sample14_CubeLevel1.cs.meta
│ │ ├── Sample14_CubeLevel2.cs
│ │ ├── Sample14_CubeLevel2.cs.meta
│ │ ├── Sample14_PresenterBase.cs
│ │ └── Sample14_PresenterBase.cs.meta
│ ├── ReadMe.txt
│ └── Scripts
│ │ ├── Asynchronous
│ │ └── WebRequestExtensions.cs
│ │ ├── Disposables
│ │ ├── BooleanDisposable.cs
│ │ ├── CompositeDisposable.cs
│ │ ├── DictionaryDisposable.cs
│ │ ├── Disposable.cs
│ │ ├── DisposableExtensions.cs
│ │ ├── ICancelable.cs
│ │ ├── MultipleAssignmentDisposable.cs
│ │ ├── RefCountDisposable.cs
│ │ ├── ScheduledDisposable.cs
│ │ ├── SerialDisposable.cs
│ │ ├── SingleAssignmentDisposable.cs
│ │ └── StableCompositeDisposable.cs
│ │ ├── EventPattern.cs
│ │ ├── InternalUtil
│ │ ├── AscynLock.cs
│ │ ├── ImmutableList.cs
│ │ ├── ListObserver.cs
│ │ ├── PriorityQueue.cs
│ │ ├── ReflectionAccessor.cs
│ │ ├── ScheduledItem.cs
│ │ └── ThreadSafeQueueWorker.cs
│ │ ├── Notification.cs
│ │ ├── Notifiers
│ │ ├── BooleanNotifier.cs
│ │ ├── CountNotifier.cs
│ │ ├── MessageBroker.cs
│ │ └── ScheduledNotifier.cs
│ │ ├── Observable.Aggregate.cs
│ │ ├── Observable.Binding.cs
│ │ ├── Observable.Blocking.cs
│ │ ├── Observable.Concatenate.cs
│ │ ├── Observable.Concurrency.cs
│ │ ├── Observable.Conversions.cs
│ │ ├── Observable.Creation.cs
│ │ ├── Observable.ErrorHandling.cs
│ │ ├── Observable.Events.cs
│ │ ├── Observable.FromAsync.cs
│ │ ├── Observable.Joins.cs
│ │ ├── Observable.Paging.cs
│ │ ├── Observable.Time.cs
│ │ ├── Observable.cs
│ │ ├── Observer.cs
│ │ ├── Operators
│ │ ├── Aggregate.cs
│ │ ├── Amb.cs
│ │ ├── AsObservable.cs
│ │ ├── AsUnitObservable.cs
│ │ ├── Buffer.cs
│ │ ├── Cast.cs
│ │ ├── Catch.cs
│ │ ├── CombineLatest.cs
│ │ ├── Concat.cs
│ │ ├── ContinueWith.cs
│ │ ├── Create.cs
│ │ ├── DefaultIfEmpty.cs
│ │ ├── Defer.cs
│ │ ├── Delay.cs
│ │ ├── DelaySubscription.cs
│ │ ├── Dematerialize.cs
│ │ ├── Distinct.cs
│ │ ├── DistinctUntilChanged.cs
│ │ ├── Do.cs
│ │ ├── Empty.cs
│ │ ├── Finally.cs
│ │ ├── First.cs
│ │ ├── ForEachAsync.cs
│ │ ├── FromEvent.cs
│ │ ├── IgnoreElements.cs
│ │ ├── Last.cs
│ │ ├── Materialize.cs
│ │ ├── Merge.cs
│ │ ├── Never.cs
│ │ ├── ObserveOn.cs
│ │ ├── OfType.cs
│ │ ├── OperatorObservableBase.cs
│ │ ├── OperatorObserverBase.cs
│ │ ├── PairWise.cs
│ │ ├── Range.cs
│ │ ├── RefCount.cs
│ │ ├── Repeat.cs
│ │ ├── RepeatSafe.cs
│ │ ├── Return.cs
│ │ ├── Sample.cs
│ │ ├── Scan.cs
│ │ ├── Select.cs
│ │ ├── SelectMany.cs
│ │ ├── Single.cs
│ │ ├── Skip.cs
│ │ ├── SkipUntil.cs
│ │ ├── SkipWhile.cs
│ │ ├── Start.cs
│ │ ├── StartWith.cs
│ │ ├── SubscribeOn.cs
│ │ ├── Switch.cs
│ │ ├── Synchronize.cs
│ │ ├── Take.cs
│ │ ├── TakeUntil.cs
│ │ ├── TakeWhile.cs
│ │ ├── Throttle.cs
│ │ ├── ThrottleFirst.cs
│ │ ├── Throw.cs
│ │ ├── TimeInterval.cs
│ │ ├── Timeout.cs
│ │ ├── Timer.cs
│ │ ├── Timestamp.cs
│ │ ├── ToArray.cs
│ │ ├── ToList.cs
│ │ ├── ToObservable.cs
│ │ ├── Wait.cs
│ │ ├── WhenAll.cs
│ │ ├── Where.cs
│ │ └── Zip.cs
│ │ ├── Pair.cs
│ │ ├── Schedulers
│ │ ├── CurrentThreadScheduler.cs
│ │ ├── IScheduler.cs
│ │ ├── ImmediateScheduler.cs
│ │ ├── Scheduler.cs
│ │ └── ThreadPoolScheduler.cs
│ │ ├── Subjects
│ │ ├── AsyncSubject.cs
│ │ ├── BehaviorSubject.cs
│ │ ├── ConnectableObservable.cs
│ │ ├── ISubject.cs
│ │ ├── ReplaySubject.cs
│ │ └── Subject.cs
│ │ ├── System
│ │ ├── IObservable.cs
│ │ ├── IObserver.cs
│ │ ├── IOptimizedObservable.cs
│ │ ├── IProgress.cs
│ │ ├── Tuple.cs
│ │ └── Unit.cs
│ │ ├── TimeInterval.cs
│ │ ├── Timestamped.cs
│ │ ├── UnityEngineBridge
│ │ ├── AotSafeExtensions.cs
│ │ ├── AsyncOperationExtensions.cs
│ │ ├── CancellationToken.cs
│ │ ├── Diagnostics
│ │ │ ├── LogEntry.cs
│ │ │ ├── LogEntryExtensions.cs
│ │ │ ├── Logger.cs
│ │ │ ├── ObservableLogger.cs
│ │ │ └── UnityDebugSink.cs
│ │ ├── InspectableReactiveProperty.cs
│ │ ├── InspectorDisplayDrawer.cs
│ │ ├── LazyTask.cs
│ │ ├── LifetimeDisposableExtensions.cs
│ │ ├── MainThreadDispatcher.cs
│ │ ├── MainThreadScheduler.cs
│ │ ├── Observable.Unity.cs
│ │ ├── ObservableMonoBehaviour.cs
│ │ ├── ObservableWWW.cs
│ │ ├── ObservableWebRequest.cs
│ │ ├── ObserveExtensions.cs
│ │ ├── Operators
│ │ │ ├── DelayFrame.cs
│ │ │ ├── DelayFrameSubscription.cs
│ │ │ ├── FromCoroutine.cs
│ │ │ ├── RepeatUntil.cs
│ │ │ ├── SampleFrame.cs
│ │ │ ├── SubscribeOnMainThread.cs
│ │ │ ├── ThrottleFirstFrame.cs
│ │ │ ├── ThrottleFrame.cs
│ │ │ └── TimeoutFrame.cs
│ │ ├── PresenterBase.cs
│ │ ├── ReactiveCollection.cs
│ │ ├── ReactiveDictionary.cs
│ │ ├── ReactiveProperty.cs
│ │ ├── ScenePlaybackDetector.cs
│ │ ├── Triggers
│ │ │ ├── ObservableAnimatorTrigger.cs
│ │ │ ├── ObservableBeginDragTrigger.cs
│ │ │ ├── ObservableCancelTrigger.cs
│ │ │ ├── ObservableCanvasGroupChangedTrigger.cs
│ │ │ ├── ObservableCollision2DTrigger.cs
│ │ │ ├── ObservableCollisionTrigger.cs
│ │ │ ├── ObservableDeselectTrigger.cs
│ │ │ ├── ObservableDestroyTrigger.cs
│ │ │ ├── ObservableDragTrigger.cs
│ │ │ ├── ObservableDropTrigger.cs
│ │ │ ├── ObservableEnableTrigger.cs
│ │ │ ├── ObservableEndDragTrigger.cs
│ │ │ ├── ObservableEventTrigger.cs
│ │ │ ├── ObservableFixedUpdateTrigger.cs
│ │ │ ├── ObservableInitializePotentialDragTrigger.cs
│ │ │ ├── ObservableLateUpdateTrigger.cs
│ │ │ ├── ObservableMouseTrigger.cs
│ │ │ ├── ObservableMoveTrigger.cs
│ │ │ ├── ObservablePointerClickTrigger.cs
│ │ │ ├── ObservablePointerDownTrigger.cs
│ │ │ ├── ObservablePointerEnterTrigger.cs
│ │ │ ├── ObservablePointerExitTrigger.cs
│ │ │ ├── ObservablePointerUpTrigger.cs
│ │ │ ├── ObservableRectTransformTrigger.cs
│ │ │ ├── ObservableScrollTrigger.cs
│ │ │ ├── ObservableSelectTrigger.cs
│ │ │ ├── ObservableStateMachineTrigger.cs
│ │ │ ├── ObservableSubmitTrigger.cs
│ │ │ ├── ObservableTransformChangedTrigger.cs
│ │ │ ├── ObservableTrigger2DTrigger.cs
│ │ │ ├── ObservableTriggerBase.cs
│ │ │ ├── ObservableTriggerExtensions.Component.cs
│ │ │ ├── ObservableTriggerExtensions.cs
│ │ │ ├── ObservableTriggerTrigger.cs
│ │ │ ├── ObservableUpdateSelectedTrigger.cs
│ │ │ ├── ObservableUpdateTrigger.cs
│ │ │ └── ObservableVisibleTrigger.cs
│ │ ├── TypedMonoBehaviour.cs
│ │ ├── UnityEqualityComparer.cs
│ │ ├── UnityEventExtensions.cs
│ │ ├── UnityGraphicExtensions.cs
│ │ ├── UnityUIComponentExtensions.cs
│ │ └── YieldInstructionCache.cs
│ │ └── UnityWinRTBridge
│ │ ├── Thread.cs
│ │ └── ThreadPoolScheduler_UnityWinRT.cs
├── UnitTests.meta
├── UnitTests
│ ├── SceneItems.meta
│ ├── SceneItems
│ │ ├── Result.cs
│ │ ├── Result.cs.meta
│ │ ├── UnitTestScene.cs
│ │ └── UnitTestScene.cs.meta
│ ├── Tools.meta
│ ├── Tools
│ │ ├── ChainingAssertion.Unity.cs
│ │ ├── ChainingAssertion.Unity.cs.meta
│ │ ├── Container.cs
│ │ ├── Container.cs.meta
│ │ ├── Shim.cs
│ │ ├── Shim.cs.meta
│ │ ├── TestUtil.cs
│ │ └── TestUtil.cs.meta
│ ├── UnitTests.cs
│ ├── UnitTests.cs.meta
│ ├── UnitTests.tt
│ └── UnitTests.tt.meta
├── UnityVS.meta
├── UnityVS
│ └── Editor
│ │ ├── SyntaxTree.VisualStudio.Unity.Bridge.dll
│ │ ├── SyntaxTree.VisualStudio.Unity.Messaging.dll
│ │ └── UnityVS.VersionSpecific.dll
├── smcs.rsp
└── smcs.rsp.meta
├── Dlls
├── UniRx.Library.Unity
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── UniRx.Library.Unity.csproj
└── UniRx.Library
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── UniRx.Library.csproj
├── LICENSE
├── ProjectSettings
├── AudioManager.asset
├── ClusterInputManager.asset
├── DynamicsManager.asset
├── EditorBuildSettings.asset
├── EditorSettings.asset
├── GraphicsSettings.asset
├── InputManager.asset
├── NavMeshAreas.asset
├── NavMeshLayers.asset
├── NetworkManager.asset
├── Physics2DSettings.asset
├── ProjectSettings.asset
├── ProjectVersion.txt
├── QualitySettings.asset
├── TagManager.asset
├── TimeManager.asset
├── UnityAdsSettings.asset
└── UnityConnectSettings.asset
├── README.md
├── StoreDocument
├── AnalyzerReference.jpg
├── MVP_Pattern.png
├── MVRP_Loop.png
├── OriginalIcon_511x511.png
├── RxPropInspector.png
├── VSAnalyzer.jpg
├── big_precise.jpg
├── big_precise.psd
├── icon_precise.jpg
├── icon_precise.psd
├── presenterbase_steps.gif
├── small_precise.jpg
├── small_precise.psd
├── ss1.jpg
├── ss2.jpg
└── ss3.jpg
├── Tests
├── UniRx.Console
│ ├── App.config
│ ├── CombineLatestGenerator.tt
│ ├── CombineLatestGenerator.txt
│ ├── Playground.cs
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── UniRx.Console.csproj
│ ├── ZipGenerator.tt
│ └── ZipGenerator.txt
└── UniRx.Tests
│ ├── AggregateTest.cs
│ ├── ContinueWithTest.cs
│ ├── ConversionTest.cs
│ ├── DisposableTest.cs
│ ├── DoTest.cs
│ ├── DurabilityTest.cs
│ ├── Observable.ConcatTest.cs
│ ├── Observable.ConcurrencyTest.cs
│ ├── Observable.ErrorHandlingTest.cs
│ ├── Observable.Events.cs
│ ├── Observable.GeneratorTest.cs
│ ├── Observable.PagingTest.cs
│ ├── Observable.TimeTest.cs
│ ├── ObservableTest.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── QueueWorkerTest.cs
│ ├── RangeTest.cs
│ ├── ReactivePropertyTest.cs
│ ├── ReactriveDictionaryTest.cs
│ ├── SchedulerTest.cs
│ ├── SelectMany.cs
│ ├── SubjectTest.cs
│ ├── TakeTest.cs
│ ├── ToTest.cs
│ ├── Tools
│ ├── ChainingAssertion.Unity.cs
│ ├── Init.cs
│ └── TestUtil.cs
│ ├── UniRx.Tests.csproj
│ ├── WhenAllTest.cs
│ └── packages.config
├── UniRx.CSharp.csproj
└── UniRx.sln
/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rampage1212/Unity-UniRx/9d2af3b9b21838f29c9220b1c396fdbeb76c782d/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/.nuget/UniRx.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | UniRx
5 | 5.1.0
6 | UniRx
7 | neuecc
8 | neuecc
9 | false
10 | Reactive Extensions for Unity. This is .NET 3.5 subset of UniRx.
11 |
12 |
15 |
16 | en-US
17 | http://opensource.org/licenses/MIT
18 | https://github.com/neuecc/UniRx
19 | Rx Unity LINQ
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.nuget/pack.bat:
--------------------------------------------------------------------------------
1 | nuget pack UniRx.nuspec
--------------------------------------------------------------------------------
/.nuget/push.bat:
--------------------------------------------------------------------------------
1 | nuget push UniRx.5.0.0.nupkg
--------------------------------------------------------------------------------
/Analyzer/UniRxAnalyzer/UniRxAnalyzer.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("UniRxAnalyzer.Test")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("UniRxAnalyzer.Test")]
12 | [assembly: AssemblyCopyright("Copyright © 2015")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // Version information for an assembly consists of the following four values:
22 | //
23 | // Major Version
24 | // Minor Version
25 | // Build Number
26 | // Revision
27 | //
28 | // You can specify all the values or you can default the Build and Revision Numbers
29 | // by using the '*' as shown below:
30 | // [assembly: AssemblyVersion("1.0.*")]
31 | [assembly: AssemblyVersion("1.0.0.0")]
32 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/Analyzer/UniRxAnalyzer/UniRxAnalyzer.Test/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Analyzer/UniRxAnalyzer/UniRxAnalyzer.Vsix/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | UniRxAnalyzer.Vsix
6 | UniRx analyzers.
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Analyzer/UniRxAnalyzer/UniRxAnalyzer/Diagnostic.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | UniRxAnalyzer
5 | 1.0.3.2
6 | UniRxAnalyzer
7 | neuecc
8 | https://github.com/neuecc/UniRx
9 | false
10 | Various Analyzers for UniRx
11 | Update for VS2015 RTM.
12 | UniRx, analyzers
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Analyzer/UniRxAnalyzer/UniRxAnalyzer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("UniRxAnalyzer")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("UniRxAnalyzer")]
12 | [assembly: AssemblyTrademark("")]
13 | [assembly: AssemblyCulture("")]
14 |
15 | // Setting ComVisible to false makes the types in this assembly not visible
16 | // to COM components. If you need to access a type in this assembly from
17 | // COM, set the ComVisible attribute to true on that type.
18 | [assembly: ComVisible(false)]
19 |
20 | // Version information for an assembly consists of the following four values:
21 | //
22 | // Major Version
23 | // Minor Version
24 | // Build Number
25 | // Revision
26 | //
27 | // You can specify all the values or you can default the Build and Revision Numbers
28 | // by using the '*' as shown below:
29 | [assembly: AssemblyVersion("1.0.3.2")]
30 | [assembly: AssemblyFileVersion("1.0.3.2")]
--------------------------------------------------------------------------------
/Analyzer/UniRxAnalyzer/UniRxAnalyzer/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Analyzer/UniRxAnalyzer/UniRxAnalyzer/tools/install.ps1:
--------------------------------------------------------------------------------
1 | param($installPath, $toolsPath, $package, $project)
2 |
3 | $analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers" ) * -Resolve
4 |
5 | foreach($analyzersPath in $analyzersPaths)
6 | {
7 | # Install the language agnostic analyzers.
8 | if (Test-Path $analyzersPath)
9 | {
10 | foreach ($analyzerFilePath in Get-ChildItem $analyzersPath -Filter *.dll)
11 | {
12 | if($project.Object.AnalyzerReferences)
13 | {
14 | $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName)
15 | }
16 | }
17 | }
18 | }
19 |
20 | # $project.Type gives the language name like (C# or VB.NET)
21 | $languageFolder = ""
22 | if($project.Type -eq "C#")
23 | {
24 | $languageFolder = "cs"
25 | }
26 | if($project.Type -eq "VB.NET")
27 | {
28 | $languageFolder = "vb"
29 | }
30 | if($languageFolder -eq "")
31 | {
32 | return
33 | }
34 |
35 | foreach($analyzersPath in $analyzersPaths)
36 | {
37 | # Install language specific analyzers.
38 | $languageAnalyzersPath = join-path $analyzersPath $languageFolder
39 | if (Test-Path $languageAnalyzersPath)
40 | {
41 | foreach ($analyzerFilePath in Get-ChildItem $languageAnalyzersPath -Filter *.dll)
42 | {
43 | if($project.Object.AnalyzerReferences)
44 | {
45 | $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName)
46 | }
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/Analyzer/UniRxAnalyzer/UniRxAnalyzer/tools/uninstall.ps1:
--------------------------------------------------------------------------------
1 | param($installPath, $toolsPath, $package, $project)
2 |
3 | $analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers" ) * -Resolve
4 |
5 | foreach($analyzersPath in $analyzersPaths)
6 | {
7 | # Uninstall the language agnostic analyzers.
8 | if (Test-Path $analyzersPath)
9 | {
10 | foreach ($analyzerFilePath in Get-ChildItem $analyzersPath -Filter *.dll)
11 | {
12 | if($project.Object.AnalyzerReferences)
13 | {
14 | $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName)
15 | }
16 | }
17 | }
18 | }
19 |
20 | # $project.Type gives the language name like (C# or VB.NET)
21 | $languageFolder = ""
22 | if($project.Type -eq "C#")
23 | {
24 | $languageFolder = "cs"
25 | }
26 | if($project.Type -eq "VB.NET")
27 | {
28 | $languageFolder = "vb"
29 | }
30 | if($languageFolder -eq "")
31 | {
32 | return
33 | }
34 |
35 | foreach($analyzersPath in $analyzersPaths)
36 | {
37 | # Uninstall language specific analyzers.
38 | $languageAnalyzersPath = join-path $analyzersPath $languageFolder
39 | if (Test-Path $languageAnalyzersPath)
40 | {
41 | foreach ($analyzerFilePath in Get-ChildItem $languageAnalyzersPath -Filter *.dll)
42 | {
43 | if($project.Object.AnalyzerReferences)
44 | {
45 | try
46 | {
47 | $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName)
48 | }
49 | catch
50 | {
51 |
52 | }
53 | }
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/Assets/AssetStoreTools.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8951e7b9687d74949af2854b82e3601c
3 | folderAsset: yes
4 | timeCreated: 1425282656
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/AssetStoreTools/Editor/DroidSansMono.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rampage1212/Unity-UniRx/9d2af3b9b21838f29c9220b1c396fdbeb76c782d/Assets/AssetStoreTools/Editor/DroidSansMono.ttf
--------------------------------------------------------------------------------
/Assets/AssetStoreTools/Editor/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rampage1212/Unity-UniRx/9d2af3b9b21838f29c9220b1c396fdbeb76c782d/Assets/AssetStoreTools/Editor/icon.png
--------------------------------------------------------------------------------
/Assets/ObjectTest.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 50e8d464f8f33c84cb49c3af8e898ceb
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/Button.controller.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6fdaf095aa7510d41888da62d7bd413d
3 | timeCreated: 1435156774
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/Clicker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 |
4 | namespace UniRx.ObjectTest
5 | {
6 | public class Clicker : MonoBehaviour
7 | {
8 | public event Action OnClicked = delegate { };
9 |
10 | public event Action OnEntered = delegate { };
11 |
12 | public event Action OnExited = delegate { };
13 |
14 | #if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
15 |
16 | // Disable OnMouse_ event handlers to make it easy to confirm warning.
17 |
18 | void OnMouseDown()
19 | {
20 | OnClicked();
21 | }
22 |
23 | void OnMouseEnter()
24 | {
25 | OnEntered();
26 | }
27 |
28 | void OnMouseExit()
29 | {
30 | OnExited();
31 | }
32 |
33 | #endif
34 |
35 | Subject update;
36 | public int VVV;
37 |
38 | public void Update()
39 | {
40 | var t = (int)Time.time;
41 | if (t % 5 == 0)
42 | {
43 | VVV = t;
44 | }
45 |
46 | if (update != null) update.OnNext(Unit.Default);
47 | }
48 |
49 | public IObservable UpdateAsObservable()
50 | {
51 | return update ?? (update = new Subject());
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/Clicker.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4043b787d3435404bb4205088677fdb2
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/CountOnly.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using UnityEngine.UI;
4 |
5 | public class CountOnly : MonoBehaviour
6 | {
7 | public Text text;
8 |
9 | int count = 0;
10 |
11 | public void Update()
12 | {
13 | text.text = (count++).ToString();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/CountOnly.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 57f661840470c90418e47e6200b71261
3 | timeCreated: 1450100793
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/DispatcherCullingTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using UnityEngine;
6 |
7 | namespace UniRx.ObjectTest
8 | {
9 | public class DispatcherCullingTest : MonoBehaviour
10 | {
11 | public GUIText cullLabel;
12 | private string cullingModeDescription = string.Empty;
13 |
14 | void Start()
15 | {
16 | var cullClicker = cullLabel.gameObject.AddComponent();
17 | var cullClickerColor = cullClicker.GetComponent().color;
18 | cullClicker.OnEntered += () => cullLabel.GetComponent().color = Color.blue;
19 | cullClicker.OnExited += () => cullLabel.GetComponent().color = cullClickerColor;
20 | cullClicker.OnClicked += () =>
21 | {
22 | var values = Enum.GetValues(typeof(MainThreadDispatcher.CullingMode));
23 | var currentValue = (int)MainThreadDispatcher.cullingMode;
24 | MainThreadDispatcher.cullingMode = (MainThreadDispatcher.CullingMode)((currentValue + 1 == values.Length) ? 0 : currentValue + 1);
25 | };
26 | }
27 |
28 | void Update()
29 | {
30 | switch (MainThreadDispatcher.cullingMode)
31 | {
32 | case MainThreadDispatcher.CullingMode.Disabled:
33 | cullingModeDescription = "Won't remove any MainThreadDispatchers.";
34 | break;
35 |
36 | case MainThreadDispatcher.CullingMode.Self:
37 | cullingModeDescription = "A new MainThreadDispatcher will remove itself when there's an existing dispatcher.";
38 | break;
39 |
40 | case MainThreadDispatcher.CullingMode.All:
41 | cullingModeDescription = "When a new MainThreadDispatcher is added, search and destroy any excess dispatchers.";
42 | break;
43 | }
44 | cullLabel.text = string.Format("Click to toggle Dispatcher Culling Mode: {0}\n{1}"
45 | , MainThreadDispatcher.cullingMode.ToString(), cullingModeDescription);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/DispatcherCullingTest.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c5390ee4ca9f48645b5af618e5b4947a
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/EditorBehaviourTest.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d08a9165edad27148bf7f277471be591
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/GameObjectDisplacer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using UnityEngine;
4 |
5 | namespace UniRx.ObjectTest
6 | {
7 | public class GameObjectDisplacer : MonoBehaviour
8 | {
9 | public GameObject originalObject;
10 | public Vector3 displacement;
11 |
12 | private int Counter = 0;
13 | private static GameObjectDisplacer _instance;
14 |
15 | void Awake()
16 | {
17 | originalObject.AddComponent();
18 |
19 | if (_instance == null)
20 | {
21 | _instance = this;
22 |
23 | AwakeDetector.OnAwake += (g) => GameObjectCloned(g);
24 | }
25 | else
26 | {
27 | Destroy(this.gameObject);
28 | }
29 | }
30 |
31 | public void GameObjectCloned(GameObject g)
32 | {
33 | if (originalObject != null)
34 | {
35 | g.name = string.Format("{0} #{1}", originalObject.name, Counter++);
36 | g.transform.position += displacement * Counter;
37 | }
38 | }
39 | }
40 |
41 | public class AwakeDetector : MonoBehaviour
42 | {
43 | public static event Action OnAwake = delegate { };
44 |
45 | void Awake()
46 | {
47 | OnAwake(this.gameObject);
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/Assets/ObjectTest/GameObjectDisplacer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0fa67989512d4214488451dcafef6425
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/IntervalTest.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fd1302d3c1666e241928a17e7cf0abdb
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/LoadLevelTest.cs:
--------------------------------------------------------------------------------
1 | #if !UNITY_5_3
2 | using System;
3 | using System.Collections;
4 | using UnityEngine;
5 |
6 | namespace UniRx.ObjectTest
7 | {
8 | public class LoadLevelTest : MonoBehaviour
9 | {
10 | void Start()
11 | {
12 | var ll = GameObject.Find("LoadLevel");
13 | var llcolor = ll.GetComponent().color;
14 | var cll = ll.AddComponent();
15 | cll.OnClicked += () => Application.LoadLevel("LoadLevelTestNew");
16 | cll.OnEntered += () => cll.GetComponent().color = Color.blue;
17 | cll.OnExited += () => cll.GetComponent().color = llcolor;
18 |
19 | var lla = GameObject.Find("LoadLevelAdditive");
20 | var llacolor = lla.GetComponent().color;
21 | var clla = lla.AddComponent();
22 |
23 | clla.OnClicked += () => Application.LoadLevelAdditive("LoadLevelTestAdditive");
24 | clla.OnEntered += () => clla.GetComponent().color = Color.blue;
25 | clla.OnExited += () => clla.GetComponent().color = llacolor;
26 | }
27 | }
28 | }
29 |
30 | #endif
--------------------------------------------------------------------------------
/Assets/ObjectTest/LoadLevelTest.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 917c041d082a38f40bda99bf1b7738be
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/MyStateMachine.cs:
--------------------------------------------------------------------------------
1 | #if UNITY_5
2 |
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using UnityEngine;
8 |
9 | namespace Assets.ObjectTest
10 | {
11 |
12 | public class MyStateMachine : StateMachineBehaviour
13 | {
14 | //public override void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
15 | //{
16 | // base.OnStateMove(animator, stateInfo, layerIndex);
17 | // Debug.Log("Move Called");
18 | //}
19 |
20 | //public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
21 | //{
22 | // base.OnStateEnter(animator, stateInfo, layerIndex);
23 | // Debug.Log("State Enter");
24 | //}
25 | }
26 | }
27 |
28 | #endif
--------------------------------------------------------------------------------
/Assets/ObjectTest/MyStateMachine.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b2057d72c185c0340b0e8cfc794127f9
3 | timeCreated: 1435156738
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/New Animator Controller.controller:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!91 &9100000
4 | AnimatorController:
5 | m_ObjectHideFlags: 0
6 | m_PrefabParentObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 0}
8 | m_Name: New Animator Controller
9 | serializedVersion: 5
10 | m_AnimatorParameters: []
11 | m_AnimatorLayers:
12 | - serializedVersion: 5
13 | m_Name: Base Layer
14 | m_StateMachine: {fileID: 110797916}
15 | m_Mask: {fileID: 0}
16 | m_Motions: []
17 | m_Behaviours: []
18 | m_BlendingMode: 0
19 | m_SyncedLayerIndex: -1
20 | m_DefaultWeight: 0
21 | m_IKPass: 0
22 | m_SyncedLayerAffectsTiming: 0
23 | m_Controller: {fileID: 0}
24 | --- !u!114 &11421932
25 | MonoBehaviour:
26 | m_ObjectHideFlags: 1
27 | m_PrefabParentObject: {fileID: 0}
28 | m_PrefabInternal: {fileID: 0}
29 | m_GameObject: {fileID: 0}
30 | m_Enabled: 1
31 | m_EditorHideFlags: 0
32 | m_Script: {fileID: 11500000, guid: b2057d72c185c0340b0e8cfc794127f9, type: 3}
33 | m_Name:
34 | m_EditorClassIdentifier:
35 | --- !u!1107 &110797916
36 | AnimatorStateMachine:
37 | serializedVersion: 5
38 | m_ObjectHideFlags: 1
39 | m_PrefabParentObject: {fileID: 0}
40 | m_PrefabInternal: {fileID: 0}
41 | m_Name: Base Layer
42 | m_ChildStates: []
43 | m_ChildStateMachines: []
44 | m_AnyStateTransitions: []
45 | m_EntryTransitions: []
46 | m_StateMachineTransitions:
47 | data:
48 | first: {fileID: 110797916}
49 | second: []
50 | m_StateMachineBehaviours:
51 | - {fileID: 11421932}
52 | m_AnyStatePosition: {x: 144, y: -36, z: 0}
53 | m_EntryPosition: {x: 180, y: 84, z: 0}
54 | m_ExitPosition: {x: 800, y: 120, z: 0}
55 | m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
56 | m_DefaultState: {fileID: 0}
57 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/New Animator Controller.controller.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 106fa5ee00061b5499ea7ab2eead334e
3 | timeCreated: 1435156687
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/RotateGameObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UniRx;
3 | using UnityEngine;
4 |
5 | namespace UniRx.ObjectTest
6 | {
7 | public class RotateGameObject : MonoBehaviour
8 | {
9 | public GameObject target;
10 | public Vector3 angle;
11 |
12 | void Awake()
13 | {
14 | if (angle == Vector3.zero)
15 | {
16 | angle = new Vector3(2, 4, 4);
17 | }
18 | }
19 |
20 | void Start()
21 | {
22 | var interval = Observable
23 | .Interval(System.TimeSpan.FromMilliseconds(20))
24 | .Do((l) => target.transform.Rotate(angle));
25 |
26 | interval
27 | .CatchIgnore((Exception ex) => Debug.LogWarning(ex))
28 | .Subscribe();
29 |
30 | /*
31 | .Subscribe((s) =>
32 | {
33 | if (g != null)
34 | g.transform.Rotate(angle);
35 | else
36 | throw new Exception("Can't find GameObject `Cylinder`!");
37 | });
38 | */
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/Assets/ObjectTest/RotateGameObject.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 61bb465eaef753741836179da83c606a
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/Sandbox2.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using UniRx;
3 | using UniRx.Triggers;
4 | using System.Collections;
5 | using System.Linq;
6 | using System;
7 | using System.Collections.Generic;
8 | using UnityEngine.UI;
9 | // using UnityEngine.SceneManagement;
10 |
11 | public class MyEventClass
12 | {
13 | public event Action Hoge;
14 | public void Push(int x)
15 | {
16 | Hoge(x);
17 | }
18 | }
19 |
20 | public class MoGe
21 | {
22 | public void Huga()
23 | {
24 | }
25 | }
26 |
27 | // for Scenes/NextSandBox
28 | public class Sandbox2 : MonoBehaviour
29 | {
30 | public Button button;
31 |
32 | void Awake()
33 | {
34 | MainThreadDispatcher.Initialize();
35 | }
36 |
37 | void Aaa(Action action)
38 | {
39 | }
40 |
41 | //int clickCount = 0;
42 | //AsyncOperation ao = null;
43 |
44 | void Start()
45 | {
46 |
47 | button.OnClickAsObservable().Subscribe(_ =>
48 | {
49 |
50 | var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
51 |
52 | cube.UpdateAsObservable()
53 | .SampleFrame(30)
54 | .TakeUntilDestroy(cube) // add line.
55 | .Subscribe(
56 | __ =>
57 | {
58 | var p = cube.transform.position;
59 | cube.transform.position = new Vector3(p.x + 0.4f, p.y, p.z);
60 | },
61 | e => Debug.LogError("Error! " + e),
62 | () => Debug.Log("Completed!"));
63 |
64 | GameObject.Destroy(cube, 3f);
65 |
66 | Debug.Log(cube);
67 | });
68 | }
69 | }
--------------------------------------------------------------------------------
/Assets/ObjectTest/Sandbox2.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7e866ab5ccb1eda45a190fce8c1a4729
3 | timeCreated: 1430930095
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/SimpleMultiline.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using UniRx;
4 |
5 | public class SimpleMultiline : MonoBehaviour
6 | {
7 |
8 | public StringReactiveProperty SinglelineString;
9 |
10 | [MultilineReactiveProperty]
11 | public StringReactiveProperty MultineString;
12 |
13 | [Multiline(3)]
14 | public string ML;
15 |
16 | [TextArea(5, 10)]
17 | public string TA;
18 |
19 | void Start()
20 | {
21 | SinglelineString.Subscribe(x =>
22 | {
23 | Debug.Log(x);
24 | });
25 |
26 | MultineString.Subscribe(x =>
27 | {
28 | Debug.Log(x);
29 | });
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/SimpleMultiline.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8a15fa4fd14a9c24a94c88d95ccc0eb6
3 | timeCreated: 1448634214
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/UniRxTestSandbox.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 02440cdbc97b02245978ad23e78a3189
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/WorkerThreadTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using UniRx;
4 | using UnityEngine;
5 |
6 | namespace UniRx.ObjectTest
7 | {
8 | public class WorkerThreadTest : MonoBehaviour
9 | {
10 | void Awake()
11 | {
12 | #if UNITY_METRO
13 | // Windows Store doesn't support System.Threading.Thread.
14 | // Other platforms can use both ThreadPool and System.Threading.Thread.
15 | // ThreadPool.QueueUserWorkItem(RegisterApplicationQuitEvent);
16 | // ThreadPool.QueueUserWorkItem(SpawnCapsules);
17 | #else
18 | Thread thread = new Thread(SpawnCapsules);
19 | thread.Start();
20 | #endif
21 | }
22 |
23 | private void RegisterApplicationQuitEvent(object a)
24 | {
25 | MainThreadDispatcher.OnApplicationQuitAsObservable().Subscribe(_ => Debug.Log("OnApplicationQuitAsObservable"));
26 | }
27 |
28 | private void SpawnCapsules(object a)
29 | {
30 | // Create capsules one by one.
31 | Observable.Interval(TimeSpan.FromMilliseconds(300))
32 | .Take(5)
33 | .Subscribe((s) =>
34 | {
35 | var g = GameObject.CreatePrimitive(PrimitiveType.Capsule);
36 | g.name = "Capsule " + s;
37 | g.transform.position += new Vector3(s, 0, 0);
38 | });
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/Assets/ObjectTest/WorkerThreadTest.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: dca0dc71a1038104391fbfe361f092e7
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/YieldTest.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using UniRx;
4 | using System;
5 |
6 | public class YieldTest : MonoBehaviour
7 | {
8 | public void Start()
9 | {
10 | //Observable.Create(observer =>
11 | //{
12 | // observer.OnNext(Unit.Default);
13 | // observer.OnCompleted();
14 | // return Disposable.Empty;
15 | //})
16 | //Observable.ReturnUnit()
17 | // .Finally(() =>
18 | // {
19 | // Debug.Log("finally");
20 | // })
21 | // .Subscribe(_ =>
22 | // {
23 | // Debug.Log("onnext");
24 | // }, () => Debug.Log("comp"));
25 | this.StartCoroutine(this.SomeCoroutine());
26 | }
27 |
28 | private IEnumerator SomeCoroutine()
29 | {
30 | Debug.Log("begin SomeCoroutine");
31 | yield return this.SomeObservable().StartAsCoroutine();
32 | Debug.Log("end SomeCoroutine"); //not called!
33 | }
34 |
35 | private IObservable SomeObservable()
36 | {
37 | Debug.Log("begin SomeObservable");
38 | return Observable.ReturnUnit()
39 | .Do(_ => Debug.Log("end SomeObservable"));
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/YieldTest.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b80633b2d5102df4b8c4a7b82962f65b
3 | timeCreated: 1444309959
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/ObjectTest/clicker.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rampage1212/Unity-UniRx/9d2af3b9b21838f29c9220b1c396fdbeb76c782d/Assets/ObjectTest/clicker.jpg
--------------------------------------------------------------------------------
/Assets/ObjectTest/clicker.jpg.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9f4f1075987dfa746b1b6a1043bfdfe0
3 | TextureImporter:
4 | fileIDToRecycleName:
5 | 21300000: clicker
6 | serializedVersion: 2
7 | mipmaps:
8 | mipMapMode: 0
9 | enableMipMap: 0
10 | linearTexture: 0
11 | correctGamma: 0
12 | fadeOut: 0
13 | borderMipMap: 0
14 | mipMapFadeDistanceStart: 1
15 | mipMapFadeDistanceEnd: 3
16 | bumpmap:
17 | convertToNormalMap: 0
18 | externalNormalMap: 0
19 | heightScale: .25
20 | normalMapFilter: 0
21 | isReadable: 0
22 | grayScaleToAlpha: 0
23 | generateCubemap: 0
24 | seamlessCubemap: 0
25 | textureFormat: -1
26 | maxTextureSize: 1024
27 | textureSettings:
28 | filterMode: -1
29 | aniso: 1
30 | mipBias: -1
31 | wrapMode: 1
32 | nPOTScale: 0
33 | lightmap: 0
34 | compressionQuality: 50
35 | spriteMode: 1
36 | spriteExtrude: 1
37 | spriteMeshType: 1
38 | alignment: 0
39 | spritePivot: {x: .5, y: .5}
40 | spriteBorder: {x: 0, y: 0, z: 0, w: 0}
41 | spritePixelsToUnits: 100
42 | alphaIsTransparency: 1
43 | textureType: 8
44 | buildTargetSettings:
45 | - buildTarget: iPhone
46 | maxTextureSize: 1024
47 | textureFormat: -2
48 | compressionQuality: 50
49 | spriteSheet:
50 | sprites: []
51 | spritePackingTag:
52 | userData:
53 |
--------------------------------------------------------------------------------
/Assets/Scenes.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6fb33e56c9bfdf9449525a90016ce863
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/Assets/Scenes/Clean.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 93251f6ee005afd4f8ff524f0bee41fe
3 | timeCreated: 1450100742
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Scenes/LoadLevelTest.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a2efb166056ec684583f4c1b0a9d072c
3 | timeCreated: 1425282656
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Scenes/LoadLevelTestAdditive.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 47ef72962a830f647a965e97fa833fd5
3 | timeCreated: 1425282656
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Scenes/LoadLevelTestNew.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5e998d404e335b24887738e21451f8ed
3 | timeCreated: 1425282656
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Scenes/MultipleDispatchersTest.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 242f9f44d749cd848b4f44ec1b111afd
3 | timeCreated: 1425282656
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Scenes/NextSandBox.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9746d751da96ee9488fe35e2b9ee2dfd
3 | timeCreated: 1427099831
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Scenes/TestSandbox.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 76ec0772b181e9b46b00cfa89d2c4d48
3 | timeCreated: 1425282656
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Scenes/UnitAssertion.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e0ada73eb8475644e93cb8c9a31279cc
3 | timeCreated: 1450073810
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Scenes/WorkerThreadTest.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ab31ecac1ccd4f143a354b7f5a87ba5e
3 | timeCreated: 1425282656
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UniRx.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 635d02b0a3adf8344b83acd8706240c3
3 | folderAsset: yes
4 | timeCreated: 1425282656
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample01_ObservableWWW.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d18d2078e0118cf4a9454f0a3b855691
3 | timeCreated: 1425282659
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample02_ObservableTriggers.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using UniRx.Triggers; // Triggers Namepsace
3 | using System;
4 |
5 | namespace UniRx.Examples
6 | {
7 | public class Sample02_ObservableTriggers : MonoBehaviour
8 | {
9 | void Start()
10 | {
11 | // Get the plain object
12 | var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
13 |
14 | // Add ObservableXxxTrigger for handle MonoBehaviour's event as Observable
15 | cube.AddComponent()
16 | .UpdateAsObservable()
17 | .SampleFrame(30)
18 | .Subscribe(x => Debug.Log("cube"), () => Debug.Log("destroy"));
19 |
20 | // destroy after 3 second:)
21 | GameObject.Destroy(cube, 3f);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample02_ObservableTriggers.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: dbe06d7ba757f3240a61f3c13bd0e4a0
3 | timeCreated: 1425282659
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample03_GameObjectAsObservable.cs:
--------------------------------------------------------------------------------
1 | #if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
2 |
3 | using UnityEngine;
4 | using UniRx.Triggers; // for enable gameObject.EventAsObservbale()
5 |
6 | namespace UniRx.Examples
7 | {
8 | public class Sample03_GameObjectAsObservable : MonoBehaviour
9 | {
10 | void Start()
11 | {
12 | // All events can subscribe by ***AsObservable if enables UniRx.Triggers
13 | this.OnMouseDownAsObservable()
14 | .SelectMany(_ => this.gameObject.UpdateAsObservable())
15 | .TakeUntil(this.gameObject.OnMouseUpAsObservable())
16 | .Select(_ => Input.mousePosition)
17 | .RepeatUntilDestroy(this)
18 | .Subscribe(x => Debug.Log(x), ()=> Debug.Log("!!!" + "complete"));
19 | }
20 | }
21 | }
22 |
23 | #endif
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample03_GameObjectAsObservable.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ee855b2348c6bfd4a86774265bc64356
3 | timeCreated: 1425282659
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample04_ConvertFromUnityCallback.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ad39f59973882ae4d8a1e4b8cc71b24b
3 | timeCreated: 1425282659
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample05_ConvertFromCoroutine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using UnityEngine;
4 |
5 | namespace UniRx.Examples
6 | {
7 | public class Sample05_ConvertFromCoroutine
8 | {
9 | // public method
10 | public static IObservable GetWWW(string url)
11 | {
12 | // convert coroutine to IObservable
13 | return Observable.FromCoroutine((observer, cancellationToken) => GetWWWCore(url, observer, cancellationToken));
14 | }
15 |
16 | // IEnumerator with callback
17 | static IEnumerator GetWWWCore(string url, IObserver observer, CancellationToken cancellationToken)
18 | {
19 | var www = new UnityEngine.WWW(url);
20 | while (!www.isDone && !cancellationToken.IsCancellationRequested)
21 | {
22 | yield return null;
23 | }
24 |
25 | if (cancellationToken.IsCancellationRequested) yield break;
26 |
27 | if (www.error != null)
28 | {
29 | observer.OnError(new Exception(www.error));
30 | }
31 | else
32 | {
33 | observer.OnNext(www.text);
34 | observer.OnCompleted();
35 | }
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample05_ConvertFromCoroutine.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7b5cfe9d61a58ad4ca44c889d82ccc2c
3 | timeCreated: 1425282658
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample06_ConvertToCoroutine.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2af227a4ed7f39042a636f10696a2c0d
3 | timeCreated: 1425282658
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample07_OrchestratIEnumerator.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable 0168
2 |
3 | using System;
4 | using System.Collections;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using UnityEngine;
9 |
10 | namespace UniRx.Examples
11 | {
12 | public class Sample07_OrchestratIEnumerator : MonoBehaviour
13 | {
14 | // two coroutines
15 | IEnumerator AsyncA()
16 | {
17 | Debug.Log("a start");
18 | yield return new WaitForSeconds(3);
19 | Debug.Log("a end");
20 | }
21 |
22 | IEnumerator AsyncB()
23 | {
24 | Debug.Log("b start");
25 | yield return new WaitForEndOfFrame();
26 | Debug.Log("b end");
27 | }
28 |
29 | void Start()
30 | {
31 | // after completed AsyncA, run AsyncB as continuous routine.
32 | // UniRx expands SelectMany(IEnumerator) as SelectMany(IEnumerator.ToObservable())
33 | var cancel = Observable.FromCoroutine(AsyncA)
34 | .SelectMany(AsyncB)
35 | .Subscribe();
36 |
37 | // If you want to stop Coroutine(as cancel), call subscription.Dispose()
38 | // cancel.Dispose();
39 | }
40 | }
41 | }
42 |
43 |
44 | #pragma warning restore 0168
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample07_OrchestratIEnumerator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d7f36d874287ba845942ca19312b77b4
3 | timeCreated: 1425282659
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample08_DetectDoubleClick.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using UnityEngine;
7 |
8 | namespace UniRx.Examples
9 | {
10 | public class Sample08_DetectDoubleClick : MonoBehaviour
11 | {
12 | void Start()
13 | {
14 | // Global event handling is very useful.
15 | // UniRx can handle there events.
16 | // Observable.EveryUpdate/EveryFixedUpdate/EveryEndOfFrame
17 | // Observable.EveryApplicationFocus/EveryApplicationPause
18 | // Observable.OnceApplicationQuit
19 |
20 | // This DoubleCLick Sample is from
21 | // The introduction to Reactive Programming you've been missing
22 | // https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
23 |
24 | var clickStream = Observable.EveryUpdate()
25 | .Where(_ => Input.GetMouseButtonDown(0));
26 |
27 | clickStream.Buffer(clickStream.Throttle(TimeSpan.FromMilliseconds(250)))
28 | .Where(xs => xs.Count >= 2)
29 | .Subscribe(xs => Debug.Log("DoubleClick Detected! Count:" + xs.Count));
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample08_DetectDoubleClick.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b528bbabea03ac841844a40408326ffc
3 | timeCreated: 1425282659
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample09_EventHandling.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 03bb64cbe2323dc49b3f4277c2fb534d
3 | timeCreated: 1425282656
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample10_MainThreadDispatcher.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using UnityEngine;
4 |
5 | namespace UniRx.Examples
6 | {
7 | public class Sample10_MainThreadDispatcher
8 | {
9 | public void Run()
10 | {
11 | // MainThreadDispatcher is heart of Rx and Unity integration
12 |
13 | // StartCoroutine can start coroutine besides MonoBehaviour.
14 | MainThreadDispatcher.StartCoroutine(TestAsync());
15 |
16 | // We have two way of run coroutine, FromCoroutine or StartCoroutine.
17 | // StartCoroutine is Unity primitive way and it's awaitable by yield return.
18 | // FromCoroutine is Rx, it's composable and cancellable by subscription's IDisposable.
19 | // FromCoroutine's overload can have return value, see:Sample05_ConvertFromCoroutine
20 | Observable.FromCoroutine(TestAsync).Subscribe();
21 |
22 | // Add Action to MainThreadDispatcher. Action is saved queue, run on next update.
23 | MainThreadDispatcher.Post(_ => Debug.Log("test"), null);
24 |
25 | // Timebased operations is run on MainThread(as default)
26 | // All timebased operation(Interval, Timer, Delay, Buffer, etc...)is single thread, thread safe!
27 | Observable.Interval(TimeSpan.FromSeconds(1))
28 | .Subscribe(x => Debug.Log(x));
29 |
30 | // Observable.Start use ThreadPool Scheduler as default.
31 | // ObserveOnMainThread return to mainthread
32 | Observable.Start(() => Unit.Default) // asynchronous work
33 | .ObserveOnMainThread()
34 | .Subscribe(x => Debug.Log(x));
35 | }
36 |
37 | IEnumerator TestAsync()
38 | {
39 | Debug.Log("a");
40 | yield return new WaitForSeconds(1);
41 | Debug.Log("b");
42 | yield return new WaitForSeconds(1);
43 | Debug.Log("c");
44 | yield return new WaitForSeconds(1);
45 | Debug.Log("d");
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample10_MainThreadDispatcher.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a7e9627c7376c5e4abad3a2982051721
3 | timeCreated: 1425282659
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample11_Logger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using UniRx.Diagnostics;
4 | using UnityEngine;
5 |
6 | namespace UniRx.Examples
7 | {
8 | public class Sample11_Logger
9 | {
10 | // UniRx.Diagnostics.Logger
11 | // logger is threadsafe, define per class with name.
12 | static readonly UniRx.Diagnostics.Logger logger = new UniRx.Diagnostics.Logger("Sample11");
13 |
14 | // call once at applicationinit
15 | public void ApplicationInitialize()
16 | {
17 | // Log as Stream, UniRx.Diagnostics.ObservableLogger.Listener is IObservable
18 | // You can subscribe and output to any place.
19 | ObservableLogger.Listener.LogToUnityDebug();
20 |
21 | // for example, filter only Exception and upload to web.
22 | // (make custom sink(IObserver) is better to use)
23 | ObservableLogger.Listener
24 | .Where(x => x.LogType == LogType.Exception)
25 | .Subscribe(x =>
26 | {
27 | // ObservableWWW.Post("", null).Subscribe();
28 | });
29 | }
30 |
31 | public void Run()
32 | {
33 | // Debug is write only DebugBuild.
34 | logger.Debug("Debug Message");
35 |
36 | // or other logging methods
37 | logger.Log("Message");
38 | logger.Exception(new Exception("test exception"));
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample11_Logger.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 69a86d851de4ff84aaf023d707d0f1ad
3 | timeCreated: 1425282658
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample12Scene.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e11e18571780f7344a92e1a45974701a
3 | timeCreated: 1425643117
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample12_ReactiveProperty.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 577cad547552f9f4e9e993261db7ab44
3 | timeCreated: 1425637242
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample13Scene.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 862645bd3c32c054ebb7c31d903605be
3 | timeCreated: 1425907486
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample13_ToDoApp.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 89a489c663a87e348ac12644ee59f898
3 | timeCreated: 1425907659
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample13_ToDoItem.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d7059502be0050c4a9cd9ef0e82a720b
3 | timeCreated: 1426146513
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample14Scene.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e388e4fa5c5dec9408daacff8d477857
3 | timeCreated: 1429741593
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample14_CubeLevel1.cs:
--------------------------------------------------------------------------------
1 | using UniRx;
2 | using UnityEngine;
3 |
4 | namespace Assets.UniRx.Examples
5 | {
6 | // see:Sample14_PresenterBase
7 | public class Sample14_CubeLevel1 : PresenterBase
8 | {
9 | public IReactiveProperty Number { get; private set; }
10 |
11 | public Sample14_CubeLevel2 child1;
12 | public Sample14_CubeLevel2 child2;
13 |
14 | protected override IPresenter[] Children
15 | {
16 | get
17 | {
18 | return new IPresenter[] { child1, child2 };
19 | }
20 | }
21 |
22 | protected override void OnAwake()
23 | {
24 | AnimationMarker.MarkAwakePhase(this);
25 | }
26 |
27 | protected override void BeforeInitialize(float argument)
28 | {
29 | AnimationMarker.MarkCapturePhase(this);
30 |
31 | child1.PropagateArgument(argument * 2);
32 | child2.PropagateArgument(argument * 2);
33 | }
34 |
35 | // Initialize is like constructor.
36 | // This phase, called child -> parent.
37 | // Therefore you can touch child's property safety.
38 | protected override void Initialize(float argument)
39 | {
40 | AnimationMarker.MarkBubblingPhase(this);
41 |
42 | Number = new ReactiveProperty(argument);
43 | Number.Subscribe(x =>
44 | {
45 | child1.Number.Value = x;
46 | child2.Number.Value = x;
47 | this.GetComponent().material.color = new Color(0.2f, x, 0.2f, 0);
48 | });
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample14_CubeLevel1.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a9894994bae43b94ca032056937e378c
3 | timeCreated: 1429739583
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 50
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample14_CubeLevel2.cs:
--------------------------------------------------------------------------------
1 | using UniRx;
2 | using UnityEngine;
3 |
4 | namespace Assets.UniRx.Examples
5 | {
6 | public class Sample14_CubeLevel2 : PresenterBase
7 | {
8 | public IReactiveProperty Number { get;private set; }
9 |
10 | protected override IPresenter[] Children
11 | {
12 | get
13 | {
14 | return EmptyChildren;
15 | }
16 | }
17 |
18 | protected override void OnAwake()
19 | {
20 | AnimationMarker.MarkAwakePhase(this);
21 | }
22 |
23 | protected override void BeforeInitialize(float argument)
24 | {
25 | AnimationMarker.MarkCapturePhase(this);
26 | }
27 |
28 | protected override void Initialize(float argument)
29 | {
30 | AnimationMarker.MarkBubblingPhase(this);
31 |
32 | Number = new ReactiveProperty(argument);
33 | Number.Subscribe(x =>
34 | {
35 | this.GetComponent().material.color = new Color(x, 0.2f, 0.2f, 0);
36 | });
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample14_CubeLevel2.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b6a11a427af74204dad7e88d3204a889
3 | timeCreated: 1429739565
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 100
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Examples/Sample14_PresenterBase.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d4c7b0029a0874243b11788de7d1e4aa
3 | timeCreated: 1429739565
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 300
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Disposables/BooleanDisposable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 |
4 | namespace UniRx
5 | {
6 | public class BooleanDisposable : IDisposable, ICancelable
7 | {
8 | public bool IsDisposed { get; private set; }
9 |
10 | public BooleanDisposable()
11 | {
12 |
13 | }
14 |
15 | internal BooleanDisposable(bool isDisposed)
16 | {
17 | IsDisposed = isDisposed;
18 | }
19 |
20 | public void Dispose()
21 | {
22 | if (!IsDisposed) IsDisposed = true;
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Disposables/Disposable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 |
4 | namespace UniRx
5 | {
6 | public static class Disposable
7 | {
8 | public static readonly IDisposable Empty = EmptyDisposable.Singleton;
9 |
10 | public static IDisposable Create(Action disposeAction)
11 | {
12 | return new AnonymousDisposable(disposeAction);
13 | }
14 |
15 | class EmptyDisposable : IDisposable
16 | {
17 | public static EmptyDisposable Singleton = new EmptyDisposable();
18 |
19 | private EmptyDisposable()
20 | {
21 |
22 | }
23 |
24 | public void Dispose()
25 | {
26 | }
27 | }
28 |
29 | class AnonymousDisposable : IDisposable
30 | {
31 | bool isDisposed = false;
32 | readonly Action dispose;
33 |
34 | public AnonymousDisposable(Action dispose)
35 | {
36 | this.dispose = dispose;
37 | }
38 |
39 | public void Dispose()
40 | {
41 | if (!isDisposed)
42 | {
43 | isDisposed = true;
44 | dispose();
45 | }
46 | }
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Disposables/DisposableExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace UniRx
5 | {
6 | public static partial class DisposableExtensions
7 | {
8 | /// Add disposable(self) to CompositeDisposable(or other ICollection). Return value is self disposable.
9 | public static T AddTo(this T disposable, ICollection container)
10 | where T : IDisposable
11 | {
12 | if (disposable == null) throw new ArgumentNullException("disposable");
13 | if (container == null) throw new ArgumentNullException("container");
14 |
15 | container.Add(disposable);
16 |
17 | return disposable;
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Disposables/ICancelable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace UniRx
6 | {
7 | public interface ICancelable : IDisposable
8 | {
9 | bool IsDisposed { get; }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Disposables/MultipleAssignmentDisposable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 |
4 | namespace UniRx
5 | {
6 | public class MultipleAssignmentDisposable : IDisposable, ICancelable
7 | {
8 | static readonly BooleanDisposable True = new BooleanDisposable(true);
9 |
10 | object gate = new object();
11 | IDisposable current;
12 |
13 | public bool IsDisposed
14 | {
15 | get
16 | {
17 | lock (gate)
18 | {
19 | return current == True;
20 | }
21 | }
22 | }
23 |
24 | public IDisposable Disposable
25 | {
26 | get
27 | {
28 | lock (gate)
29 | {
30 | return (current == True)
31 | ? UniRx.Disposable.Empty
32 | : current;
33 | }
34 | }
35 | set
36 | {
37 | var shouldDispose = false;
38 | lock (gate)
39 | {
40 | shouldDispose = (current == True);
41 | if (!shouldDispose)
42 | {
43 | current = value;
44 | }
45 | }
46 | if (shouldDispose && value != null)
47 | {
48 | value.Dispose();
49 | }
50 | }
51 | }
52 |
53 | public void Dispose()
54 | {
55 | IDisposable old = null;
56 |
57 | lock (gate)
58 | {
59 | if (current != True)
60 | {
61 | old = current;
62 | current = True;
63 | }
64 | }
65 |
66 | if (old != null) old.Dispose();
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Disposables/ScheduledDisposable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 |
4 | namespace UniRx
5 | {
6 | public sealed class ScheduledDisposable : ICancelable
7 | {
8 | private readonly IScheduler scheduler;
9 | private volatile IDisposable disposable;
10 | private int isDisposed = 0;
11 |
12 | public ScheduledDisposable(IScheduler scheduler, IDisposable disposable)
13 | {
14 | this.scheduler = scheduler;
15 | this.disposable = disposable;
16 | }
17 |
18 | public IScheduler Scheduler
19 | {
20 | get { return scheduler; }
21 | }
22 |
23 | public IDisposable Disposable
24 | {
25 | get { return disposable; }
26 | }
27 |
28 | public bool IsDisposed
29 | {
30 | get { return isDisposed != 0; }
31 | }
32 |
33 | public void Dispose()
34 | {
35 | Scheduler.Schedule(DisposeInner);
36 | }
37 |
38 | private void DisposeInner()
39 | {
40 | if (Interlocked.Increment(ref isDisposed) == 1)
41 | {
42 | disposable.Dispose();
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Disposables/SerialDisposable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 |
4 | namespace UniRx
5 | {
6 | public class SerialDisposable : IDisposable, ICancelable
7 | {
8 | readonly object gate = new object();
9 | IDisposable current;
10 | bool disposed;
11 |
12 | public bool IsDisposed { get { lock (gate) { return disposed; } } }
13 |
14 | public IDisposable Disposable
15 | {
16 | get
17 | {
18 | return current;
19 | }
20 | set
21 | {
22 | var shouldDispose = false;
23 | var old = default(IDisposable);
24 | lock (gate)
25 | {
26 | shouldDispose = disposed;
27 | if (!shouldDispose)
28 | {
29 | old = current;
30 | current = value;
31 | }
32 | }
33 | if (old != null)
34 | {
35 | old.Dispose();
36 | }
37 | if (shouldDispose && value != null)
38 | {
39 | value.Dispose();
40 | }
41 | }
42 | }
43 |
44 | public void Dispose()
45 | {
46 | var old = default(IDisposable);
47 |
48 | lock (gate)
49 | {
50 | if (!disposed)
51 | {
52 | disposed = true;
53 | old = current;
54 | current = null;
55 | }
56 | }
57 |
58 | if (old != null)
59 | {
60 | old.Dispose();
61 | }
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Disposables/SingleAssignmentDisposable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 |
4 | namespace UniRx
5 | {
6 | // should be use Interlocked.CompareExchange for Threadsafe?
7 | // but CompareExchange cause ExecutionEngineException on iOS.
8 | // AOT...
9 | // use lock instead
10 |
11 | public class SingleAssignmentDisposable : IDisposable, ICancelable
12 | {
13 | readonly object gate = new object();
14 | IDisposable current;
15 | bool disposed;
16 |
17 | public bool IsDisposed { get { lock (gate) { return disposed; } } }
18 |
19 | public IDisposable Disposable
20 | {
21 | get
22 | {
23 | return current;
24 | }
25 | set
26 | {
27 | var old = default(IDisposable);
28 | bool alreadyDisposed;
29 | lock (gate)
30 | {
31 | alreadyDisposed = disposed;
32 | old = current;
33 | if (!alreadyDisposed)
34 | {
35 | if (value == null) return;
36 | current = value;
37 | }
38 | }
39 |
40 | if (alreadyDisposed && value != null)
41 | {
42 | value.Dispose();
43 | return;
44 | }
45 |
46 | if (old != null) throw new InvalidOperationException("Disposable is already set");
47 | }
48 | }
49 |
50 |
51 | public void Dispose()
52 | {
53 | IDisposable old = null;
54 |
55 | lock (gate)
56 | {
57 | if (!disposed)
58 | {
59 | disposed = true;
60 | old = current;
61 | current = null;
62 | }
63 | }
64 |
65 | if (old != null) old.Dispose();
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/InternalUtil/ImmutableList.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.InternalUtil
4 | {
5 | public class ImmutableList
6 | {
7 | public static readonly ImmutableList Empty = new ImmutableList();
8 |
9 | T[] data;
10 |
11 | public T[] Data
12 | {
13 | get { return data; }
14 | }
15 |
16 | ImmutableList()
17 | {
18 | data = new T[0];
19 | }
20 |
21 | public ImmutableList(T[] data)
22 | {
23 | this.data = data;
24 | }
25 |
26 | public ImmutableList Add(T value)
27 | {
28 | var newData = new T[data.Length + 1];
29 | Array.Copy(data, newData, data.Length);
30 | newData[data.Length] = value;
31 | return new ImmutableList(newData);
32 | }
33 |
34 | public ImmutableList Remove(T value)
35 | {
36 | var i = IndexOf(value);
37 | if (i < 0) return this;
38 |
39 | var length = data.Length;
40 | if (length == 1) return Empty;
41 |
42 | var newData = new T[length - 1];
43 |
44 | Array.Copy(data, 0, newData, 0, i);
45 | Array.Copy(data, i + 1, newData, i, length - i - 1);
46 |
47 | return new ImmutableList(newData);
48 | }
49 |
50 | public int IndexOf(T value)
51 | {
52 | for (var i = 0; i < data.Length; ++i)
53 | {
54 | // ImmutableList only use for IObserver(no worry for boxed)
55 | if (object.Equals(data[i], value)) return i;
56 | }
57 | return -1;
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Notifiers/BooleanNotifier.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace UniRx
6 | {
7 | ///
8 | /// Notify boolean flag.
9 | ///
10 | public class BooleanNotifier : IObservable
11 | {
12 | readonly Subject boolTrigger = new Subject();
13 |
14 | bool boolValue;
15 | /// Current flag value
16 | public bool Value
17 | {
18 | get { return boolValue; }
19 | set
20 | {
21 | boolValue = value;
22 | boolTrigger.OnNext(value);
23 | }
24 | }
25 |
26 | ///
27 | /// Setup initial flag.
28 | ///
29 | public BooleanNotifier(bool initialValue = false)
30 | {
31 | this.Value = initialValue;
32 | }
33 |
34 | ///
35 | /// Set and raise true if current value isn't true.
36 | ///
37 | public void TurnOn()
38 | {
39 | if (Value != true)
40 | {
41 | Value = true;
42 | }
43 | }
44 |
45 | ///
46 | /// Set and raise false if current value isn't false.
47 | ///
48 | public void TurnOff()
49 | {
50 | if (Value != false)
51 | {
52 | Value = false;
53 | }
54 | }
55 |
56 | ///
57 | /// Set and raise reverse value.
58 | ///
59 | public void SwitchValue()
60 | {
61 | Value = !Value;
62 | }
63 |
64 |
65 | ///
66 | /// Subscribe observer.
67 | ///
68 | public IDisposable Subscribe(IObserver observer)
69 | {
70 | return boolTrigger.Subscribe(observer);
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Observable.Aggregate.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using UniRx.Operators;
5 |
6 | namespace UniRx
7 | {
8 | public static partial class Observable
9 | {
10 | public static IObservable Scan(this IObservable source, Func accumulator)
11 | {
12 | return new ScanObservable(source, accumulator);
13 | }
14 |
15 | public static IObservable Scan(this IObservable source, TAccumulate seed, Func accumulator)
16 | {
17 | return new ScanObservable(source, seed, accumulator);
18 | }
19 |
20 | public static IObservable Aggregate(this IObservable source, Func accumulator)
21 | {
22 | return new AggregateObservable(source, accumulator);
23 | }
24 |
25 | public static IObservable Aggregate(this IObservable source, TAccumulate seed, Func accumulator)
26 | {
27 | return new AggregateObservable(source, seed, accumulator);
28 | }
29 |
30 | public static IObservable Aggregate(this IObservable source, TAccumulate seed, Func accumulator, Func resultSelector)
31 | {
32 | return new AggregateObservable(source, seed, accumulator, resultSelector);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Observable.Blocking.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx
4 | {
5 | public static partial class Observable
6 | {
7 | public static T Wait(this IObservable source)
8 | {
9 | return new UniRx.Operators.Wait(source, InfiniteTimeSpan).Run();
10 | }
11 |
12 | public static T Wait(this IObservable source, TimeSpan timeout)
13 | {
14 | return new UniRx.Operators.Wait(source, timeout).Run();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Observable.Events.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UniRx.Operators;
3 |
4 | namespace UniRx
5 | {
6 | public static partial class Observable
7 | {
8 | public static IObservable> FromEventPattern(Func, TDelegate> conversion, Action addHandler, Action removeHandler)
9 | where TEventArgs : EventArgs
10 | {
11 | return new FromEventPatternObservable(conversion, addHandler, removeHandler);
12 | }
13 |
14 | public static IObservable FromEvent(Func conversion, Action addHandler, Action removeHandler)
15 | {
16 | return new FromEventObservable(conversion, addHandler, removeHandler);
17 | }
18 |
19 | public static IObservable FromEvent(Func, TDelegate> conversion, Action addHandler, Action removeHandler)
20 | {
21 | return new FromEventObservable(conversion, addHandler, removeHandler);
22 | }
23 |
24 | public static IObservable FromEvent(Action addHandler, Action removeHandler)
25 | {
26 | return new FromEventObservable(addHandler, removeHandler);
27 | }
28 |
29 | public static IObservable FromEvent(Action> addHandler, Action> removeHandler)
30 | {
31 | return new FromEventObservable_(addHandler, removeHandler);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Observable.Joins.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace UniRx
6 | {
7 | public static partial class Observable
8 | {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/AsObservable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UniRx.Operators;
3 |
4 | namespace UniRx.Operators
5 | {
6 | internal class AsObservableObservable : OperatorObservableBase
7 | {
8 | readonly IObservable source;
9 |
10 | public AsObservableObservable(IObservable source)
11 | : base(source.IsRequiredSubscribeOnCurrentThread())
12 | {
13 | this.source = source;
14 | }
15 |
16 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
17 | {
18 | return source.Subscribe(new AsObservable(observer, cancel));
19 | }
20 |
21 | class AsObservable : OperatorObserverBase
22 | {
23 | public AsObservable(IObserver observer, IDisposable cancel) : base(observer, cancel)
24 | {
25 | }
26 |
27 | public override void OnNext(T value)
28 | {
29 | base.observer.OnNext(value);
30 | }
31 |
32 | public override void OnError(Exception error)
33 | {
34 | try { observer.OnError(error); }
35 | finally { Dispose(); }
36 | }
37 |
38 | public override void OnCompleted()
39 | {
40 | try { observer.OnCompleted(); }
41 | finally { Dispose(); }
42 | }
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/AsUnitObservable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class AsUnitObservableObservable : OperatorObservableBase
6 | {
7 | readonly IObservable source;
8 |
9 | public AsUnitObservableObservable(IObservable source)
10 | : base(source.IsRequiredSubscribeOnCurrentThread())
11 | {
12 | this.source = source;
13 | }
14 |
15 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
16 | {
17 | return source.Subscribe(new AsUnitObservable(observer, cancel));
18 | }
19 |
20 | class AsUnitObservable : OperatorObserverBase
21 | {
22 | public AsUnitObservable(IObserver observer, IDisposable cancel)
23 | : base(observer, cancel)
24 | {
25 | }
26 |
27 | public override void OnNext(T value)
28 | {
29 | base.observer.OnNext(Unit.Default);
30 | }
31 |
32 | public override void OnError(Exception error)
33 | {
34 | try { observer.OnError(error); }
35 | finally { Dispose(); }
36 | }
37 |
38 | public override void OnCompleted()
39 | {
40 | try { observer.OnCompleted(); }
41 | finally { Dispose(); }
42 | }
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/Cast.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class CastObservable : OperatorObservableBase
6 | {
7 | readonly IObservable source;
8 |
9 | public CastObservable(IObservable source)
10 | : base(source.IsRequiredSubscribeOnCurrentThread())
11 | {
12 | this.source = source;
13 | }
14 |
15 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
16 | {
17 | return source.Subscribe(new Cast(observer, cancel));
18 | }
19 |
20 | class Cast : OperatorObserverBase
21 | {
22 | public Cast(IObserver observer, IDisposable cancel)
23 | : base(observer, cancel)
24 | {
25 | }
26 |
27 | public override void OnNext(TSource value)
28 | {
29 | var castValue = default(TResult);
30 | try
31 | {
32 | castValue = (TResult)(object)value;
33 | }
34 | catch (Exception ex)
35 | {
36 | try { observer.OnError(ex); }
37 | finally { Dispose(); }
38 | return;
39 | }
40 |
41 | observer.OnNext(castValue);
42 | }
43 |
44 | public override void OnError(Exception error)
45 | {
46 | try { observer.OnError(error); }
47 | finally { Dispose(); }
48 | }
49 |
50 | public override void OnCompleted()
51 | {
52 | try { observer.OnCompleted(); }
53 | finally { Dispose(); }
54 | }
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/DefaultIfEmpty.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UniRx.Operators;
3 |
4 | namespace UniRx.Operators
5 | {
6 | internal class DefaultIfEmptyObservable : OperatorObservableBase
7 | {
8 | readonly IObservable source;
9 | readonly T defaultValue;
10 |
11 | public DefaultIfEmptyObservable(IObservable source, T defaultValue)
12 | : base(source.IsRequiredSubscribeOnCurrentThread())
13 | {
14 | this.source = source;
15 | this.defaultValue = defaultValue;
16 | }
17 |
18 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
19 | {
20 | return source.Subscribe(new DefaultIfEmpty(this, observer, cancel));
21 | }
22 |
23 | class DefaultIfEmpty : OperatorObserverBase
24 | {
25 | readonly DefaultIfEmptyObservable parent;
26 | bool hasValue;
27 |
28 | public DefaultIfEmpty(DefaultIfEmptyObservable parent, IObserver observer, IDisposable cancel) : base(observer, cancel)
29 | {
30 | this.parent = parent;
31 | this.hasValue = false;
32 | }
33 |
34 | public override void OnNext(T value)
35 | {
36 | hasValue = true;
37 | observer.OnNext(value);
38 | }
39 |
40 | public override void OnError(Exception error)
41 | {
42 | try { observer.OnError(error); }
43 | finally { Dispose(); }
44 | }
45 |
46 | public override void OnCompleted()
47 | {
48 | if (!hasValue)
49 | {
50 | observer.OnNext(parent.defaultValue);
51 | }
52 |
53 | try { observer.OnCompleted(); }
54 | finally { Dispose(); }
55 | }
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/Defer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class DeferObservable : OperatorObservableBase
6 | {
7 | readonly Func> observableFactory;
8 |
9 | public DeferObservable(Func> observableFactory)
10 | : base(false)
11 | {
12 | this.observableFactory = observableFactory;
13 | }
14 |
15 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
16 | {
17 | observer = new Defer(observer, cancel);
18 |
19 | IObservable source;
20 | try
21 | {
22 | source = observableFactory();
23 | }
24 | catch (Exception ex)
25 | {
26 | source = Observable.Throw(ex);
27 | }
28 |
29 | return source.Subscribe(observer);
30 | }
31 |
32 | class Defer : OperatorObserverBase
33 | {
34 | public Defer(IObserver observer, IDisposable cancel) : base(observer, cancel)
35 | {
36 | }
37 |
38 | public override void OnNext(T value)
39 | {
40 | try
41 | {
42 | base.observer.OnNext(value);
43 | }
44 | catch
45 | {
46 | Dispose();
47 | throw;
48 | }
49 | }
50 |
51 | public override void OnError(Exception error)
52 | {
53 | try { observer.OnError(error); }
54 | finally { Dispose(); }
55 | }
56 |
57 | public override void OnCompleted()
58 | {
59 | try { observer.OnCompleted(); }
60 | finally { Dispose(); }
61 | }
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/DelaySubscription.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace UniRx.Operators
5 | {
6 | internal class DelaySubscriptionObservable : OperatorObservableBase
7 | {
8 | readonly IObservable source;
9 | readonly IScheduler scheduler;
10 | readonly TimeSpan? dueTimeT;
11 | readonly DateTimeOffset? dueTimeD;
12 |
13 | public DelaySubscriptionObservable(IObservable source,TimeSpan dueTime, IScheduler scheduler)
14 | : base(scheduler == Scheduler.CurrentThread || source.IsRequiredSubscribeOnCurrentThread())
15 | {
16 | this.source = source;
17 | this.scheduler = scheduler;
18 | this.dueTimeT = dueTime;
19 | }
20 |
21 | public DelaySubscriptionObservable(IObservable source, DateTimeOffset dueTime, IScheduler scheduler)
22 | : base(scheduler == Scheduler.CurrentThread || source.IsRequiredSubscribeOnCurrentThread())
23 | {
24 | this.source = source;
25 | this.scheduler = scheduler;
26 | this.dueTimeD = dueTime;
27 | }
28 |
29 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
30 | {
31 | if (dueTimeT != null)
32 | {
33 | var d = new MultipleAssignmentDisposable();
34 | var dt = Scheduler.Normalize(dueTimeT.Value);
35 |
36 | d.Disposable = scheduler.Schedule(dt, () =>
37 | {
38 | d.Disposable = source.Subscribe(observer);
39 | });
40 |
41 | return d;
42 | }
43 | else
44 | {
45 | var d = new MultipleAssignmentDisposable();
46 |
47 | d.Disposable = scheduler.Schedule(dueTimeD.Value, () =>
48 | {
49 | d.Disposable = source.Subscribe(observer);
50 | });
51 |
52 | return d;
53 | }
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/Empty.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class EmptyObservable : OperatorObservableBase
6 | {
7 | readonly IScheduler scheduler;
8 |
9 | public EmptyObservable(IScheduler scheduler)
10 | : base(false)
11 | {
12 | this.scheduler = scheduler;
13 | }
14 |
15 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
16 | {
17 | observer = new Empty(observer, cancel);
18 |
19 | if (scheduler == Scheduler.Immediate)
20 | {
21 | observer.OnCompleted();
22 | return Disposable.Empty;
23 | }
24 | else
25 | {
26 | return scheduler.Schedule(observer.OnCompleted);
27 | }
28 | }
29 |
30 | class Empty : OperatorObserverBase
31 | {
32 | public Empty(IObserver observer, IDisposable cancel) : base(observer, cancel)
33 | {
34 | }
35 |
36 | public override void OnNext(T value)
37 | {
38 | try
39 | {
40 | base.observer.OnNext(value);
41 | }
42 | catch
43 | {
44 | Dispose();
45 | throw;
46 | }
47 | }
48 |
49 | public override void OnError(Exception error)
50 | {
51 | try { observer.OnError(error); }
52 | finally { Dispose(); }
53 | }
54 |
55 | public override void OnCompleted()
56 | {
57 | try { observer.OnCompleted(); }
58 | finally { Dispose(); }
59 | }
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/IgnoreElements.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UniRx.Operators;
3 |
4 | namespace UniRx.Operators
5 | {
6 | internal class IgnoreElementsObservable : OperatorObservableBase
7 | {
8 | readonly IObservable source;
9 |
10 | public IgnoreElementsObservable(IObservable source)
11 | : base(source.IsRequiredSubscribeOnCurrentThread())
12 | {
13 | this.source = source;
14 | }
15 |
16 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
17 | {
18 | return source.Subscribe(new IgnoreElements(observer, cancel));
19 | }
20 |
21 | class IgnoreElements : OperatorObserverBase
22 | {
23 | public IgnoreElements(IObserver observer, IDisposable cancel) : base(observer, cancel)
24 | {
25 | }
26 |
27 | public override void OnNext(T value)
28 | {
29 | }
30 |
31 | public override void OnError(Exception error)
32 | {
33 | try { observer.OnError(error); }
34 | finally { Dispose(); }
35 | }
36 |
37 | public override void OnCompleted()
38 | {
39 | try { observer.OnCompleted(); }
40 | finally { Dispose(); }
41 | }
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/Materialize.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class MaterializeObservable : OperatorObservableBase>
6 | {
7 | readonly IObservable source;
8 |
9 | public MaterializeObservable(IObservable source)
10 | : base(source.IsRequiredSubscribeOnCurrentThread())
11 | {
12 | this.source = source;
13 | }
14 |
15 | protected override IDisposable SubscribeCore(IObserver> observer, IDisposable cancel)
16 | {
17 | return new Materialize(this, observer, cancel).Run();
18 | }
19 |
20 | class Materialize : OperatorObserverBase>
21 | {
22 | readonly MaterializeObservable parent;
23 |
24 | public Materialize(MaterializeObservable parent, IObserver> observer, IDisposable cancel)
25 | : base(observer, cancel)
26 | {
27 | this.parent = parent;
28 | }
29 |
30 | public IDisposable Run()
31 | {
32 | return parent.source.Subscribe(this);
33 | }
34 |
35 | public override void OnNext(T value)
36 | {
37 | observer.OnNext(Notification.CreateOnNext(value));
38 | }
39 |
40 | public override void OnError(Exception error)
41 | {
42 | observer.OnNext(Notification.CreateOnError(error));
43 | try { observer.OnCompleted(); } finally { Dispose(); }
44 | }
45 |
46 | public override void OnCompleted()
47 | {
48 | observer.OnNext(Notification.CreateOnCompleted());
49 | try { observer.OnCompleted(); } finally { Dispose(); }
50 | }
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/Never.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class NeverObservable : OperatorObservableBase
6 | {
7 | public NeverObservable()
8 | : base(false)
9 | {
10 | }
11 |
12 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
13 | {
14 | return Disposable.Empty;
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/OfType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class OfTypeObservable : OperatorObservableBase
6 | {
7 | readonly IObservable source;
8 |
9 | public OfTypeObservable(IObservable source)
10 | : base(source.IsRequiredSubscribeOnCurrentThread())
11 | {
12 | this.source = source;
13 | }
14 |
15 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
16 | {
17 | return source.Subscribe(new OfType(observer, cancel));
18 | }
19 |
20 | class OfType : OperatorObserverBase
21 | {
22 | public OfType(IObserver observer, IDisposable cancel)
23 | : base(observer, cancel)
24 | {
25 | }
26 |
27 | public override void OnNext(TSource value)
28 | {
29 | if (value is TResult)
30 | {
31 | var castValue = (TResult)(object)value;
32 | observer.OnNext(castValue);
33 | }
34 | }
35 |
36 | public override void OnError(Exception error)
37 | {
38 | try { observer.OnError(error); } finally { Dispose(); }
39 | }
40 |
41 | public override void OnCompleted()
42 | {
43 | try { observer.OnCompleted(); } finally { Dispose(); }
44 | }
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/OperatorObservableBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | // implements note : all field must be readonly.
6 | public abstract class OperatorObservableBase : IObservable, IOptimizedObservable
7 | {
8 | readonly bool isRequiredSubscribeOnCurrentThread;
9 |
10 | public OperatorObservableBase(bool isRequiredSubscribeOnCurrentThread)
11 | {
12 | this.isRequiredSubscribeOnCurrentThread = isRequiredSubscribeOnCurrentThread;
13 | }
14 |
15 | public bool IsRequiredSubscribeOnCurrentThread()
16 | {
17 | return isRequiredSubscribeOnCurrentThread;
18 | }
19 |
20 | public IDisposable Subscribe(IObserver observer)
21 | {
22 | var subscription = new SingleAssignmentDisposable();
23 |
24 | // note:
25 | // does not make the safe observer, it breaks exception durability.
26 | // var safeObserver = Observer.CreateAutoDetachObserver(observer, subscription);
27 |
28 | if (isRequiredSubscribeOnCurrentThread && Scheduler.IsCurrentThreadSchedulerScheduleRequired)
29 | {
30 | Scheduler.CurrentThread.Schedule(() => subscription.Disposable = SubscribeCore(observer, subscription));
31 | }
32 | else
33 | {
34 | subscription.Disposable = SubscribeCore(observer, subscription);
35 | }
36 |
37 | return subscription;
38 | }
39 |
40 | protected abstract IDisposable SubscribeCore(IObserver observer, IDisposable cancel);
41 | }
42 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/OperatorObserverBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 |
4 | namespace UniRx.Operators
5 | {
6 | public abstract class OperatorObserverBase : IDisposable, IObserver
7 | {
8 | protected internal volatile IObserver observer;
9 | IDisposable cancel;
10 |
11 | public OperatorObserverBase(IObserver observer, IDisposable cancel)
12 | {
13 | this.observer = observer;
14 | this.cancel = cancel;
15 | }
16 |
17 | public abstract void OnNext(TSource value);
18 |
19 | public abstract void OnError(Exception error);
20 |
21 | public abstract void OnCompleted();
22 |
23 | public void Dispose()
24 | {
25 | observer = UniRx.InternalUtil.EmptyObserver.Instance;
26 | var target = System.Threading.Interlocked.Exchange(ref cancel, null);
27 | if (target != null)
28 | {
29 | target.Dispose();
30 | }
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/Return.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class ReturnObservable : OperatorObservableBase
6 | {
7 | readonly T value;
8 | readonly IScheduler scheduler;
9 |
10 | public ReturnObservable(T value, IScheduler scheduler)
11 | : base(scheduler == Scheduler.CurrentThread)
12 | {
13 | this.value = value;
14 | this.scheduler = scheduler;
15 | }
16 |
17 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
18 | {
19 | observer = new Return(observer, cancel);
20 |
21 | if (scheduler == Scheduler.Immediate)
22 | {
23 | observer.OnNext(value);
24 | observer.OnCompleted();
25 | return Disposable.Empty;
26 | }
27 | else
28 | {
29 | return scheduler.Schedule(() =>
30 | {
31 | observer.OnNext(value);
32 | observer.OnCompleted();
33 | });
34 | }
35 | }
36 |
37 | class Return : OperatorObserverBase
38 | {
39 | public Return(IObserver observer, IDisposable cancel)
40 | : base(observer, cancel)
41 | {
42 | }
43 |
44 | public override void OnNext(T value)
45 | {
46 | try
47 | {
48 | base.observer.OnNext(value);
49 | }
50 | catch
51 | {
52 | Dispose();
53 | throw;
54 | }
55 | }
56 |
57 | public override void OnError(Exception error)
58 | {
59 | try { observer.OnError(error); }
60 | finally { Dispose(); }
61 | }
62 |
63 | public override void OnCompleted()
64 | {
65 | try { observer.OnCompleted(); }
66 | finally { Dispose(); }
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/SubscribeOn.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace UniRx.Operators
5 | {
6 | internal class SubscribeOnObservable : OperatorObservableBase
7 | {
8 | readonly IObservable source;
9 | readonly IScheduler scheduler;
10 |
11 | public SubscribeOnObservable(IObservable source, IScheduler scheduler)
12 | : base(scheduler == Scheduler.CurrentThread || source.IsRequiredSubscribeOnCurrentThread())
13 | {
14 | this.source = source;
15 | this.scheduler = scheduler;
16 | }
17 |
18 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
19 | {
20 | var m = new SingleAssignmentDisposable();
21 | var d = new SerialDisposable();
22 | d.Disposable = m;
23 |
24 | m.Disposable = scheduler.Schedule(() =>
25 | {
26 | d.Disposable = new ScheduledDisposable(scheduler, source.Subscribe(observer));
27 | });
28 |
29 | return d;
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/Synchronize.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UniRx.Operators;
3 |
4 | namespace UniRx.Operators
5 | {
6 | internal class SynchronizeObservable : OperatorObservableBase
7 | {
8 | readonly IObservable source;
9 | readonly object gate;
10 |
11 | public SynchronizeObservable(IObservable source, object gate)
12 | : base(source.IsRequiredSubscribeOnCurrentThread())
13 | {
14 | this.source = source;
15 | this.gate = gate;
16 | }
17 |
18 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
19 | {
20 | return source.Subscribe(new Synchronize(this, observer, cancel));
21 | }
22 |
23 | class Synchronize : OperatorObserverBase
24 | {
25 | readonly SynchronizeObservable parent;
26 |
27 | public Synchronize(SynchronizeObservable parent, IObserver observer, IDisposable cancel) : base(observer, cancel)
28 | {
29 | this.parent = parent;
30 | }
31 |
32 | public override void OnNext(T value)
33 | {
34 | lock (parent.gate)
35 | {
36 | base.observer.OnNext(value);
37 | }
38 | }
39 |
40 | public override void OnError(Exception error)
41 | {
42 | lock (parent.gate)
43 | {
44 | try { observer.OnError(error); } finally { Dispose(); };
45 | }
46 | }
47 |
48 | public override void OnCompleted()
49 | {
50 | lock (parent.gate)
51 | {
52 | try { observer.OnCompleted(); } finally { Dispose(); };
53 | }
54 | }
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/Throw.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class ThrowObservable : OperatorObservableBase
6 | {
7 | readonly Exception error;
8 | readonly IScheduler scheduler;
9 |
10 | public ThrowObservable(Exception error, IScheduler scheduler)
11 | : base(scheduler == Scheduler.CurrentThread)
12 | {
13 | this.error = error;
14 | this.scheduler = scheduler;
15 | }
16 |
17 | protected override IDisposable SubscribeCore(IObserver observer, IDisposable cancel)
18 | {
19 | observer = new Throw(observer, cancel);
20 |
21 | if (scheduler == Scheduler.Immediate)
22 | {
23 | observer.OnError(error);
24 | return Disposable.Empty;
25 | }
26 | else
27 | {
28 | return scheduler.Schedule(() =>
29 | {
30 | observer.OnError(error);
31 | observer.OnCompleted();
32 | });
33 | }
34 | }
35 |
36 | class Throw : OperatorObserverBase
37 | {
38 | public Throw(IObserver observer, IDisposable cancel)
39 | : base(observer, cancel)
40 | {
41 | }
42 |
43 | public override void OnNext(T value)
44 | {
45 | try
46 | {
47 | base.observer.OnNext(value);
48 | }
49 | catch
50 | {
51 | Dispose();
52 | throw;
53 | }
54 | }
55 |
56 | public override void OnError(Exception error)
57 | {
58 | try { observer.OnError(error); }
59 | finally { Dispose(); }
60 | }
61 |
62 | public override void OnCompleted()
63 | {
64 | try { observer.OnCompleted(); }
65 | finally { Dispose(); }
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/TimeInterval.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class TimeIntervalObservable : OperatorObservableBase>
6 | {
7 | readonly IObservable source;
8 | readonly IScheduler scheduler;
9 |
10 | public TimeIntervalObservable(IObservable source, IScheduler scheduler)
11 | : base(scheduler == Scheduler.CurrentThread || source.IsRequiredSubscribeOnCurrentThread())
12 | {
13 | this.source = source;
14 | this.scheduler = scheduler;
15 | }
16 |
17 | protected override IDisposable SubscribeCore(IObserver> observer, IDisposable cancel)
18 | {
19 | return source.Subscribe(new TimeInterval(this, observer, cancel));
20 | }
21 |
22 | class TimeInterval : OperatorObserverBase>
23 | {
24 | readonly TimeIntervalObservable parent;
25 | DateTimeOffset lastTime;
26 |
27 | public TimeInterval(TimeIntervalObservable parent, IObserver> observer, IDisposable cancel)
28 | : base(observer, cancel)
29 | {
30 | this.parent = parent;
31 | this.lastTime = parent.scheduler.Now;
32 | }
33 |
34 | public override void OnNext(T value)
35 | {
36 | var now = parent.scheduler.Now;
37 | var span = now.Subtract(lastTime);
38 | lastTime = now;
39 |
40 | base.observer.OnNext(new UniRx.TimeInterval(value, span));
41 | }
42 |
43 | public override void OnError(Exception error)
44 | {
45 | try { observer.OnError(error); }
46 | finally { Dispose(); }
47 | }
48 |
49 | public override void OnCompleted()
50 | {
51 | try { observer.OnCompleted(); }
52 | finally { Dispose(); }
53 | }
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/Timestamp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class TimestampObservable : OperatorObservableBase>
6 | {
7 | readonly IObservable source;
8 | readonly IScheduler scheduler;
9 |
10 | public TimestampObservable(IObservable source, IScheduler scheduler)
11 | : base(scheduler == Scheduler.CurrentThread || source.IsRequiredSubscribeOnCurrentThread())
12 | {
13 | this.source = source;
14 | this.scheduler = scheduler;
15 | }
16 |
17 | protected override IDisposable SubscribeCore(IObserver> observer, IDisposable cancel)
18 | {
19 | return source.Subscribe(new Timestamp(this, observer, cancel));
20 | }
21 |
22 | class Timestamp : OperatorObserverBase>
23 | {
24 | readonly TimestampObservable parent;
25 |
26 | public Timestamp(TimestampObservable parent, IObserver> observer, IDisposable cancel)
27 | : base(observer, cancel)
28 | {
29 | this.parent = parent;
30 | }
31 |
32 | public override void OnNext(T value)
33 | {
34 | base.observer.OnNext(new Timestamped(value, parent.scheduler.Now));
35 | }
36 |
37 | public override void OnError(Exception error)
38 | {
39 | try { observer.OnError(error); }
40 | finally { Dispose(); }
41 | }
42 |
43 | public override void OnCompleted()
44 | {
45 | try { observer.OnCompleted(); }
46 | finally { Dispose(); }
47 | }
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/ToList.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace UniRx.Operators
5 | {
6 | internal class ToListObservable : OperatorObservableBase>
7 | {
8 | readonly IObservable source;
9 |
10 | public ToListObservable(IObservable source)
11 | : base(source.IsRequiredSubscribeOnCurrentThread())
12 | {
13 | this.source = source;
14 | }
15 |
16 | protected override IDisposable SubscribeCore(IObserver> observer, IDisposable cancel)
17 | {
18 | return source.Subscribe(new ToList(observer, cancel));
19 | }
20 |
21 | class ToList : OperatorObserverBase>
22 | {
23 | readonly List list = new List();
24 |
25 | public ToList(IObserver> observer, IDisposable cancel)
26 | : base(observer, cancel)
27 | {
28 | }
29 |
30 | public override void OnNext(TSource value)
31 | {
32 | try
33 | {
34 | list.Add(value); // sometimes cause error on multithread
35 | }
36 | catch (Exception ex)
37 | {
38 | try { observer.OnError(ex); } finally { Dispose(); }
39 | return;
40 | }
41 | }
42 |
43 | public override void OnError(Exception error)
44 | {
45 | try { observer.OnError(error); } finally { Dispose(); }
46 | }
47 |
48 | public override void OnCompleted()
49 | {
50 | base.observer.OnNext(list);
51 | try { observer.OnCompleted(); } finally { Dispose(); };
52 | }
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Operators/Wait.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UniRx.Operators
4 | {
5 | internal class Wait : IObserver
6 | {
7 | static readonly TimeSpan InfiniteTimeSpan = new TimeSpan(0, 0, 0, 0, -1); // from .NET 4.5
8 |
9 | readonly IObservable source;
10 | readonly TimeSpan timeout;
11 |
12 | System.Threading.ManualResetEvent semaphore;
13 |
14 | bool seenValue = false;
15 | T value = default(T);
16 | Exception ex = default(Exception);
17 |
18 | public Wait(IObservable source, TimeSpan timeout)
19 | {
20 | this.source = source;
21 | this.timeout = timeout;
22 | }
23 |
24 | public T Run()
25 | {
26 | semaphore = new System.Threading.ManualResetEvent(false);
27 | using (source.Subscribe(this))
28 | {
29 | var waitComplete = (timeout == InfiniteTimeSpan)
30 | ? semaphore.WaitOne()
31 | : semaphore.WaitOne(timeout);
32 |
33 | if (!waitComplete)
34 | {
35 | throw new TimeoutException("OnCompleted not fired.");
36 | }
37 | }
38 |
39 | if (ex != null) throw ex;
40 | if (!seenValue) throw new InvalidOperationException("No Elements.");
41 |
42 | return value;
43 | }
44 |
45 | public void OnNext(T value)
46 | {
47 | seenValue = true;
48 | this.value = value;
49 | }
50 |
51 | public void OnError(Exception error)
52 | {
53 | this.ex = error;
54 | semaphore.Set();
55 | }
56 |
57 | public void OnCompleted()
58 | {
59 | semaphore.Set();
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/Assets/UniRx/Scripts/Pair.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace UniRx
5 | {
6 | // Pair is used for Observable.Pairwise
7 | [Serializable]
8 | public struct Pair : IEquatable>
9 | {
10 | readonly T previous;
11 | readonly T current;
12 |
13 | public T Previous
14 | {
15 | get { return previous; }
16 | }
17 |
18 | public T Current
19 | {
20 | get { return current; }
21 | }
22 |
23 | public Pair(T previous, T current)
24 | {
25 | this.previous = previous;
26 | this.current = current;
27 | }
28 |
29 | public override int GetHashCode()
30 | {
31 | var comparer = EqualityComparer.Default;
32 |
33 | int h0;
34 | h0 = comparer.GetHashCode(previous);
35 | h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(current);
36 | return h0;
37 | }
38 |
39 | public override bool Equals(object obj)
40 | {
41 | if (!(obj is Pair