This repository was archived by the owner on Mar 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Reactive Variables
pointcache edited this page Jan 15, 2017
·
8 revisions
Reactive variable is called rVar in URSA, and all reactive types start with r_
like r_float, r_Vector3 etc.
A wrapper around any type that will:
- Raise
OnChangedevent. - Fully serialized by Unity and FullSerializer
- Changing value in inspector will raise event as well, thus its fully reactive.
- Can be registered in Console
- Are the only type of variable supported by Config objects.
This functionality however (due to how Unity handles generic types and inspectors) comes at a price.
##If you need to create a reactive variable of custom type, read Creating custom rVars .
These are implemented after UniRx Reactive Properties.
#Usage
//create new rVar<bool>
public r_bool IsRunning = new r_bool();
//... in some system
void OnEnable() {
Pool<Player>.First.IsRunning.OnChanged += OnPlayerRunning;
}
void OnPlayerRunning(bool val) {
if(val)
PlaySound("Running");
}
//... somewhere else
void OrderedUpdate() {
var playerCfg = Pool<PlayerConfig>.First;
var player = Pool<Player>.First;
var input = Pool<Input>.First;
player.IsRunning.Value = player.Speed > playerCfg.MinRunSpeed && input.PlayerRun;
}