Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
Prepare 5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Dec 15, 2015
1 parent 0d53127 commit cce8b26
Showing 1 changed file with 53 additions and 22 deletions.
75 changes: 53 additions & 22 deletions Assets/UniRx/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
UniRx - Reactive Extensions for Unity / ver.4.8.2
UniRx - Reactive Extensions for Unity / ver.5.0.0
===
Created by Yoshifumi Kawai(neuecc)

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/neuecc/UniRx?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

What is UniRx?
---
UniRx (Reactive Extensions for Unity) is a reimplementation of the .NET Reactive Extensions. The Official Rx implementation is great but doesn't work on Unity and has issues with iOS AOT compatibility. This library fixes those issues and adds some specific utilities for Unity. Supported platforms are PC/Mac/Android/iOS/WP8/WindowsStore/etc and the library is fully supported on both Unity 5 and 4.6.
UniRx (Reactive Extensions for Unity) is a reimplementation of the .NET Reactive Extensions. The Official Rx implementation is great but doesn't work on Unity and has issues with iOS AOT/IL2CPP compatibility. This library fixes those issues and adds some specific utilities for Unity. Supported platforms are PC/Mac/Android/iOS/WP8/WindowsStore/etc and the library is fully supported on both Unity 5 and 4.6.

UniRx is available on the Unity Asset Store (FREE) - http://u3d.as/content/neuecc/uni-rx-reactive-extensions-for-unity/7tT

Expand Down Expand Up @@ -103,7 +105,7 @@ parallel.Subscribe(xs =>
Progress information is available:

```csharp
// notifier for progress
// notifier for progress use ScheudledNotifier or new Progress<float>(/* action */)
var progressNotifier = new ScheduledNotifier<float>();
progressNotifier.Subscribe(x => Debug.Log(x)); // write www.progress

Expand Down Expand Up @@ -167,6 +169,28 @@ var cancel = Observable.FromCoroutine(AsyncA)
cancel.Dispose();
```

If in Unity 5.3, you can use ToYieldInstruction for Observable to Coroutine.

```csharp
IEnumerator TestNewCustomYieldInstruction()
{
// wait Rx Observable.
yield return Observable.Timer(TimeSpan.FromSeconds(1)).ToYieldInstruction();

// you can change the scheduler(this is ignore Time.scale)
yield return Observable.Timer(TimeSpan.FromSeconds(1), Scheduler.MainThreadIgnoreTimeScale).ToYieldInstruction();

// get return value from ObservableYieldInstruction
var o = ObservableWWW.Get("http://unity3d.com/").ToYieldInstruction(throwOnError: false);
yield return o;

if (o.HasError) { Debug.Log(o.Error.ToString()); }
if (o.HasResult) { Debug.Log(o.Result); }

// other sample(wait until transform.position.y >= 100)
yield return this.ObserveEveryValueChanged(x => x.transform).FirstOrDefault(x => x.position.y >= 100).ToYieldInstruction();
}
```
Normally, we have to use callbacks when we require a coroutine to return a value. Observable.FromCoroutine can convert coroutines to cancellable IObservable[T] instead.

```csharp
Expand Down Expand Up @@ -437,7 +461,7 @@ public class DangerousDragAndDrop : MonoBehaviour

UniRx provides an additional safe Repeat method. `RepeatSafe`: if contiguous "OnComplete" are called repeat stops. `RepeatUntilDestroy(gameObject/component)`, `RepeatUntilDisable(gameObject/component)` allows to stop when a target GameObject has been destroyed:

```
```csharp
this.gameObject.OnMouseDownAsObservable()
.SelectMany(_ => this.gameObject.UpdateAsObservable())
.TakeUntil(this.gameObject.OnMouseUpAsObservable())
Expand All @@ -446,6 +470,22 @@ this.gameObject.OnMouseDownAsObservable()
.Subscribe(x => Debug.Log(x));
```

UniRx gurantees hot observable(FromEvent/Subject/FromCoroutine/UnityUI.AsObservable..., there are like event) have unhandled exception durability. What is it? If subscribe in subcribe, does not detach event.

```csharp
button.OnClickAsObservable().Subscribe(_ =>
{
// If throws error in inner subscribe, but doesn't detached OnClick event.
ObservableWWW.Get("htttp://error/").Subscribe(x =>
{
Debug.Log(x);
});
});
```

This behaviour is sometimes useful such as user event handling.


All class instances provide an `ObserveEveryValueChanged` method, which watches for changing values every frame:

```csharp
Expand Down Expand Up @@ -615,7 +655,7 @@ void Start()
MyToggle.OnValueChangedAsObservable().SubscribeToInteractable(MyButton);

// Input is displayed after a 1 second delay
MyInput.OnValueChangeAsObservable()
MyInput.OnValueChangedAsObservable()
.Where(x => x != null)
.Delay(TimeSpan.FromSeconds(1))
.SubscribeToText(MyText); // SubscribeToText is helper for subscribe to text
Expand Down Expand Up @@ -867,28 +907,19 @@ See [UniRx/Examples](https://github.com/neuecc/UniRx/tree/master/Assets/UniRx/Ex

The samples demonstrate how to do resource management (Sample09_EventHandling), what is the MainThreadDispatcher, among other things.

iOS AOT
---
UniRx provides AotSafe utilities:

```csharp
// create safety iterator
Enumerable.Range(1, 10).AsSafeEnumerable().ToArray();

// Wrap elements in a class
Enumerable.Range(1, 10).WrapValueToClass(); // IEnumerable<Tuple<int>>
Observable.Range(1, 10).WrapValueToClass(); // IObservable<Tuple<int>>
```

Please see [AOT Exception Patterns and Hacks](https://github.com/neuecc/UniRx/wiki/AOT-Exception-Patterns-and-Hacks).

If you encounter the [Ran out of trampolines of type 2](http://developer.xamarin.com/guides/ios/troubleshooting/troubleshooting/) error, set the AOT compilation option `nimt-trampolines=2048`. If you encounter the Ran out of trampolines of type 0 error, set the AOT compilation options `ntrampolines=2048` as well. I recommend setting both when using UniRx.

Windows Store/Phone App (NETFX_CORE)
---
Some interfaces, such as `UniRx.IObservable<T>` and `System.IObservable<T>`, cause conflicts when submitting to the Windows Store App.
Therefore, when using NETFX_CORE, please refrain from using such constructs as `UniRx.IObservable<T>` and refer to the UniRx components by their short name, without adding the namespace. This solves the conflicts.

DLL Separation
---
If you want to pre-build UniRx, you can build own dll. clone project and open `UniRx.sln`, you can see `UniRx.Library` and `UniRx.Library.Unity`. `UniRx.Library` can use both .NET 3.5 normal CLR application and Unity. `UniRx.Library.Unity` is for Unity project, you should define compile symbol like `UniRxLibrary;UNITY;UNITY_5_3_0;UNITY_5_3;UNITY_5;UNITY_IPHONE;`. We can not provides binary because compile symbol is different each other.

If needs `UniRx.Library` for minimal test, it avilable in NuGet.

[Install-Package UniRx](https://www.nuget.org/packages/UniRx)

Reference
---
* [RxJava Wiki](https://github.com/Netflix/RxJava/wiki)
Expand Down

0 comments on commit cce8b26

Please sign in to comment.