Git Product home page Git Product logo

redmoon-reactivekit's Introduction

Red Moon Reactive Kit

Description

A Lightweight UniRx Integration into Unity's UI Toolkit.

How to Use (Install)

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

How to Use (Work)

Red Moon Reactive Kit provides Binding and Subscription Extensions that work with Unity's UI Toolkit.

Commands

BindCallback

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

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

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

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.

Views

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

ViewModels

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

Plans

  • More Stylization UniRX commands.
  • Optimizing calls
  • More Examples

License

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

Contact me at [email protected]. If you want your message to actually be read, add "[Github-Message]" to your subject line.

redmoon-reactivekit's People

Contributors

crazyjackel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

redmoon-reactivekit's Issues

Add Sample folder as a Samples folder displayed within Unity

Hello,

Currently when we pull your project, we are unable to open the BasicUI/ contained inside the Samples/ folder.
This is because you cannot access since within the package system.

Unity provide a way inside the manifest.json to do so,
I have an exemple on my project if that helps
Also, if you put the ~ in front of your folder name, the folder won't be displayed within the package, but only could be downloaded on the PackageManager UI.

For exemple
image

"samples": [ { "displayName": "MySample", "description": "Description", "path": "Samples~/MySampleFolder" } ]

Hopefully that helps !

Thank you again and have a great day.

Not work in Unity 2021.3.23f1

Hi Bro, I install this package, but compile error shows below:

Library\PackageCache\io.crazyjackel.redmoon-reactivekit@8bdfa4a\Runtime\Scripts\ViewModel.cs(7,15): error CS0234: The type or namespace name 'Injector' does not exist in the namespace 'RedMoon' (are you missing an assembly reference?)

Library\PackageCache\io.crazyjackel.redmoon-reactivekit@8bdfa4a\Runtime\Scripts\ViewModel.cs(11,58): error CS0246: The type or namespace name 'IClient' could not be found (are you missing a using directive or an assembly reference?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.