Prerequisites
- Familiar with Observer pattern
- Hands on any Rx library
Introduction
PowerObservables are set of time-based operations with ability to pause and possibility to manage tick freqeuency
Why Power Observables
- Easy access to time-based operations
- Timers / Countdowns based on TimeSpans
- Ability to pause an observable using another observable (i.e. BoolReactiveProperty)
Power Observables
Countdown
Observable sequence that produces a differed time value for certain duration with ability to pause and resume. Completes when there is no time left.
It’s pretty usefull when it comes to
- Limit time in Arcade Games
- Countdown before race start when you want to prompt “3, 2, 1, GO”
- Damage overtime — every tick deal 10 damage to player, on complete remove debuff
TimerInterval
Observable sequence that produces a value after each period for certain duration with ability to pause.
CountedInterval
Returns an observable sequence with aggregated time since subscribe with pause option
TimerCountedInterval
Returns an observable sequence with aggregated time since subscribe. Lasts for certain duration. It’s the same concept as Countdown but reversed. Instead times go up from zero. It completes after certain duration.
How To Use
Simple use case scenario below:
Unity Installation
Since unity doesn’t support git dependencies in package.json you have to install UniRx manually. Edit manifest.json file in your Unity Packages directory
Unity Examples
All code samples can be found on our GitHub page
Example 1 - Counted Interval
This example shows how to create Interval observable that will return TimeSpan in the cumulative way. It shows the way of refreshing the UI. It also shows use case for BoolReactiveProperty from UniRx library to manage pause/resume functionality.
Example 2 — Countdown
This example shows how to create, restart and refresh Countdown and how to manage subscription and completion methods in observable.