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

Commit 823e0b5

Browse files
committed
Ready for 5.4.0
1 parent 2e01638 commit 823e0b5

File tree

3 files changed

+388
-28
lines changed

3 files changed

+388
-28
lines changed

Assets/Plugins/UniRx/ReadMe.txt

Lines changed: 216 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
UniRx - Reactive Extensions for Unity / ver 5.3.0
1+
UniRx - Reactive Extensions for Unity / ver 5.4.0
22
===
33
Created by Yoshifumi Kawai(neuecc)
44

@@ -29,7 +29,7 @@ This kind of lack of composability causes operations to be close-coupled, which
2929

3030
Rx cures that kind of "asynchronous blues". Rx is a library for composing asynchronous and event-based programs using observable collections and LINQ-style query operators.
3131

32-
The game loop (every Update, OnCollisionEnter, etc), sensor data (Kinect, Leap Motion, etc.) are all types of events. Rx represents events as reactive sequences which are both easily composable and support time-based operations by using LINQ query operators.
32+
The game loop (every Update, OnCollisionEnter, etc), sensor data (Kinect, Leap Motion, VR Input, etc.) are all types of events. Rx represents events as reactive sequences which are both easily composable and support time-based operations by using LINQ query operators.
3333

3434
Unity is generally single threaded but UniRx facilitates multithreading for joins, cancels, accessing GameObjects, etc.
3535

@@ -320,7 +320,7 @@ public class MyComponent : MonoBehaviour
320320
}
321321
```
322322

323-
Supported triggers are `ObservableAnimatorTrigger`, `ObservableCollision2DTrigger`, `ObservableCollisionTrigger`, `ObservableDestroyTrigger`, `ObservableEnableTrigger`, `ObservableFixedUpdateTrigger`, `ObservableUpdateTrigger`, `ObservableLastUpdateTrigger`, `ObservableMouseTrigger`, `ObservableTrigger2DTrigger`, `ObservableTriggerTrigger`, `ObservableVisibleTrigger`, `ObservableTransformChangedTrigger`, `ObservableRectTransformTrigger`, `ObservableCanvasGroupChangedTrigger`, `ObservableStateMachineTrigger`, `ObservableEventTrigger`.
323+
Supported triggers are listed in [UniRx.wiki#UniRx.Triggers](https://github.com/neuecc/UniRx/wiki#unirxtriggers).
324324

325325
These can also be handled more easily by directly subscribing to observables returned by extension methods on Component/GameObject. These methods inject ObservableTrigger automaticaly (except for `ObservableEventTrigger` and `ObservableStateMachineTrigger`):
326326

@@ -581,6 +581,18 @@ logger.Log("Message");
581581
logger.Exception(new Exception("test exception"));
582582
```
583583

584+
Debugging
585+
---
586+
`Debug` operator in `UniRx.Diagnostics` namespace helps debugging.
587+
588+
```csharp
589+
using UniRx.Diagnostics;
590+
591+
fooObservable.Debug("Debug Test").Subscribe();
592+
```
593+
594+
shows sequence element on `OnNext`, `OnError`, `OnCompleted`, `OnCancel`, `OnSubscribe` timing to Debug.Log. It enables only `#if DEBUG`.
595+
584596
Unity-specific Extra Gems
585597
---
586598
```csharp
@@ -624,6 +636,9 @@ ThrottleFrame|
624636
ThrottleFirstFrame|
625637
TimeoutFrame|
626638
DelayFrameSubscription|
639+
FrameInterval|
640+
FrameTimeInterval|
641+
BatchFrame|
627642

628643
For example, delayed invoke once:
629644

@@ -675,8 +690,28 @@ void Start()
675690
}
676691
```
677692

693+
![image](https://cloud.githubusercontent.com/assets/46207/15267997/86e9ed5c-1a0c-11e6-8371-14b61a09c72c.png)
694+
678695
MicroCoroutine's limitation, only supports `yield return null` and update timing is determined start method(`StartUpdateMicroCoroutine`, `StartFixedUpdateMicroCoroutine`, `StartEndOfFrameMicroCoroutine`).
679696

697+
If you combine with other IObservable, you can check completed property like isDone.
698+
699+
```csharp
700+
IEnumerator MicroCoroutineWithToYieldInstruction()
701+
{
702+
var www = ObservableWWW.Get("http://aaa").ToYieldInstruction();
703+
while (!www.IsDone)
704+
{
705+
yield return null;
706+
}
707+
708+
if (www.HasResult)
709+
{
710+
UnityEngine.Debug.Log(www.Result);
711+
}
712+
}
713+
```
714+
680715
uGUI Integration
681716
---
682717
UniRx can handle `UnityEvent`s easily. Use `UnityEvent.AsObservable` to subscribe to events:
@@ -937,7 +972,7 @@ Yellow is `Awake`, order is indeterminate. Green is `BeforeInitialize` phase, it
937972

938973
If you create `PresenterBase` dynamically for example from Prefab, you can call `ForceInitialize(argument)` after instantiate.
939974

940-
ReactiveCommand
975+
ReactiveCommand, AsyncReactiveCommand
941976
---
942977
ReactiveCommand abstraction of button command with boolean interactable.
943978

@@ -961,7 +996,7 @@ public class Player
961996
}
962997
}
963998

