A Lightweight UniRx Integration into Unity's UI Toolkit.
Follow the Install Instructions for https://github.com/sandolkakos/unity-package-manager-utilities
For Git Versioning and Updates, Install: https://github.com/mob-sakai/UpmGitExtension#usage
Then Just copy the link below and add it to your project via Unity Package Manager: Installing from a Git URL
https://github.com/Redmoon-Development/redmoon-reactiveKit.git
Red Moon Reactive Kit provides Binding and Subscription Extensions that work with Unity's UI Toolkit.
BindCallback Binds Visual Element Callbacks to ReactiveCommands and Other Callbacks
Button button = Root.Q<Button>("MyButton");
button.BindCallback<ClickEvent>(command);
In the Example, The Button is bound to the command. When the Button is Clicked it will call the ReactiveCommand with a ClickEvent. Use BindClick instead of BindCallback for your click commands.
BindValueChanged emits a new observable whenever an element's value changes.
TextField field = Root.Q<TextField>("MyField");
field.BindValueChanged<string>(command);
field.BindValueChanged<string>(property);
In the Example, The Textfield is bound such that whenever it text changes, it will call a ReactiveCommand and Update a ReactiveProperty.
BindToValueChanged set the Element to change it's value whenever an Observable Emits a New Value. It does not notify that the value was changed.
TextField field = Root.Q<TextField>("MyField");
field.BindToValueChanged<string>(property);
In the Example, the ReactiveProperty is bound to the Field, such that whenever the ReactiveProperty Changes, the Textfield will update it's string.
AsObservable gets the Visual Element Events as Obsevable Emissions.
Button button = Root.Q<Button>("MyButton");
Observable<ClickEvent> clickStream = button.AsObservable<ClickEvent>();
clickStream.Subscribe((c) => Debug.Log(c));
In this Example, The Button now Emits ClickEvents as an Observable Stream, which is subscribed to log out the ClickEvent information.
A View is an Abstract Class that Wraps around a Document and Connects it to the ViewModel. Override OnActivation and you can use it to set up your UI.
public class MainView : View<MainViewModel>
{
public override void OnActivation(MainViewModel viewModel, CompositeDisposable disposable)
{
Button button = Root.Q<Button>("ReactiveButton");
button
.BindClick(viewModel.OnButtonClick)
.AddTo(disposable);
}
}
A ViewModel is an Abstract Class that is designed to act as your connector between the View and the functionality of the class. It is Loaded In first and allows you to set up a bunch of commands and expose them to many other classes.
public class MainViewModel : ViewModel<MainViewModel>
{
public ReactiveCommand<ClickEvent> OnButtonClick;
public override void OnInitialization()
{
OnButtonClick = new ReactiveCommand<ClickEvent>();
OnButtonClick.Subscribe((c) => Debug.Log("Button Clicked"));
}
}
- More Stylization UniRX commands.
- Optimizing calls
- More Examples
MIT License
There is no legally binding modifications to the MIT License, but if you are using my stuff, I would appreciate doing one of the following: buy me a beer if you ever meet me at a bar or invite me to potential money-making operations via my Contact Information provided below.
Contact me at [email protected]. If you want your message to actually be read, add "[Github-Message]" to your subject line.