https://github.com/codewriter-packages/view-binding
View binding library for Unity. Built over UniMob
https://github.com/codewriter-packages/view-binding
c-sharp data-binding game game-development game-engine gamedev mvvm ui unity unity3d view-binding
Last synced: about 1 year ago
JSON representation
View binding library for Unity. Built over UniMob
- Host: GitHub
- URL: https://github.com/codewriter-packages/view-binding
- Owner: codewriter-packages
- License: mit
- Created: 2021-05-30T15:33:19.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-12-02T11:18:29.000Z (over 2 years ago)
- Last Synced: 2025-03-16T13:01:54.898Z (about 1 year ago)
- Topics: c-sharp, data-binding, game, game-development, game-engine, gamedev, mvvm, ui, unity, unity3d, view-binding
- Language: C#
- Homepage:
- Size: 166 KB
- Stars: 28
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# View Binding [](#) [](#)  [](https://openupm.com/packages/com.codewriter.view-binding/)
_View binding library for unity_
#### NOTE: To use View Binding library you need to install [Tri Inspector](https://github.com/codewriter-packages/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.

#### 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.

#### 3. Set values from code

```csharp
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](./Runtime/Applicators/UnityEvent/UnityEventBoolApplicator.cs), [Float](./Runtime/Applicators/UnityEvent/UnityEventFloatApplicator.cs), [Integer](./Runtime/Applicators/UnityEvent/UnityEventIntApplicator.cs), [String](./Runtime/Applicators/UnityEvent/UnityEventStringApplicator.cs))
- [GameObject - Activity](./Runtime/Applicators/GameObjectActivityApplicator.cs)
- [UI CanvasGroup - Alpha](./Runtime/Applicators/UI/CanvasGroupAlphaApplicator.cs)
- [UI CanvasGroup - Interactable](./Runtime/Applicators/UI/CanvasGroupInteractableApplicator.cs)
- [UI CanvasGroup - RaycastTarget](./Runtime/Applicators/UI/CanvasGroupRaycastTargetApplicator.cs)
- [UI CanvasGroup - Visibility](./Runtime/Applicators/UI/CanvasGroupVisibilityApplicator.cs)
- [UI Button - Interactable](./Runtime/Applicators/UI/ButtonInteractableApplicator.cs)
- [UI Image - Enabled](./Runtime/Applicators/UI/ImageEnabledApplicator.cs)
- [UI Image - Fill Amount](./Runtime/Applicators/UI/ImageFillAmountApplicator.cs)
- [UI InputField - Text](./Runtime/Applicators/UI/InputFieldApplicator.cs)
- [UI Slider - Value](./Runtime/Applicators/UI/SliderValueApplicator.cs)
- [UI Text - Text](./Runtime/Applicators/UI/TextApplicator.cs)
- [UI TextMeshPro - Text](./Runtime/Applicators/UI/TMPTextApplicator.cs)
- [UI TextMeshPro - Formatted Text](./Runtime/Applicators/UI/FormattedTMPTextApplicator.cs)
- [UI TextMeshPro - Localized Text](./Runtime/Applicators/UI/LocalizedTMPTextApplicator.cs)
- [UI Toggle - IsOn](./Runtime/Applicators/UI/ToggleApplicator.cs)
#### Builtin adapters:
- [Bool To String](./Runtime/Applicators/Adapters/BoolToStringAdapter.cs)
- [Bool To Formatted String](./Runtime/Applicators/Adapters/BoolToFormattedStringAdapter.cs)
- [Formatted Text](./Runtime/Applicators/Adapters/FormattedTextAdapter.cs)
- [Compare String](./Runtime/Applicators/Adapters/CompareStringAdapter.cs)
- [Float Format](./Runtime/Applicators/Adapters/FloatFormatAdapter.cs)
- [Float Ratio](./Runtime/Applicators/Adapters/FloatRatioAdapter.cs)
- [Inverse Boolean](./Runtime/Applicators/Adapters/InverseBoolAdapter.cs)
- [Text Localize](./Runtime/Applicators/Adapters/TextLocalizeAdapter.cs)
- [Time Localize](./Runtime/Applicators/Adapters/TimeLocalizeAdapter.cs)
#### Builtin binders:
- [UI Button - Click](./Runtime/Binders/UI/ButtonClickBinder.cs)
- [UI Toggle - ValueChanged](./Runtime/Binders/UI/ToggleValueChangedBinder.cs)
- [UI Slider - ValueChanged](./Runtime/Binders/UI/SliderValueChangedBinder.cs)
- [UI InputField - TextChanged](./Runtime/Binders/UI/InputFieldTextChangedBinder.cs)
- [UI InputField - EndEdit](./Runtime/Binders/UI/InputFieldEndEditBinder.cs)
## How to Install
Minimal Unity Version is 2020.1.
Library distributed as git package ([How to install package from git URL](https://docs.unity3d.com/Manual/upm-ui-giturl.html))
Git URL: `https://github.com/codewriter-packages/View-Binding.git`
## License
View-Binding is [MIT licensed](./LICENSE.md).