gitmyhub

UniRx

C# ★ 7.3k updated 2y ago ▣ archived

Reactive Extensions for Unity

UniRx is a Unity library that replaces messy coroutine code with clean, stream-based event handling, letting game developers filter, combine, and react to inputs, network calls, and frame updates in a readable query style.

C#Unity.NETsetup: easycomplexity 3/5

UniRx is a library for Unity game developers that makes it easier to write code that responds to events and handles asynchronous operations. Unity's built-in approach to asynchronous work uses a mechanism called coroutines, but coroutines have real limitations: they cannot return values and cannot handle exceptions, which tends to produce tangled, hard-to-maintain code. UniRx provides a different approach based on Reactive Extensions (Rx), a programming pattern originally from the .NET world. The core idea is to treat events as streams that you can filter, combine, delay, and transform using a query style that looks similar to database queries.

In practice, this means things like button clicks, game loop updates (every frame), sensor input from devices like Kinect or VR controllers, and network responses can all be treated as observable event streams. You write rules about how those streams should behave, and the library handles the details. For example, detecting a double-click means watching a stream of click events and checking whether two arrive within 250 milliseconds. The library also makes network requests cancellable, supports running multiple requests in parallel, and includes progress tracking.

UniRx supports PC, Mac, Android, iOS, WebGL, and Windows Store. It was written to work around Unity-specific platform issues, particularly compatibility problems with iOS's IL2CPP compilation mode that the official .NET Rx library did not handle. The library is free and was available through the Unity Asset Store.

The README opens with an important note: the author now distributes an evolved successor called Cysharp/R3 and recommends using that instead of UniRx. Async/await integration was also separated into a companion project called UniTask after version 7.0.

The full README is longer than what was shown.

Where it fits