Skip to content

Commit 882eaf1

Browse files
authored
Update readme file.
1 parent 73ae3a9 commit 882eaf1

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

README.md

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ A package that brings data-binding to your Unity project.
1313
- [IL2CPP restriction](#il2cpp-restriction)
1414
- [Introduction](#ledger-introduction)
1515
- [ViewModel](#viewmodel)
16-
- [CanvasView\<TBindingContext\>](#canvasviewtbindingcontext)
17-
- [DocumentView\<TBindingContext\>](#documentviewtbindingcontext)
18-
- [Command & Command\<T\>](#command--commandt)
19-
- [AsyncCommand & AsyncCommand\<T\>](#asynccommand--asynccommandt)
20-
- [AsyncLazyCommand & AsyncLazyCommand\<T\>](#asynclazycommand--asynclazycommandt)
21-
- [PropertyValueConverter\<TSourceType, TTargetType\>](#propertyvalueconvertertsourcetype-ttargettype)
22-
- [ParameterValueConverter\<TTargetType\>](#parametervalueconverterttargettype)
16+
- [CanvasView](#canvasviewtbindingcontext)
17+
- [DocumentView](#documentviewtbindingcontext)
18+
- [Command](#command--commandt)
19+
- [AsyncCommand](#asynccommand--asynccommandt)
20+
- [AsyncLazyCommand](#asynclazycommand--asynclazycommandt)
21+
- [PropertyValueConverter](#propertyvalueconvertertsourcetype-ttargettype)
22+
- [ParameterValueConverter](#parametervalueconverterttargettype)
2323
- [Quick start](#watch-quick-start)
2424
- [How To Use](#rocket-how-to-use)
2525
- [Data-binding](#data-binding)
@@ -36,7 +36,7 @@ A package that brings data-binding to your Unity project.
3636

3737
## :pencil: About
3838

39-
The **UnityMvvmToolkit** is a package that allows you to bind UI elements in your `UI Document` or `Canvas` to data sources in your app. Use the samples as a starting point for understanding how to utilize the package.
39+
The **UnityMvvmToolkit** allows you to use data binding to establish a connection between the app UI and the data it displays. This is a simple and consistent way to achieve clean separation of business logic from UI. Use the samples as a starting point for understanding how to utilize the package.
4040

4141
Key features:
4242
- Runtime data-binding
@@ -271,8 +271,8 @@ Key functionality:
271271
- Provides a base implementation for `Canvas` based view
272272
- Automatically searches for bindable UI elements on the `Canvas`
273273
- Allows to override the base viewmodel instance creation
274-
- Allows to define 'property' & 'parameter' value converters
275-
- Allows to define custom UI elements
274+
- Allows to define [property](#propertyvalueconvertertsourcetype-ttargettype) & [parameter](#parametervalueconverterttargettype) value converters
275+
- Allows to provide a custom bindable elements factory
276276

277277
```csharp
278278
public class CounterView : CanvasView<CounterViewModel>
@@ -290,7 +290,7 @@ public class CounterView : CanvasView<CounterViewModel>
290290
return _appContext.Resolve<IValueConverter[]>();
291291
}
292292

293-
// Define custom UI elements.
293+
// Provide a custom bindable elements factory.
294294
protected override IBindableElementsFactory GetBindableElementsFactory()
295295
{
296296
return _appContext.Resolve<IBindableElementsFactory>();
@@ -306,8 +306,8 @@ Key functionality:
306306
- Provides a base implementation for `UI Document` based view
307307
- Automatically searches for bindable UI elements on the `UI Document`
308308
- Allows to override the base viewmodel instance creation
309-
- Allows to define 'property' & 'parameter' value converters
310-
- Allows to define custom UI elements
309+
- Allows to define [property](#propertyvalueconvertertsourcetype-ttargettype) & [parameter](#parametervalueconverterttargettype) value converters
310+
- Allows to provide a custom bindable elements factory
311311

312312
```csharp
313313
public class CounterView : DocumentView<CounterViewModel>
@@ -325,10 +325,10 @@ public class CounterView : DocumentView<CounterViewModel>
325325
return _appContext.Resolve<IValueConverter[]>();
326326
}
327327

328-
// Define custom UI elements.
328+
// Provide a custom bindable elements factory.
329329
protected override IBindableElementsFactory GetBindableElementsFactory()
330330
{
331-
return _appContext.Resolve<IBindableElementFactory>();
331+
return _appContext.Resolve<IBindableElementsFactory>();
332332
}
333333
}
334334
```
@@ -380,7 +380,7 @@ And the relative UI could then be.
380380

381381
The `BindableButton` binds to the `ICommand` in the viewmodel, which wraps the private `IncrementCount` method. The `BindableLabel` displays the value of the `Count` property and is updated every time the property value changes.
382382

383-
> **Note:** You need to define `IntToStrConverter` to convert int to string.
383+
> **Note:** You need to define `IntToStrConverter` to convert int to string. See the [PropertyValueConverter](#propertyvalueconvertertsourcetype-ttargettype) section for more information.
384384
385385
### AsyncCommand & AsyncCommand\<T\>
386386

@@ -413,7 +413,7 @@ public class ImageViewerViewModel : ViewModel
413413

414414
public IAsyncCommand DownloadImageCommand { get; }
415415

416-
private async UniTask DownloadImageAsync(CancellationToken cancellationToken = default)
416+
private async UniTask DownloadImageAsync(CancellationToken cancellationToken)
417417
{
418418
Image = await _imageDownloader.DownloadRandomImageAsync(cancellationToken);
419419
}
@@ -460,6 +460,11 @@ public class MyViewModel : ViewModel
460460
public IAsyncCommand MyAsyncCommand { get; }
461461
public ICommand CancelCommand { get; }
462462

463+
private async UniTask DoSomethingAsync(CancellationToken cancellationToken)
464+
{
465+
...
466+
}
467+
463468
private void Cancel()
464469
{
465470
// If the underlying command is not running, or
@@ -724,7 +729,7 @@ The included UI elements are:
724729
- [BindableListView](#bindablelistview)
725730
- [BindableScrollView](#bindablescrollview)
726731

727-
> **Note:** The `ListView` & `ScrollView` are provided for `UI Toolkit` only.
732+
> **Note:** The `BindableListView` & `BindableScrollView` are provided for `UI Toolkit` only.
728733
729734
#### BindableLabel
730735

@@ -801,7 +806,7 @@ To pass a parameter to the viewmodel, see the [ParameterValueConverter](#paramet
801806

802807
The `BindableListView` control is the most efficient way to create lists. Use the `binding-items-source-path` of the `BindableListView` to bind to an `ObservableCollection`.
803808

804-
The following example demonstrates how to bind to a list of users with `BindableListView`.
809+
The following example demonstrates how to bind to a collection of users with `BindableListView`.
805810

806811
Create a main `UI Document` named `UsersView.uxml` with the following content.
807812

@@ -941,7 +946,7 @@ public class UserItemData : ICollectionItemData
941946

942947
### Create custom control
943948

944-
Let's create a bindable image UI element.
949+
Let's create a `BindableImage` UI element.
945950

946951
First of all, create a base `Image` class.
947952

@@ -984,7 +989,7 @@ public class BindableImage : Image, IBindableUIElement
984989
}
985990
```
986991

987-
The next step is to describe the data binding logic.
992+
The next step is to describe the data binding logic. To do that, create a `BindableImageWrapper` that inherits the `BindablePropertyElement` abstract class.
988993

989994
```csharp
990995
public class BindableImageWrapper : BindablePropertyElement
@@ -1005,6 +1010,8 @@ public class BindableImageWrapper : BindablePropertyElement
10051010
}
10061011
```
10071012

1013+
The **UnityMvvmToolkit** contains two abstract classes `BindableCommandElement` and `BindablePropertyElement` that provide a methods for getting properties from the `BindingContext`.
1014+
10081015
Finally, tell the elements factory what to do with the new UI element.
10091016

10101017
```csharp
@@ -1061,7 +1068,7 @@ public class ImageViewerViewModel : ViewModel
10611068

10621069
To enable [async commands](#asynccommand--asynccommandt) support, you need to add the [UniTask](https://github.com/Cysharp/UniTask) package to your project.
10631070

1064-
In addition to async commands **UnityMvvmToolkit** provides extensions to make [USS transition's](https://docs.unity3d.com/Manual/UIE-Transitions.html) awaitable.
1071+
In addition to async commands **UnityMvvmToolkit** provides extensions to make [USS transition](https://docs.unity3d.com/Manual/UIE-Transitions.html)'s awaitable.
10651072

10661073
For example, your `VisualElement` has the following transitions.
10671074
```css

0 commit comments

Comments
 (0)