964-
public class Presenter
999+
public class Presenter : MonoBehaviour
9651000
{
9661001
public Button resurrectButton;
9671002

@@ -977,7 +1012,68 @@ public class Presenter
9771012
}
9781013
```
9791014

980-
MessageBroker
1015+
AsyncReactiveCommand is a variation of ReactiveCommand that `CanExecute`(in many cases bind to button's interactable) is changed to false until asynchronous execution was finished.
1016+
1017+
```csharp
1018+
public class Presenter : MonoBehaviour
1019+
{
1020+
public UnityEngine.UI.Button button;
1021+
1022+
void Start()
1023+
{
1024+
var command = new AsyncReactiveCommand();
1025+
1026+
command.Subscribe(_ =>
1027+
{
1028+
// heavy, heavy, heavy method....
1029+
return Observable.Timer(TimeSpan.FromSeconds(3)).AsUnitObservable();
1030+
});
1031+
1032+
// after clicked, button shows disable for 3 seconds
1033+
command.BindTo(button);
1034+
1035+
// Note:shortcut extension, bind aync onclick directly
1036+
button.BindToOnClick(_ =>
1037+
{
1038+
return Observable.Timer(TimeSpan.FromSeconds(3)).AsUnitObservable();
1039+
});
1040+
}
1041+
}
1042+
```
1043+
1044+
`AsyncReactiveCommand` has three constructor.
1045+
1046+
* `()` - CanExecute is changed to false until async execution finished
1047+
* `(IObservable<bool> canExecuteSource)` - Mixed with empty, CanExecute becomes true when canExecuteSource send to true and does not executing
1048+
* `(IReactiveProperty<bool> sharedCanExecute)` - share execution status between multiple AsyncReactiveCommands, if one AsyncReactiveCommand is executing, other AsyncReactiveCommands(with same sharedCanExecute property) becomes CanExecute false until async execution finished
1049+
1050+
```csharp
1051+
public class Presenter : MonoBehaviour
1052+
{
1053+
public UnityEngine.UI.Button button1;
1054+
public UnityEngine.UI.Button button2;
1055+
1056+
void Start()
1057+
{
1058+
// share canExecute status.
1059+
// when clicked button1, button1 and button2 was disabled for 3 seconds.
1060+
1061+
var sharedCanExecute = new ReactiveProperty<bool>();
1062+
1063+
button1.BindToOnClick(sharedCanExecute, _ =>
1064+
{
1065+
return Observable.Timer(TimeSpan.FromSeconds(3)).AsUnitObservable();
1066+
});
1067+
1068+
button2.BindToOnClick(sharedCanExecute, _ =>
1069+
{
1070+
return Observable.Timer(TimeSpan.FromSeconds(3)).AsUnitObservable();
1071+
});
1072+
}
1073+
}
1074+
```
1075+
1076+
MessageBroker, AsyncMessageBroker
9811077
---
9821078
MessageBroker is Rx based in-memory pubsub system filtered by type.
9831079

@@ -996,6 +1092,92 @@ MessageBroker.Default.Receive<TestArgs>().Subscribe(x => UnityEngine.Debug.Log(x
9961092
MessageBroker.Default.Publish(new TestArgs { Value = 1000 });
9971093
```
9981094

