View-Binding icon indicating copy to clipboard operation
View-Binding copied to clipboard

View binding library for Unity. Built over UniMob

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:

  • UnityEvent (Bool, Float, Integer, String)
  • GameObject - Activity
  • UI CanvasGroup - Alpha
  • UI CanvasGroup - Interactable
  • UI CanvasGroup - RaycastTarget
  • UI CanvasGroup - Visibility
  • UI Button - Interactable
  • UI Image - Enabled
  • UI Image - Fill Amount
  • UI InputField - Text
  • UI Slider - Value
  • UI Text - Text
  • UI TextMeshPro - Text
  • UI TextMeshPro - Formatted Text
  • UI TextMeshPro - Localized Text
  • UI Toggle - IsOn

Builtin adapters:

  • Bool To String
  • Bool To Formatted String
  • Formatted Text
  • Compare String
  • Float Format
  • Float Ratio
  • Inverse Boolean
  • Text Localize
  • Time Localize

Builtin binders:

  • UI Button - Click
  • UI Toggle - ValueChanged
  • UI Slider - ValueChanged
  • UI InputField - TextChanged
  • UI InputField - EndEdit

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.