### StartAsync Source: https://github.com/neuecc/unirx/wiki/UniRx.Async.Triggers Provides an asynchronous handler for the Start event on a GameObject or Component. ```APIDOC ## `StartAsync` ### Description Provides an asynchronous way to execute logic when the `Start` event is triggered. ### Method Extension Method ### Endpoint N/A (Extension Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp gameobject.StartAsync() // or component.StartAsync() ``` ### Response #### Success Response Returns a `UniTask` that completes when the `Start` event has been processed asynchronously. #### Response Example N/A ``` -------------------------------- ### Start Source: https://github.com/neuecc/unirx/wiki/UniRx Creates an observable sequence that starts with the result of the specified function or action, optionally with a delay or on a specific scheduler. ```APIDOC ## Start ### Description Creates an observable sequence that starts with the result of the specified function or action, optionally with a delay or on a specific scheduler. ### Method Signatures - `IObservable Start(Func function)` - `IObservable Start(Func function, TimeSpan timeSpan)` - `IObservable Start(Func function, IScheduler scheduler)` - `IObservable Start(Func function, TimeSpan timeSpan, IScheduler scheduler)` - `IObservable Start(Action action)` - `IObservable Start(Action action, TimeSpan timeSpan)` - `IObservable Start(Action action, IScheduler scheduler)` - `IObservable Start(Action action, TimeSpan timeSpan, IScheduler scheduler)` ``` -------------------------------- ### AsyncStartTrigger Source: https://github.com/neuecc/unirx/wiki/UniRx.Async.Triggers Provides an asynchronous way to handle the Start event for a MonoBehaviour. ```APIDOC ## AsyncStartTrigger ### Description Handles the Start event asynchronously. ### Methods #### StartAsync() - **Returns**: `UniTask` - A UniTask that completes when the Start event is triggered. ``` -------------------------------- ### Install UniRxAnalyzer NuGet Package Source: https://github.com/neuecc/unirx/blob/master/README.md Command to install the UniRxAnalyzer package for Visual Studio 2015 users. This analyzer helps detect potential issues like unsubscribed streams. ```powershell Install-Package [UniRxAnalyzer](http://www.nuget.org/packages/UniRxAnalyzer) ``` -------------------------------- ### Take Source: https://github.com/neuecc/unirx/wiki/UniRx Returns a specified number of contiguous elements from the start of an observable sequence. ```APIDOC ## Take ### Description Returns a specified number of contiguous elements from the start of an observable sequence. ### Method Signature `IObservable Take(this IObservable source, Int32 count)` `IObservable Take(this IObservable source, TimeSpan duration)` `IObservable Take(this IObservable source, TimeSpan duration, IScheduler scheduler)` ``` -------------------------------- ### StartAsObservable Method Source: https://github.com/neuecc/unirx/wiki/UniRx.Triggers Converts the MonoBehaviour Start event into an Observable stream. Use for initialization logic that should run once when the script becomes active. ```csharp IObservable StartAsObservable() ``` -------------------------------- ### UniTask.WhenAll Promise Constructor Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/UniTask.WhenAll.Generated.txt Initializes a WhenAllPromise for five tasks, setting up initial states and starting the task processing. ```csharp class WhenAllPromise { const int MaxCount = 5; T1 result1; T2 result2; T3 result3; T4 result4; T5 result5; ExceptionDispatchInfo exception; int completeCount; Action whenComplete; public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { this.completeCount = 0; this.whenComplete = null; this.result1 = default(T1); this.result2 = default(T2); this.result3 = default(T3); this.result4 = default(T4); this.result5 = default(T5); this.exception = null; RunTask1(task1); RunTask2(task2); RunTask3(task3); RunTask4(task4); RunTask5(task5); } void TryCallContinuation() { var action = Interlocked.Exchange(ref whenComplete, null); if (action != null) { action.Invoke(); } } ``` -------------------------------- ### AsyncStartTrigger Source: https://github.com/neuecc/unirx/wiki/UniRx.Async.Triggers Provides an asynchronous trigger for the Start event. ```APIDOC ## AsyncStartTrigger ### Description Get an asynchronous trigger for the Start event on a GameObject or Component. ### Method Signature `AsyncStartTrigger GetAsyncStartTrigger(this GameObject gameObject)` `AsyncStartTrigger GetAsyncStartTrigger(this Component component)` ``` -------------------------------- ### WhenAnyPromise Initialization and Task Handling Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/UniTask.WhenAny.Generated.txt Demonstrates the constructor for `WhenAnyPromise` which initializes state and starts running tasks. It includes `RunTask` methods to await individual UniTasks and handle their completion or exceptions. ```csharp class WhenAnyPromise { T0 result0; T1 result1; T2 result2; T3 result3; T4 result4; T5 result5; T6 result6; T7 result7; ExceptionDispatchInfo exception; Action whenComplete; int completeCount; int winArgumentIndex; bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1; public WhenAnyPromise(UniTask task0, UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { this.whenComplete = null; this.exception = null; this.completeCount = 0; this.winArgumentIndex = -1; this.result0 = default(T0); this.result1 = default(T1); this.result2 = default(T2); this.result3 = default(T3); this.result4 = default(T4); this.result5 = default(T5); this.result6 = default(T6); this.result7 = default(T7); RunTask0(task0).Forget(); RunTask1(task1).Forget(); RunTask2(task2).Forget(); RunTask3(task3).Forget(); RunTask4(task4).Forget(); RunTask5(task5).Forget(); RunTask6(task6).Forget(); RunTask7(task7).Forget(); } void TryCallContinuation() { var action = Interlocked.Exchange(ref whenComplete, null); if (action != null) { action.Invoke(); } } async UniTaskVoid RunTask0(UniTask task) { T0 value; try { value = await task; } catch (Exception ex) { exception = ExceptionDispatchInfo.Capture(ex); TryCallContinuation(); return; } var count = Interlocked.Increment(ref completeCount); if (count == 1) { result0 = value; Volatile.Write(ref winArgumentIndex, 0); TryCallContinuation(); } } async UniTaskVoid RunTask1(UniTask task) { T1 value; try { value = await task; } catch (Exception ex) { exception = ExceptionDispatchInfo.Capture(ex); TryCallContinuation(); return; } ``` -------------------------------- ### WhenAllPromise Constructor for 7 Tasks Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/UniTask.WhenAll.Generated.txt Initializes a WhenAllPromise for seven tasks, setting up initial states and starting task processing. ```csharp public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { this.completeCount = 0; this.whenComplete = null; this.result1 = default(T1); this.result2 = default(T2); this.result3 = default(T3); this.result4 = default(T4); this.result5 = default(T5); this.result6 = default(T6); this.result7 = default(T7); this.exception = null; RunTask1(task1); RunTask2(task2); RunTask3(task3); RunTask4(task4); RunTask5(task5); RunTask6(task6); RunTask7(task7); } ``` -------------------------------- ### Start Factory Method with WhenAll Source: https://github.com/neuecc/unirx/blob/master/README.md Uses Observable.Start to run heavy methods on a thread pool scheduler and Observable.WhenAll to await their results. ObserveOnMainThread is used to return to the main thread for UI updates. ```csharp var heavyMethod = Observable.Start(() => { // heavy method... System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); return 10; }); var heavyMethod2 = Observable.Start(() => { // heavy method... System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3)); return 10; }); // Join and await two other thread values Observable.WhenAll(heavyMethod, heavyMethod2) .ObserveOnMainThread() // return to main thread .Subscribe(xs => { // Unity can't touch GameObject from other thread // but use ObserveOnMainThread, you can touch GameObject naturally. (GameObject.Find("myGuiText")).guiText.text = xs[0] + ":" + xs[1]; }); ``` -------------------------------- ### Unity-Specific UniRx Schedulers and Coroutine Conversion Source: https://github.com/neuecc/unirx/blob/master/README.md Provides examples of Unity-specific UniRx features like MainThreadScheduler, starting coroutines, and converting between coroutines and Observables. ```csharp // Unity's singleton UiThread Queue Scheduler Scheduler.MainThreadScheduler ObserveOnMainThread()/SubscribeOnMainThread() // Global StartCoroutine runner MainThreadDispatcher.StartCoroutine(enumerator) // convert Coroutine to IObservable Observable.FromCoroutine((observer, token) => enumerator(observer, token)); // convert IObservable to Coroutine yield return Observable.Range(1, 10).ToYieldInstruction(); // after Unity 5.3, before can use StartAsCoroutine() // Lifetime hooks Observable.EveryApplicationPause(); Observable.EveryApplicationFocus(); Observable.OnceApplicationQuit(); ``` -------------------------------- ### ReactiveCommand Example Source: https://github.com/neuecc/unirx/blob/master/README.md Demonstrates how to use ReactiveCommand for button commands with boolean interactability. The command can only be executed if the player's HP is not zero or less. ```csharp public class Player { public ReactiveProperty Hp; public ReactiveCommand Resurrect; public Player() { Hp = new ReactiveProperty(1000); // If dead, can not execute. Resurrect = Hp.Select(x => x <= 0).ToReactiveCommand(); // Execute when clicked Resurrect.Subscribe(_ => { Hp.Value = 1000; }); } } public class Presenter : MonoBehaviour { public Button resurrectButton; Player player; void Start() { player = new Player(); // If Hp <= 0, can't press button. player.Resurrect.BindTo(resurrectButton); } } ``` -------------------------------- ### WhenAnyPromise Constructor for Three Tasks Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/UniTask.WhenAny.Generated.txt Initializes a WhenAnyPromise for three UniTasks. It sets up initial states and starts the tasks, forgetting them to run in the background. ```csharp public WhenAnyPromise(UniTask task0, UniTask task1, UniTask task2) { this.whenComplete = null; this.exception = null; this.completeCount = 0; this.winArgumentIndex = -1; this.result0 = default(T0); this.result1 = default(T1); this.result2 = default(T2); RunTask0(task0).Forget(); RunTask1(task1).Forget(); RunTask2(task2).Forget(); } ``` -------------------------------- ### WhenAnyPromise Constructor for Four Tasks Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/UniTask.WhenAny.Generated.txt Initializes a WhenAnyPromise for four UniTasks. It sets up initial states and starts the tasks, forgetting them to run in the background. ```csharp public WhenAnyPromise(UniTask task0, UniTask task1, UniTask task2, UniTask task3) { this.whenComplete = null; this.exception = null; this.completeCount = 0; this.winArgumentIndex = -1; this.result0 = default(T0); this.result1 = default(T1); this.result2 = default(T2); this.result3 = default(T3); RunTask0(task0).Forget(); RunTask1(task1).Forget(); RunTask2(task2).Forget(); RunTask3(task3).Forget(); } ``` -------------------------------- ### Unity MonoBehaviour with UniRx Source: https://github.com/neuecc/unirx/blob/master/README.md Example of a MonoBehaviour class demonstrating asynchronous actions using UniRx. IObservable is returned for asynchronous operations. ```csharp // sample class public class Foobar : MonoBehaviour { public IObservable ActionAsync() { // heavy, heavy, action... return Observable.Timer(TimeSpan.FromSeconds(3)).AsUnitObservable(); } } ``` -------------------------------- ### WhenAnyPromise Constructor for Five Tasks Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/UniTask.WhenAny.Generated.txt Initializes a WhenAnyPromise for five tasks. It sets up the initial state and starts the execution of each task runner. ```csharp class WhenAnyPromise { T0 result0; T1 result1; T2 result2; T3 result3; T4 result4; ExceptionDispatchInfo exception; Action whenComplete; int completeCount; int winArgumentIndex; bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1; public WhenAnyPromise(UniTask task0, UniTask task1, UniTask task2, UniTask task3, UniTask task4) { this.whenComplete = null; this.exception = null; this.completeCount = 0; this.winArgumentIndex = -1; this.result0 = default(T0); this.result1 = default(T1); this.result2 = default(T2); this.result3 = default(T3); this.result4 = default(T4); RunTask0(task0).Forget(); RunTask1(task1).Forget(); RunTask2(task2).Forget(); RunTask3(task3).Forget(); RunTask4(task4).Forget(); } } ``` -------------------------------- ### UniTask.WhenAll Promise for Three Tasks Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/UniTask.WhenAll.Generated.txt Manages the completion of three UniTasks, aggregating results or exceptions. It initializes state and starts processing each task. ```csharp class WhenAllPromise { const int MaxCount = 3; T1 result1; T2 result2; T3 result3; ExceptionDispatchInfo exception; int completeCount; Action whenComplete; public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3) { this.completeCount = 0; this.whenComplete = null; this.result1 = default(T1); this.result2 = default(T2); this.result3 = default(T3); this.exception = null; RunTask1(task1); RunTask2(task2); RunTask3(task3); } void TryCallContinuation() { var action = Interlocked.Exchange(ref whenComplete, null); if (action != null) { action.Invoke(); } } void RunTask1(UniTask task) { if (task.IsCompleted) { try { result1 = task.Result; } catch (Exception ex) { exception = ExceptionDispatchInfo.Capture(ex); TryCallContinuation(); return; } var count = Interlocked.Increment(ref completeCount); if (count == MaxCount) { TryCallContinuation(); } } else { RunTask1Async(task).Forget(); } } ``` -------------------------------- ### StartAsCoroutine Source: https://github.com/neuecc/unirx/wiki/UniRx Starts an observable as a coroutine, with optional callbacks for result and error handling. ```APIDOC ## StartAsCoroutine ### Description Automatically starts an observable as a coroutine, with optional callbacks for handling the result, errors, and cancellation. ### Method Signatures - `Coroutine StartAsCoroutine(this IObservable source, CancellationToken cancel = null)` - `Coroutine StartAsCoroutine(this IObservable source, Action onResult, CancellationToken cancel = null)` - `Coroutine StartAsCoroutine(this IObservable source, Action onError, CancellationToken cancel = null)` - `Coroutine StartAsCoroutine(this IObservable source, Action onResult, Action onError, CancellationToken cancel = null)` ``` -------------------------------- ### UniTask WhenAny Promise Constructor (C#) Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/UniTask.WhenAny.Generated.txt Initializes a WhenAnyPromise with multiple UniTasks. It sets up the initial state and starts observing each task. ```csharp class WhenAnyPromise { T0 result0; T1 result1; T2 result2; T3 result3; T4 result4; T5 result5; T6 result6; ExceptionDispatchInfo exception; Action whenComplete; int completeCount; int winArgumentIndex; bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1; public WhenAnyPromise(UniTask task0, UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { this.whenComplete = null; this.exception = null; this.completeCount = 0; this.winArgumentIndex = -1; this.result0 = default(T0); this.result1 = default(T1); this.result2 = default(T2); this.result3 = default(T3); this.result4 = default(T4); this.result5 = default(T5); this.result6 = default(T6); RunTask0(task0).Forget(); RunTask1(task1).Forget(); RunTask2(task2).Forget(); RunTask3(task3).Forget(); RunTask4(task4).Forget(); RunTask5(task5).Forget(); RunTask6(task6).Forget(); } void TryCallContinuation() { var action = Interlocked.Exchange(ref whenComplete, null); if (action != null) { action.Invoke(); } } } ``` -------------------------------- ### UniRx Stream Logger Setup Source: https://github.com/neuecc/unirx/blob/master/README.md Sets up UniRx's ObservableLogger to stream log messages. Configure listeners and filter logs for specific purposes like uploading exceptions. ```csharp // using UniRx.Diagnostics; // logger is threadsafe, define per class with name. static readonly Logger logger = new Logger("Sample11"); // call once at applicationinit public static void ApplicationInitialize() { // Log as Stream, UniRx.Diagnostics.ObservableLogger.Listener is IObservable // You can subscribe and output to any place. ObservableLogger.Listener.LogToUnityDebug(); // for example, filter only Exception and upload to web. // (make custom sink(IObserver) is better to use) ObservableLogger.Listener .Where(x => x.LogType == LogType.Exception) .Subscribe(x => { // ObservableWWW.Post("", null).Subscribe(); }); } // Debug is write only DebugBuild. logger.Debug("Debug Message"); // or other logging methods logger.Log("Message"); logger.Exception(new Exception("test exception")); ``` -------------------------------- ### MicroCoroutine vs Standard Coroutine Performance Source: https://github.com/neuecc/unirx/blob/master/README.md Compares the performance of starting many MicroCoroutines versus standard Unity Coroutines. MicroCoroutines are shown to be significantly faster and more memory efficient. ```csharp int counter; IEnumerator Worker() { while(true) { counter++; yield return null; } } void Start() { for(var i = 0; i < 10000; i++) { // fast, memory efficient MainThreadDispatcher.StartUpdateMicroCoroutine(Worker()); // slow... // StartCoroutine(Worker()); } } ``` -------------------------------- ### Parallel Network Requests with Observable.WhenAll Source: https://github.com/neuecc/unirx/blob/master/README.md Executes multiple HTTP GET requests in parallel and logs parts of their responses. Similar to Task.WhenAll for asynchronous operations. ```csharp // Observable.WhenAll is for parallel asynchronous operation // (It's like Observable.Zip but specialized for single async operations like Task.WhenAll) var parallel = Observable.WhenAll( ObservableWWW.Get("http://google.com/"), ObservableWWW.Get("http://bing.com/"), ObservableWWW.Get("http://unity3d.com/")); parallel.Subscribe(xs => { Debug.Log(xs[0].Substring(0, 100)); // google Debug.Log(xs[1].Substring(0, 100)); // bing Debug.Log(xs[2].Substring(0, 100)); // unity }); ``` -------------------------------- ### StartWith Source: https://github.com/neuecc/unirx/wiki/UniRx Emits the provided values before emitting items from the source observable. ```APIDOC ## StartWith ### Description Emits the provided values before emitting items from the source observable. ### Method Signature `IObservable StartWith(this IObservable source, T[] values)` `IObservable StartWith(this IObservable source, IEnumerable values)` `IObservable StartWith(this IObservable source, IScheduler scheduler, T value)` `IObservable StartWith(this IObservable source, IScheduler scheduler, IEnumerable values)` `IObservable StartWith(this IObservable source, IScheduler scheduler, T[] values)` ``` -------------------------------- ### StartWith Source: https://github.com/neuecc/unirx/wiki/UniRx Prepends a specified value or a value produced by a factory function to an observable sequence. ```APIDOC ## StartWith ### Description Prepends a specified value or a value produced by a factory function to an observable sequence. ### Method Signatures - `IObservable StartWith(this IObservable source, T value)` - `IObservable StartWith(this IObservable source, Func valueFactory)` ``` -------------------------------- ### PlayerLoopHelper.Initialize Method Source: https://github.com/neuecc/unirx/wiki/UniRx.Async Initializes the player loop system with a given player loop structure. This should typically be called once at application startup. ```csharp public static void Initialize(`PlayerLoopSystem&` playerLoop) ``` -------------------------------- ### AsyncTriggerExtensions Class Source: https://github.com/neuecc/unirx/wiki/UniRx.Async.Triggers Extension methods for getting asynchronous trigger components. ```csharp public static class UniRx.Async.Triggers.AsyncTriggerExtensions ``` -------------------------------- ### UniRx.Observer Static Methods Source: https://github.com/neuecc/unirx/wiki/UniRx Provides static methods for creating various types of IObserver instances. ```APIDOC ## UniRx.Observer Static Methods: - **Create**(`Action` onNext): `IObserver` Creates an observer that only handles the onNext event. - **Create**(`Action` onNext, `Action` onError): `IObserver` Creates an observer that handles onNext and onError events. - **Create**(`Action` onNext, `Action` onCompleted): `IObserver` Creates an observer that handles onNext and onCompleted events. - **Create**(`Action` onNext, `Action` onError, `Action` onCompleted): `IObserver` Creates an observer that handles onNext, onError, and onCompleted events. - **CreateAutoDetachObserver**(`IObserver` observer, `IDisposable` disposable): `IObserver` Creates an observer that automatically detaches the provided disposable when the observer is disposed. - **CreateSubscribeObserver**(`Action` onNext, `Action` onError, `Action` onCompleted): `IObserver` Creates an observer that is suitable for direct subscription, handling all three event types. - **CreateSubscribeWithState2Observer**(`TState1` state1, `TState2` state2, `Action` onNext, `Action` onError, `Action` onCompleted): `IObserver` Creates an observer that includes two state parameters for event handlers. - **CreateSubscribeWithState3Observer**(`TState1` state1, `TState2` state2, `TState3` state3, `Action` onNext, `Action` onError, `Action` onCompleted): `IObserver` Creates an observer that includes three state parameters for event handlers. - **CreateSubscribeWithStateObserver**(`TState` state, `Action` onNext, `Action` onError, `Action` onCompleted): `IObserver` Creates an observer that includes a single state parameter for event handlers. ``` -------------------------------- ### AsyncTriggerExtensions Static Methods Source: https://github.com/neuecc/unirx/wiki/UniRx.Async.Triggers Extension methods for getting asynchronous trigger components. ```APIDOC ## AsyncTriggerExtensions ### Static Methods - **AwakeAsync(this `GameObject` gameObject)**: `UniTask` - Extension method to get an asynchronous Awake trigger for a GameObject. - **AwakeAsync(this `Component` component)**: `UniTask` - Extension method to get an asynchronous Awake trigger for a Component. - **GetAsyncAnimatorTrigger(this `GameObject` gameObject)**: `AsyncAnimatorTrigger` - Get for OnAnimatorIKAsync | OnAnimatorMoveAsync. - **GetAsyncAnimatorTrigger(this `Component` component)**: `AsyncAnimatorTrigger` - Get for OnAnimatorIKAsync | OnAnimatorMoveAsync. - **GetAsyncAwakeTrigger(this `GameObject` gameObject)**: `AsyncAwakeTrigger` - Get for AwakeAsync. - **GetAsyncAwakeTrigger(this `Component` component)**: `AsyncAwakeTrigger` - Get for AwakeAsync. - **GetAsyncBeginDragTrigger(this `GameObject` gameObject)**: `AsyncBeginDragTrigger` - Get for OnBeginDragAsync. - **GetAsyncBeginDragTrigger(this `Component` component)**: `AsyncBeginDragTrigger` - Get for OnBeginDragAsync. - **GetAsyncCancelTrigger(this `GameObject` gameObject)**: `AsyncCancelTrigger` - Get for OnCancelAsync. - **GetAsyncCancelTrigger(this `Component` component)**: `AsyncCancelTrigger` - Get for OnCancelAsync. - **GetAsyncCanvasGroupChangedTrigger(this `GameObject` gameObject)**: `AsyncCanvasGroupChangedTrigger` - Get for OnCanvasGroupChangedAsync. - **GetAsyncCanvasGroupChangedTrigger(this `Component` component)**: `AsyncCanvasGroupChangedTrigger` - Get for OnCanvasGroupChangedAsync. - **GetAsyncCollision2DTrigger(this `GameObject` gameObject)**: `AsyncCollision2DTrigger` - Get for OnCollisionEnter2DAsync | OnCollisionExit2DAsync | OnCollisionStay2DAsync. - **GetAsyncCollision2DTrigger(this `Component` component)**: `AsyncCollision2DTrigger` - Get for OnCollisionEnter2DAsync | OnCollisionExit2DAsync | OnCollisionStay2DAsync. - **GetAsyncCollisionTrigger(this `GameObject` gameObject)**: `AsyncCollisionTrigger` - Get for OnCollisionEnterAsync | OnCollisionExitAsync | OnCollisionStayAsync. - **GetAsyncCollisionTrigger(this `Component` component)**: `AsyncCollisionTrigger` - Get for OnCollisionEnterAsync | OnCollisionExitAsync | OnCollisionStayAsync. - **GetAsyncDeselectTrigger(this `GameObject` gameObject)**: `AsyncDeselectTrigger` - Get for OnDeselectAsync. - **GetAsyncDeselectTrigger(this `Component` component)**: `AsyncDeselectTrigger` - Get for OnDeselectAsync. - **GetAsyncDestroyTrigger(this `GameObject` gameObject)**: `AsyncDestroyTrigger` - Get for OnDestroyAsync. - **GetAsyncDestroyTrigger(this `Component` component)**: `AsyncDestroyTrigger` - Get for OnDestroyAsync. - **GetAsyncDragTrigger(this `GameObject` gameObject)**: `AsyncDragTrigger` - Get for OnDragAsync. - **GetAsyncDragTrigger(this `Component` component)**: `AsyncDragTrigger` - Get for OnDragAsync. - **GetAsyncDropTrigger(this `GameObject` gameObject)**: `AsyncDropTrigger` - Get for OnDropAsync. - **GetAsyncDropTrigger(this `Component` component)**: `AsyncDropTrigger` - Get for OnDropAsync. - **GetAsyncEnableDisableTrigger(this `GameObject` gameObject)**: `AsyncEnableDisableTrigger` - Get for OnEnableAsync | OnDisableAsync. - **GetAsyncEnableDisableTrigger(this `Component` component)**: `AsyncEnableDisableTrigger` - Get for OnEnableAsync | OnDisableAsync. - **GetAsyncEndDragTrigger(this `GameObject` gameObject)**: `AsyncEndDragTrigger` - Get for OnEndDragAsync. - **GetAsyncEndDragTrigger(this `Component` component)**: `AsyncEndDragTrigger` - Get for OnEndDragAsync. - **GetAsyncFixedUpdateTrigger(this `GameObject` gameObject)**: `AsyncFixedUpdateTrigger` - Get for FixedUpdateAsync. - **GetAsyncFixedUpdateTrigger(this `Component` component)**: `AsyncFixedUpdateTrigger` - Get for FixedUpdateAsync. ``` -------------------------------- ### WebRequest GetResponseAsObservable Source: https://github.com/neuecc/unirx/wiki/UniRx Extension method to get the web response as an observable sequence of WebResponses. ```csharp IObservable GetResponseAsObservable(this WebRequest request) ``` -------------------------------- ### Zip Operator Run Method (5 Sources) Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/ZipGenerator.txt Initializes the zip operation by subscribing to multiple sources and setting up a disposable for cleanup. This method is part of the internal implementation of the Zip operator. ```csharp public IDisposable Run() { base.SetQueue(new System.Collections.ICollection[] { q1, q2, q3, q4, q5 }); var s1 = parent.source1.Subscribe(new ZipObserver(gate, this, 0, q1)); var s2 = parent.source2.Subscribe(new ZipObserver(gate, this, 1, q2)); var s3 = parent.source3.Subscribe(new ZipObserver(gate, this, 2, q3)); var s4 = parent.source4.Subscribe(new ZipObserver(gate, this, 3, q4)); var s5 = parent.source5.Subscribe(new ZipObserver(gate, this, 4, q5)); return StableCompositeDisposable.Create(s1, s2, s3, s4, s5, Disposable.Create(() => { lock (gate) { q1.Clear(); q2.Clear(); q3.Clear(); q4.Clear(); q5.Clear(); } })); } ``` -------------------------------- ### WebRequest GetRequestStreamAsObservable Source: https://github.com/neuecc/unirx/wiki/UniRx Extension method to get the request stream as an observable sequence of streams. ```csharp IObservable GetRequestStreamAsObservable(this WebRequest request) ``` -------------------------------- ### HttpWebRequest GetResponseAsObservable Source: https://github.com/neuecc/unirx/wiki/UniRx Extension method to get the HTTP web response as an observable sequence of HttpWebResponses. ```csharp IObservable GetResponseAsObservable(this HttpWebRequest request) ``` -------------------------------- ### Get ReactiveCommand Awaiter Source: https://github.com/neuecc/unirx/wiki/UniRx Provides an awaiter for a ReactiveCommand, allowing asynchronous waiting for command execution. ```csharp Awaiter GetAwaiter(this IReactiveCommand command) ``` -------------------------------- ### Zip Operator Run Method (6 Sources) Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/ZipGenerator.txt Initializes the zip operation for six sources by subscribing to each source and setting up a composite disposable for cleanup. This method manages the queues and subscriptions. ```csharp public IDisposable Run() { base.SetQueue(new System.Collections.ICollection[] { q1, q2, q3, q4, q5, q6 }); var s1 = parent.source1.Subscribe(new ZipObserver(gate, this, 0, q1)); var s2 = parent.source2.Subscribe(new ZipObserver(gate, this, 1, q2)); var s3 = parent.source3.Subscribe(new ZipObserver(gate, this, 2, q3)); var s4 = parent.source4.Subscribe(new ZipObserver(gate, this, 3, q4)); var s5 = parent.source5.Subscribe(new ZipObserver(gate, this, 4, q5)); var s6 = parent.source6.Subscribe(new ZipObserver(gate, this, 5, q6)); return StableCompositeDisposable.Create(s1, s2, s3, s4, s5, s6, Disposable.Create(() => { lock (gate) { q1.Clear(); q2.Clear(); q3.Clear(); q4.Clear(); q5.Clear(); q6.Clear(); } })); } ``` -------------------------------- ### ObservableWWW.GetWWW Source: https://github.com/neuecc/unirx/wiki/UniRx Initiates an HTTP GET request and returns an Observable that emits the raw WWW object. ```APIDOC ## ObservableWWW.GetWWW ### Description Initiates an HTTP GET request to the specified URL and returns an Observable that emits the raw `WWW` object. This provides access to more detailed response information. ### Method GET ### Endpoint `String url` ### Parameters #### Path Parameters - **url** (String) - Required - The URL to send the GET request to. #### Query Parameters None explicitly defined, but can be part of the URL. #### Request Body None for GET requests. ### Request Example ```csharp var request = ObservableWWW.GetWWW("http://example.com/resource"); request.Subscribe( www => { // Access www.text, www.bytes, www.error, etc. Console.WriteLine(www.text); }, error => Console.WriteLine(error) ); ``` ### Response #### Success Response (200 OK) - **IObservable** - An observable that emits the `WWW` object upon successful completion. #### Response Example ```json { "text": "Response data", "bytes": [0, 255, ...], "error": null } ``` ``` -------------------------------- ### ZipObservable Constructor (6 Sources) Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/ZipGenerator.txt Initializes a new instance of the ZipObservable class, setting up the source observables and the result selector. It determines whether to subscribe on the current thread based on source properties. ```csharp public ZipObservable( IObservable source1, IObservable source2, IObservable source3, IObservable source4, IObservable source5, IObservable source6, ZipFunc resultSelector) : base( source1.IsRequiredSubscribeOnCurrentThread() || source2.IsRequiredSubscribeOnCurrentThread() || source3.IsRequiredSubscribeOnCurrentThread() || source4.IsRequiredSubscribeOnCurrentThread() || source5.IsRequiredSubscribeOnCurrentThread() || source6.IsRequiredSubscribeOnCurrentThread() || false) { this.source1 = source1; this.source2 = source2; this.source3 = source3; this.source4 = source4; this.source5 = source5; this.source6 = source6; this.resultSelector = resultSelector; } ``` -------------------------------- ### ObservableWWW.GetAndGetBytes Source: https://github.com/neuecc/unirx/wiki/UniRx Initiates an HTTP GET request and returns an Observable that emits the response as a byte array. ```APIDOC ## ObservableWWW.GetAndGetBytes ### Description Initiates an HTTP GET request to the specified URL and returns an Observable that emits the response as a byte array. Useful for downloading binary data. Supports custom headers and progress reporting. ### Method GET ### Endpoint `String url` ### Parameters #### Path Parameters - **url** (String) - Required - The URL to send the GET request to. #### Query Parameters None explicitly defined, but can be part of the URL. #### Request Body None for GET requests. ### Request Example ```csharp var request = ObservableWWW.GetAndGetBytes("http://example.com/image.png"); request.Subscribe( bytes => { // Process the byte array Console.WriteLine($"Downloaded {bytes.Length} bytes"); }, error => Console.WriteLine(error) ); ``` ### Response #### Success Response (200 OK) - **IObservable** - An observable that emits the response body as a byte array upon successful completion. #### Response Example ```json [0, 255, 100, ...] ``` ``` -------------------------------- ### Reactive UI Programming with UniRx Source: https://github.com/neuecc/unirx/blob/master/README.md Illustrates declarative UI programming by making Unity UI elements observable. It demonstrates binding Toggle, InputField, and Slider values to Text and Button interactability with delays and formatting. ```csharp public Toggle MyToggle; public InputField MyInput; public Text MyText; public Slider MySlider; // On Start, you can write reactive rules for declaretive/reactive ui programming void Start() { // Toggle, Input etc as Observable (OnValueChangedAsObservable is a helper providing isOn value on subscribe) // SubscribeToInteractable is an Extension Method, same as .interactable = x) MyToggle.OnValueChangedAsObservable().SubscribeToInteractable(MyButton); // Input is displayed after a 1 second delay MyInput.OnValueChangedAsObservable() .Where(x => x != null) .Delay(TimeSpan.FromSeconds(1)) .SubscribeToText(MyText); // SubscribeToText is helper for subscribe to text // Converting for human readability MySlider.OnValueChangedAsObservable() .SubscribeToText(MyText, x => Math.Round(x, 2).ToString()); } ``` -------------------------------- ### ObservableBeginDragTrigger Methods Source: https://github.com/neuecc/unirx/wiki/UniRx.Triggers Provides an observable stream for the OnBeginDrag event, which is triggered when a drag operation starts on an object. ```csharp public IObservable OnBeginDragAsObservable() : ObservableTriggerBase, IEventSystemHandler, IBeginDragHandler ``` -------------------------------- ### AsyncStartTrigger Class Definition Source: https://github.com/neuecc/unirx/wiki/UniRx.Async.Triggers Defines the AsyncStartTrigger component, which inherits from MonoBehaviour and provides an asynchronous Start method. ```csharp public class UniRx.Async.Triggers.AsyncStartTrigger : MonoBehaviour ``` -------------------------------- ### Create UniRx Observers Source: https://github.com/neuecc/unirx/wiki/UniRx Provides factory methods to create IObserver instances with various combinations of onNext, onError, and onCompleted actions. Useful for defining custom observer logic. ```csharp public static IObserver Create(Action onNext) ``` ```csharp public static IObserver Create(Action onNext, Action onError) ``` ```csharp public static IObserver Create(Action onNext, Action onCompleted) ``` ```csharp public static IObserver Create(Action onNext, Action onError, Action onCompleted) ``` ```csharp public static IObserver CreateAutoDetachObserver(IObserver observer, IDisposable disposable) ``` ```csharp public static IObserver CreateSubscribeObserver(Action onNext, Action onError, Action onCompleted) ``` ```csharp public static IObserver CreateSubscribeWithState2Observer(TState1 state1, TState2 state2, Action onNext, Action onError, Action onCompleted) ``` ```csharp public static IObserver CreateSubscribeWithState3Observer(TState1 state1, TState2 state2, TState3 state3, Action onNext, Action onError, Action onCompleted) ``` ```csharp public static IObserver CreateSubscribeWithStateObserver(TState state, Action onNext, Action onError, Action onCompleted) ``` -------------------------------- ### ObservableWWW.Get Source: https://github.com/neuecc/unirx/wiki/UniRx Initiates an HTTP GET request to the specified URL and returns an Observable that emits the response as a string. ```APIDOC ## ObservableWWW.Get ### Description Initiates an HTTP GET request to the specified URL and returns an Observable that emits the response as a string. Allows for custom headers and progress reporting. ### Method GET ### Endpoint `String url` ### Parameters #### Path Parameters - **url** (String) - Required - The URL to send the GET request to. #### Query Parameters None explicitly defined, but can be part of the URL. #### Request Body None for GET requests. ### Request Example ```csharp var request = ObservableWWW.Get("http://example.com/data"); request.Subscribe( result => Console.WriteLine(result), error => Console.WriteLine(error) ); ``` ### Response #### Success Response (200 OK) - **IObservable** - An observable that emits the response body as a string upon successful completion. #### Response Example ```json "Response data as a string" ``` ``` -------------------------------- ### CoroutineAsyncExtensions GetAwaiter Method Source: https://github.com/neuecc/unirx/wiki/UniRx Extension method to get an awaiter for a Coroutine, enabling its use in async/await contexts. ```csharp public CoroutineAsyncBridge GetAwaiter(this Coroutine coroutine) ``` -------------------------------- ### UniTask.WhenAll 6 Tasks - Constructor Source: https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console/UniTask.WhenAll.Generated.txt Initializes a WhenAll promise for 6 tasks, setting initial states for results, exception, completion count, and continuation. ```csharp public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { this.completeCount = 0; this.whenComplete = null; this.result1 = default(T1); this.result2 = default(T2); this.result3 = default(T3); this.result4 = default(T4); this.result5 = default(T5); this.result6 = default(T6); this.exception = null; } ``` -------------------------------- ### ICancelable.IsDisposed Source: https://github.com/neuecc/unirx/wiki/UniRx Gets a value indicating whether the cancelable operation has been disposed. This property is part of the ICancelable interface, which extends IDisposable. ```APIDOC ## IsDisposed ### Description Gets a value indicating whether the cancelable operation has been disposed. ### Property `Boolean IsDisposed` ### Parameters None ### Response #### Success Response (Boolean) - **Boolean** - `true` if the operation has been disposed; otherwise, `false`. ``` -------------------------------- ### Using MicroCoroutine with YieldInstruction Source: https://github.com/neuecc/unirx/blob/master/README.md Demonstrates how to use MicroCoroutine with IObservable to handle asynchronous operations like web requests. It checks the `IsDone` property and accesses the result when available. ```csharp IEnumerator MicroCoroutineWithToYieldInstruction() { var www = ObservableWWW.Get("http://aaa").ToYieldInstruction(); while (!www.IsDone) { yield return null; } if (www.HasResult) { UnityEngine.Debug.Log(www.Result); } } ``` -------------------------------- ### Test UniRx DLL Integration with ObservableWWW Source: https://github.com/neuecc/unirx/wiki/Build-as-a-Managed-DLL This code snippet demonstrates how to use the UniRx.dll in a Unity project by making an asynchronous web request and logging the first 100 characters of the response. Ensure the 'UniRx' namespace is included. ```csharp ObservableWWW.Get("https://google.com/") .Subscribe( x => Debug.Log(x.Substring(0, 100)), // onSuccess ex => Debug.LogException(ex)); // onError ``` -------------------------------- ### Sample Source: https://github.com/neuecc/unirx/wiki/UniRx Samples the source observable sequence at periodic time intervals or based on another observable sequence. ```APIDOC ## `IObservable` Sample(this `IObservable` source, `TimeSpan` interval) ### Description Samples the source observable sequence at periodic time intervals. ### Method Extension Method ### Parameters - **source** (`IObservable`) - The source observable sequence. - **interval** (`TimeSpan`) - The interval at which to sample the source sequence. ### Return Value `IObservable` - An observable sequence that samples the source sequence at the specified interval. ``` ```APIDOC ## `IObservable` Sample(this `IObservable` source, `TimeSpan` interval, `IScheduler` scheduler) ### Description Samples the source observable sequence at periodic time intervals using a specified scheduler. ### Method Extension Method ### Parameters - **source** (`IObservable`) - The source observable sequence. - **interval** (`TimeSpan`) - The interval at which to sample the source sequence. - **scheduler** (`IScheduler`) - The scheduler to use for scheduling the sampling. ### Return Value `IObservable` - An observable sequence that samples the source sequence at the specified interval. ``` ```APIDOC ## `IObservable` Sample(this `IObservable` source, `IObservable` sampler) ### Description Samples the source observable sequence whenever the sampler observable sequence produces a value. ### Method Extension Method ### Parameters - **source** (`IObservable`) - The source observable sequence. - **sampler** (`IObservable`) - The observable sequence that triggers sampling. ### Return Value `IObservable` - An observable sequence that samples the source sequence based on the sampler. ``` -------------------------------- ### UniRx Framecount-Based Delay Invoke Source: https://github.com/neuecc/unirx/blob/master/README.md Example of using a framecount-based operator to delay an action. This operator executes after a specified number of frames. ```csharp Observable.TimerFrame(100).Subscribe(_ => Debug.Log("after 100 frame")); ``` -------------------------------- ### UniTask FromException Method Source: https://github.com/neuecc/unirx/wiki/UniRx.Async Creates a UniTask that is immediately completed with the specified exception. Overloads exist for generic and non-generic types. ```csharp public static UniTask FromException(Exception ex) ``` ```csharp public static UniTask FromException(Exception ex) ``` -------------------------------- ### OnBeginDragAsObservable Extension for UIBehaviour Source: https://github.com/neuecc/unirx/wiki/UniRx.Triggers Converts the UI OnBeginDrag event into an Observable stream for a UIBehaviour component. Use to react when a drag operation starts. ```csharp IObservable OnBeginDragAsObservable(this UIBehaviour component) ```