---
title: "Reactivity - s&box library"
description: "A reactive property system for components"
canonical: "https://sbox.watch/zh-cn/libraries/igor/reactivity/"
generated_at: "2026-11-27T13:30:25.246Z"
---

# Reactivity

A reactive property system for components

- 类型: 库
- 标识符: igor.reactivity
- 创作者: igor
- 规范地址: https://sbox.watch/zh-cn/libraries/igor/reactivity/
- Markdown: https://sbox.watch/zh-cn/libraries/igor/reactivity/index.md
- sbox.game: https://sbox.game/igor/reactivity/
- 生成时间: 2026-11-27T13:30:25.246Z

## 统计

- 24小时热度: +0
- Terry 评分: 27%
- 收藏: 0
- 好评: 1
- 差评: 0
- 更新时间: 2026年6月27日
- 创建时间: 2026年2月7日
- 大小: 189.5 KB
- 文件: 47
- 标签: effects, events, framework, reactive

## 描述

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();
 });
 }
}
