Skip to content

codewriter-packages/View-Binding

Repository files navigation

View Binding Github license Unity 2020.1 GitHub package.json version openupm

View binding library for unity

NOTE: To use View Binding library you need to install Tri Inspector - Free and open-source library that improves unity inspector.

How to use?

1. Setup ViewContext

ViewContext contains the data necessary to display current part of the interface.

View Context Preview

2. Add applicators and Binders

Applicators reactively update components (Text, Slider, etc) when data changes in ViewContext. Binders subscribes to events and pass them to ViewContext.

Text Applicator Preview

3. Set values from code

Code Preview

using UniMob;
using UnityEngine;
using CodeWriter.ViewBinding;

public class ViewBindingSample : MonoBehaviour
{
    public ViewVariableBool soundEnabled;
    public ViewVariableBool musicEnabled;
    public ViewVariableFloat volume;

    public ViewEventVoid onClose;

    private void Start()
    {
        soundEnabled.SetValue(true);
        soundEnabled.SetValue(false);
        volume.SetValue(0.5f);

        onClose.AddListener(() => Debug.Log("Close clicked"));
    }
}

Documentation

Builtin variable types:

  • Boolean (ViewVariableBool)
  • Integer (ViewVariableInt)
  • Float (ViewVariableFloat)
  • String (ViewVariableString)

Builtin event types:

  • Void (ViewEventVoid)
  • Boolean (ViewEventBool)
  • Integer (ViewEventInt)
  • Float (ViewEventFloat)
  • String (ViewEventString)

Builtin applicators:

Builtin adapters:

Builtin binders:

How to Install

Minimal Unity Version is 2020.1.

Library distributed as git package (How to install package from git URL)
Git URL: https://github.com/codewriter-packages/View-Binding.git

License

View-Binding is MIT licensed.