1095+
AsyncMessageBroker is variation of MessageBroker, can await Publish call.
1096+
1097+
```csharp
1098+
AsyncMessageBroker.Default.Subscribe<TestArgs>(x =>
1099+
{
1100+
// show after 3 seconds.
1101+
return Observable.Timer(TimeSpan.FromSeconds(3))
1102+
.ForEachAsync(_ =>
1103+
{
1104+
UnityEngine.Debug.Log(x);
1105+
});
1106+
});
1107+
1108+
AsyncMessageBroker.Default.PublishAsync(new TestArgs { Value = 3000 })
1109+
.Subscribe(_ =>
1110+
{
1111+
UnityEngine.Debug.Log("called all subscriber completed");
1112+
});
1113+
```
1114+
1115+
UniRx.Toolkit
1116+
---
1117+
`UniRx.Toolkit` includes serveral Rx-ish tools. Currently includes `ObjectPool` and `AsyncObjectPool`. It can `Rent`, `Return` and `PreloadAsync` for fill pool before rent operation.
1118+
1119+
```csharp
1120+
// sample class
1121+
public class Foobar : MonoBehaviour
1122+
{
1123+
public IObservable<Unit> ActionAsync()
1124+
{
1125+
// heavy, heavy, action...
1126+
return Observable.Timer(TimeSpan.FromSeconds(3)).AsUnitObservable();
1127+
}
1128+
}
1129+
1130+
public class FoobarPool : ObjectPool<Foobar>
1131+
{
1132+
readonly Foobar prefab;
1133+
readonly Transform hierarchyParent;
1134+
1135+
public FoobarPool(Foobar prefab, Transform hierarchyParent)
1136+
{
1137+
this.prefab = prefab;
1138+
this.hierarchyParent = hierarchyParent;
1139+
}
1140+
1141+
protected override Foobar CreateInstance()
1142+
{
1143+
var foobar = GameObject.Instantiate<Foobar>(prefab);
1144+
foobar.transform.SetParent(hierarchyParent);
1145+
1146+
return foobar;
1147+
}
1148+
1149+
// You can overload OnBeforeRent, OnBeforeReturn, OnClear for customize action.
1150+
// In default, OnBeforeRent = SetActive(true), OnBeforeReturn = SetActive(false)
1151+
1152+
// protected override void OnBeforeRent(Foobar instance)
1153+
// protected override void OnBeforeReturn(Foobar instance)
1154+
// protected override void OnClear(Foobar instance)
1155+
}
1156+
1157+
public class Presenter : MonoBehaviour
1158+
{
1159+
FoobarPool pool = null;
1160+
1161+
public Foobar prefab;
1162+
public Button rentButton;
1163+
1164+
void Start()
1165+
{
1166+
pool = new FoobarPool(prefab, this.transform);
1167+
1168+
rentButton.OnClickAsObservable().Subscribe(_ =>
1169+
{
1170+
var foobar = pool.Rent();
1171+
foobar.ActionAsync().Subscribe(__ =>
1172+
{
1173+
// if action completed, return to pool
1174+
pool.Return(foobar);
1175+
});
1176+
});
1177+
}
1178+
}
1179+
```
1180+
9991181
Visual Studio Analyzer
10001182
---
10011183
For Visual Studio 2015 users, a custom analyzer, UniRxAnalyzer, is provided. It can, for example, detect when streams aren't subscribed to.
@@ -1023,37 +1205,53 @@ Therefore, when using NETFX_CORE, please refrain from using such constructs as `
10231205

10241206
DLL Separation
10251207
---
1026-
If you want to pre-build UniRx, you can build own dll. clone project and open `UniRx.sln`, you can see `UniRx`, it is fullset separated project of UniRx. You should define compile symbol like `UNITY;UNITY_5_3_0;UNITY_5_3;UNITY_5;` + `UNITY_EDITOR`, `UNITY_IPHONE` or other platform symbol. We can not provides pre-build binary to release page, asset store because compile symbol is different each other.
1208+
If you want to pre-build UniRx, you can build own dll. clone project and open `UniRx.sln`, you can see `UniRx`, it is fullset separated project of UniRx. You should define compile symbol like `UNITY;UNITY_5_4_OR_NEWER;UNITY_5_4_0;UNITY_5_4;UNITY_5;` + `UNITY_EDITOR`, `UNITY_IPHONE` or other platform symbol. We can not provides pre-build binary to release page, asset store because compile symbol is different each other.
10271209

10281210
If you want to use UniRx for .NET 3.5 normal CLR application, you can use `UniRx.Library`. `UniRx.Library` is splitted UnityEngine dependency, build `UniRx.Library` needs to define `UniRxLibrary` symbol. pre-build `UniRx.Library` binary, it avilable in NuGet.
10291211

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

10321214
Reference
10331215
---
1034-
* [RxJava Wiki](https://github.com/Netflix/RxJava/wiki)
1035-
1036-
This wiki is a great way for learn Rx. All operators are illustrated with graphical marble diagrams, which makes them easy to understand.
1216+
* [UniRx/wiki](https://github.com/neuecc/UniRx/wiki)
1217+
1218+
UniRx API documents.
10371219

1038-
* [Reactive Game Architectures](http://sugarpillstudios.com/wp/?page_id=279)
1220+
* [ReactiveX](http://reactivex.io/)
10391221

1040-
Introduction on how to use Rx for game programming.
1222+
The home of ReactiveX. [Introduction](http://reactivex.io/intro.html), [All operators](http://reactivex.io/documentation/operators.html) are illustrated with graphical marble diagrams, there makes easy to understand. And UniRx is official [ReactiveX Languages](http://reactivex.io/languages.html).
10411223

10421224
* [Introduction to Rx](http://introtorx.com/)
10431225

10441226
A great online tutorial and eBook.
10451227

1046-
* [Rx(Reactive Extensions)](https://rx.codeplex.com/)
1228+
* [Beginner's Guide to the Reactive Extensions](http://msdn.microsoft.com/en-us/data/gg577611)
10471229

1048-
The original project home page.
1230+
Many videos, slides and documents for Rx.NET.
10491231

1050-
* [Beginner's Guide to the Reactive Extensions](http://msdn.microsoft.com/en-us/data/gg577611)
1232+
* [The future of programming technology in Unity - UniRx -(JPN)](http://www.slideshare.net/torisoup/unity-unirx)
1233+
- [Korean translation](http://www.slideshare.net/agebreak/160402-unirx)
1234+
1235+
Intro slide by [@torisoup](https://github.com/torisoup)
1236+
1237+
* [Reactive Programming, ​Unity 3D and you](http://slides.com/sammegidov/unirx#/)
1238+
- [Repository of UniRxSimpleGame](https://github.com/Xerios/UniRxSimpleGame)
1239+
1240+
Intro slide and sample game by [@Xerios](https://github.com/Xerios)
1241+
1242+
What game or library is using UniRx?
1243+
---
1244+
Games
10511245

1052-
Many videos, slides and documents.
1246+
Libraries
10531247

1054-
* [ReactiveX Languages](http://reactivex.io/languages.html)
1248+
- [PhotonWire](https://github.com/neuecc/PhotonWire) - Typed Asynchronous RPC Layer for Photon Server + Unity.
1249+
- [uFrame Game Framework](https://www.assetstore.unity3d.com/en/#!/content/14381) - MVVM/MV* framework designed for the Unity Engine.
1250+
- [EcsRx](https://github.com/grofit/ecsrx) - A simple framework for unity using the ECS paradigm but with unirx for fully reactive systems.
1251+
- [ActionStreetMap Demo](https://github.com/ActionStreetMap/demo) - ASM is an engine for building real city environment dynamically using OSM data.
1252+
- [utymap](https://github.com/reinterpretcat/utymap) - UtyMap is library for building real city environment dynamically using various data sources (mostly, OpenStreetMap and Natural Earth).
10551253

1056-
UniRx is an official ReacitveX family language.
1254+
If you use UniRx, please comment to [UniRx/issues/152](https://github.com/neuecc/UniRx/issues/152).
10571255

10581256
Help & Contribute
10591257
---

Assets/Plugins/UniRx/Scripts/UnityEngineBridge/ReactiveCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public static IDisposable BindTo(this AsyncReactiveCommand<Unit> command, UnityE
370370
{
371371
var d1 = command.CanExecute.SubscribeToInteractable(button);
372372
var d2 = button.OnClickAsObservable().SubscribeWithState(command, (x, c) => c.Execute(x));
373-
373+
374374
return StableCompositeDisposable.Create(d1, d2);
375375
}
376376

@@ -389,15 +389,15 @@ public static IDisposable BindToOnClick(this AsyncReactiveCommand<Unit> command,
389389
/// <summary>
390390
/// Create AsyncReactiveCommand and bind to button's interactable and onClick and register async action to command.
391391
/// </summary>
392-
public static IDisposable BindOnClick(this UnityEngine.UI.Button button, Func<Unit, IObservable<Unit>> asyncOnClick)
392+
public static IDisposable BindToOnClick(this UnityEngine.UI.Button button, Func<Unit, IObservable<Unit>> asyncOnClick)
393393
{
394394
return new AsyncReactiveCommand().BindToOnClick(button, asyncOnClick);
395395
}
396396

397397
/// <summary>
398398
/// Create AsyncReactiveCommand and bind sharedCanExecuteSource source to button's interactable and onClick and register async action to command.
399399
/// </summary>
400-
public static IDisposable BindOnClick(this UnityEngine.UI.Button button, IReactiveProperty<bool> sharedCanExecuteSource, Func<Unit, IObservable<Unit>> asyncOnClick)
400+
public static IDisposable BindToOnClick(this UnityEngine.UI.Button button, IReactiveProperty<bool> sharedCanExecuteSource, Func<Unit, IObservable<Unit>> asyncOnClick)
401401
{
402402
return sharedCanExecuteSource.ToAsyncReactiveCommand().BindToOnClick(button, asyncOnClick);
403403
}

0 commit comments

Comments
 (0)