Reactivity
by
igor
| Summary | A reactive property system for components |
|---|---|
| Description |
sbox-reactivity A reactivity system for s&box. It makes writing code that runs in response to state changes easy. Check out https://github.com/impulsh/sbox-reactivity for documentation. public class MyComponent : ReactiveComponent { [Property, Reactive] public float Speed { get; set; } = 50f; [Reactive, Derived(nameof(_tintColor))] public Color TintColor { get; } = Color.Blue; private Color _tintColor() { // Calculate the tint color only when the speed changes return Math.Abs(Speed) <= 100f ? Color.Blue : Color.Red; } protected override void OnActivate() { Effect(() => { // Create a game object when this component is enabled var go = new GameObject(); var model = go.AddComponent<ModelRenderer>(); model.Model = Model.Cube; // Tint the model whenever it changes Effect(() => model.Tint = TintColor); // Spin the object every frame while the component is enabled Frame(() => { var angles = go.LocalRotation.Angles(); angles.yaw += Speed * Time.Delta; go.LocalRotation = angles; }); // Destroy the object when the component is disabled return () => go.Destroy(); }); } }sbox-reactivity
A reactivity system for s&box. It makes writing code that runs in response to state changes easy. Check out https://github.com/impulsh/sbox-reactivity for documentation.
public class MyComponent : ReactiveComponent
{
[Property, Reactive]
public float Speed { get; set; } = 50f;
[Reactive, Derived(nameof(_tintColor))]
public Color TintColor { get; } = Color.Blue;
private Color _tintColor()
{
// Calculate the tint color only when the speed changes
return Math.Abs(Speed) <= 100f ? Color.Blue : Color.Red;
}
protected override void OnActivate()
{
Effect(() =>
{
// Create a game object when this component is enabled
var go = new GameObject();
var model = go.AddComponent<ModelRenderer>();
model.Model = Model.Cube;
// Tint the model whenever it changes
Effect(() => model.Tint = TintColor);
// Spin the object every frame while the component is enabled
Frame(() =>
{
var angles = go.LocalRotation.Angles();
angles.yaw += Speed * Time.Delta;
go.LocalRotation = angles;
});
// Destroy the object when the component is disabled
return () => go.Destroy();
});
}
}
|
| Votes | 👍1 👎0 ❤️0 |
| Error Rate | 0% |
| Usage |
1 players
3 sessions
6 minutes playtime
2 minutes avg session
Totals captured
|
| Data | {} |
| Version | Created | Size (modified) | Files | Changes |
|---|---|---|---|---|
| 302096 | 189.5 KB (20.5 KB) | 47 ~2 | Fix debug info exception outside of game project | |
| 167723 | 189.5 KB (49.6 KB) | 47 +13 ~1 | Fix editor content | |
| 167719 | 158.3 KB (30 KB) | 34 +1 ~4 -12 | Add infinite loop inspector | |
| 166668 | 184.8 KB (166.9 KB) | 45 +15 ~16 | Add reactivity debugger | |
| 160359 | 143 KB (79.1 KB) | 30 ~4 | Allow ReactiveComponent activation during OnStart | |
| 156563 | 138.2 KB (22.8 KB) | 30 ~2 | Fix state mutation in effect not causing re-run | |
| 156144 | 137.9 KB (75.6 KB) | 30 ~4 | Support reactivity attributes on static properties | |
| 155734 | 136.6 KB (85.5 KB) | 30 ~4 | Add GetEffectCancelToken | |
| 154843 | 135.1 KB (90.4 KB) | 30 +1 ~6 | Add Each method | |
| 154475 | 125.9 KB (78.7 KB) | 29 +2 ~4 | Add tick/frame methods | |
| 154335 | 113.9 KB (85 KB) | 27 +3 ~8 | Add scene events | |
| 153303 | 93.1 KB (63.7 KB) | 24 +2 ~5 -2 | Add conversion from State<T> and Derived<T> | |
| 152733 | 90.7 KB (58.8 KB) | 24 +2 ~6 | Update reactive panels | |
| 152422 | 85.6 KB (51.5 KB) | 22 ~3 | Add Interval method | |
| 152413 | 82.2 KB (53.1 KB) | 22 ~4 | Add Timeout method | |
| 152160 | 78.2 KB (14 KB) | 22 ~2 | Fix accessibility issue | |
| 152155 | 78.1 KB (57.4 KB) | 22 +3 ~7 | Added reactive panels | |
| 151887 | 67.2 KB | 19 +19 | Initial release |
Loading history…