Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit c3dc5cb

Browse files
committed
Update to 2022.3, remove newtonsoft dep, add BindIntegerField
1 parent 464c2fd commit c3dc5cb

File tree

11 files changed

+145
-167
lines changed

11 files changed

+145
-167
lines changed

Bindings/.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"visualstudiotoolsforunity.vstuc"
4+
]
5+
}

Bindings/.vscode/launch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Attach to Unity",
6+
"type": "vstuc",
7+
"request": "attach"
8+
}
9+
]
10+
}

Bindings/.vscode/settings.json

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
{
2-
"files.exclude":
3-
{
4-
"**/.DS_Store":true,
5-
"**/.git":true,
6-
"**/.gitmodules":true,
7-
"**/*.booproj":true,
8-
"**/*.pidb":true,
9-
"**/*.suo":true,
10-
"**/*.user":true,
11-
"**/*.userprefs":true,
12-
"**/*.unityproj":true,
13-
"**/*.dll":true,
14-
"**/*.exe":true,
15-
"**/*.pdf":true,
16-
"**/*.mid":true,
17-
"**/*.midi":true,
18-
"**/*.wav":true,
19-
"**/*.gif":true,
20-
"**/*.ico":true,
21-
"**/*.jpg":true,
22-
"**/*.jpeg":true,
23-
"**/*.png":true,
24-
"**/*.psd":true,
25-
"**/*.tga":true,
26-
"**/*.tif":true,
27-
"**/*.tiff":true,
28-
"**/*.3ds":true,
29-
"**/*.3DS":true,
30-
"**/*.fbx":true,
31-
"**/*.FBX":true,
32-
"**/*.lxo":true,
33-
"**/*.LXO":true,
34-
"**/*.ma":true,
35-
"**/*.MA":true,
36-
"**/*.obj":true,
37-
"**/*.OBJ":true,
38-
"**/*.asset":true,
39-
"**/*.cubemap":true,
40-
"**/*.flare":true,
41-
"**/*.mat":true,
42-
"**/*.meta":true,
43-
"**/*.prefab":true,
44-
"**/*.unity":true,
45-
"build/":true,
46-
"Build/":true,
47-
"Library/":true,
48-
"library/":true,
49-
"obj/":true,
50-
"Obj/":true,
51-
"ProjectSettings/":true,
52-
"temp/":true,
53-
"Temp/":true
54-
}
1+
{
2+
"files.exclude": {
3+
"**/.DS_Store": true,
4+
"**/.git": true,
5+
"**/.gitmodules": true,
6+
"**/*.booproj": true,
7+
"**/*.pidb": true,
8+
"**/*.suo": true,
9+
"**/*.user": true,
10+
"**/*.userprefs": true,
11+
"**/*.unityproj": true,
12+
"**/*.dll": true,
13+
"**/*.exe": true,
14+
"**/*.pdf": true,
15+
"**/*.mid": true,
16+
"**/*.midi": true,
17+
"**/*.wav": true,
18+
"**/*.gif": true,
19+
"**/*.ico": true,
20+
"**/*.jpg": true,
21+
"**/*.jpeg": true,
22+
"**/*.png": true,
23+
"**/*.psd": true,
24+
"**/*.tga": true,
25+
"**/*.tif": true,
26+
"**/*.tiff": true,
27+
"**/*.3ds": true,
28+
"**/*.3DS": true,
29+
"**/*.fbx": true,
30+
"**/*.FBX": true,
31+
"**/*.lxo": true,
32+
"**/*.LXO": true,
33+
"**/*.ma": true,
34+
"**/*.MA": true,
35+
"**/*.obj": true,
36+
"**/*.OBJ": true,
37+
"**/*.asset": true,
38+
"**/*.cubemap": true,
39+
"**/*.flare": true,
40+
"**/*.mat": true,
41+
"**/*.meta": true,
42+
"**/*.prefab": true,
43+
"**/*.unity": true,
44+
"build/": true,
45+
"Build/": true,
46+
"Library/": true,
47+
"library/": true,
48+
"obj/": true,
49+
"Obj/": true,
50+
"ProjectSettings/": true,
51+
"temp/": true,
52+
"Temp/": true
53+
},
54+
"dotnet.defaultSolution": "Bindings.sln"
5555
}

Bindings/Packages/com.virtualmaker.bindings/Runtime/Bindings.UIElements.cs

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
using System.Threading.Tasks;
77
using UnityEngine;
88
using UnityEngine.UIElements;
9-
using Button = UnityEngine.UIElements.Button;
10-
using Image = UnityEngine.UIElements.Image;
119

1210
namespace VirtualMaker.Bindings
1311
{
@@ -23,32 +21,40 @@ public Bindings(VisualElement root)
2321

2422
public void BindText<T>(string name, IProperty<T> prop)
2523
{
26-
Bind<Label, T>(name, prop, (element, value) => element.text = value?.ToString());
24+
if (TryGetElement<TextElement>(name, out var element))
25+
{
26+
BindText(element, prop);
27+
}
2728
}
2829

29-
public void BindText<T, W>(string name, IProperty<T> prop, Func<T, W> transform)
30+
public void BindText<T>(TextElement element, IProperty<T> prop)
3031
{
31-
BindText(name, Derived.From(prop, transform));
32+
Bind(element, prop, (element, value) => SetText(element, value));
3233
}
3334

34-
public void BindButtonText<T>(string name, IProperty<T> prop)
35+
public void BindText<T, W>(string name, IProperty<T> prop, Func<T, W> transform)
3536
{
36-
Bind<Button, T>(name, prop, (element, value) => element.text = value?.ToString());
37+
BindText(name, Derived.From(prop, transform));
3738
}
3839

39-
public void BindButtonText<TValue, TTransform>(string name, IProperty<TValue> prop, Func<TValue, TTransform> transform)
40+
public void BindText<T, W>(TextElement element, IProperty<T> prop, Func<T, W> transform)
4041
{
41-
BindButtonText(name, Derived.From(prop, transform));
42+
BindText(element, Derived.From(prop, transform));
4243
}
4344

4445
public void SetText<T>(string name, T value)
4546
{
4647
if (TryGetElement<Label>(name, out var element))
4748
{
48-
element.text = value?.ToString();
49+
SetText(element, value);
4950
}
5051
}
5152

53+
public void SetText<T>(TextElement element, T value)
54+
{
55+
element.text = value?.ToString();
56+
}
57+
5258
public void SetLineHeight(string name, int lineHeight)
5359
{
5460
if (TryGetElement<Label>(name, out var element))
@@ -272,53 +278,43 @@ public void BindBackgroundImage(string name, IProperty<Texture2D> prop)
272278
Bind<VisualElement, Texture2D>(name, prop, SetBackgroundImage);
273279
}
274280

275-
public void BindTextField<T>(string name, IProperty<T> sourceProp, Property<string> inputTextProp, Func<T, string> transform, Func<ChangeEvent<string>, bool> validate = null, Property<bool> validateProp = null)
281+
public void BindTextField(string name, Property<string> prop, bool twoWay)
276282
{
277283
if (TryGetElement<TextField>(name, out var element))
278284
{
279-
BindTextField(element, inputTextProp, validate, validateProp);
280-
Bind(sourceProp, value => inputTextProp.Value = transform.Invoke(value));
285+
BindTextField(element, prop, twoWay);
281286
}
282287
}
283288

284-
public void BindTextField(string name, Property<string> prop, Func<ChangeEvent<string>, bool> validate = null, Property<bool> validateProp = null)
289+
private void BindTextField(TextField textField, Property<string> property, bool twoWay)
285290
{
286-
if (TryGetElement<TextField>(name, out var element))
291+
Bind(property, value => textField.value = value);
292+
293+
if (twoWay)
287294
{
288-
BindTextField(element, prop, validate, validateProp);
295+
On<ChangeEvent<string>>(textField, e => property.Value = e.newValue);
289296
}
290297
}
291298

292-
private void BindTextField(TextField textField, Property<string> property, Func<ChangeEvent<string>, bool> validate, Property<bool> validateProp = null)
299+
#if UNITY_2022_1_OR_NEWER
300+
public void BindIntegerField(string name, Property<int> prop, bool twoWay)
293301
{
294-
Bind(property, value => textField.value = value);
295-
296-
var inputCallback = new EventCallback<ChangeEvent<string>>(e =>
302+
if (TryGetElement<IntegerField>(name, out var element))
297303
{
298-
if (validate != null)
299-
{
300-
var isValid = validate(e);
301-
302-
if (isValid)
303-
{
304-
textField.RemoveFromClassList("invalid-input");
305-
}
306-
else
307-
{
308-
textField.AddToClassList("invalid-input");
309-
}
310-
311-
if (validateProp != null)
312-
{
313-
validateProp.Value = isValid;
314-
}
315-
}
304+
BindIntegerField(element, prop, twoWay);
305+
}
306+
}
316307

317-
property.Value = e.newValue;
318-
});
308+
private void BindIntegerField(IntegerField intField, Property<int> property, bool twoWay)
309+
{
310+
Bind(property, value => intField.value = value);
319311

320-
On(textField, inputCallback);
312+
if (twoWay)
313+
{
314+
On<ChangeEvent<int>>(intField, e => property.Value = e.newValue);
315+
}
321316
}
317+
#endif
322318

323319
public void SetClass(VisualElement element, string className, bool value)
324320
{
@@ -486,6 +482,12 @@ public void Bind<TElement, T>(string name, IProperty<T> prop, Action<TElement, T
486482
}
487483
}
488484

485+
public void Bind<TElement, T>(TElement element, IProperty<T> prop, Action<TElement, T> action)
486+
where TElement : VisualElement
487+
{
488+
Bind(prop, v => action(element, v));
489+
}
490+
489491
public void Set<T>(string name, Action<T> action) where T : VisualElement
490492
{
491493
if (TryGetElement<T>(name, out var element))

Bindings/Packages/com.virtualmaker.bindings/Runtime/Property.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,4 @@ public static DerivedProperty<TDerived> From<TValue, TDerived>(IProperty<TValue>
259259
return DerivedProperty<TDerived>.From<TValue>(property, func);
260260
}
261261
}
262-
263-
public class PropertyConverter<T> : Newtonsoft.Json.JsonConverter<Property<T>>
264-
{
265-
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, Property<T> value, Newtonsoft.Json.JsonSerializer serializer)
266-
{
267-
serializer.Serialize(writer, value.Value);
268-
}
269-
270-
public override Property<T> ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, Property<T> existingValue, bool hasExistingValue, Newtonsoft.Json.JsonSerializer serializer)
271-
{
272-
T value = serializer.Deserialize<T>(reader);
273-
return new Property<T> { Value = value };
274-
}
275-
}
276262
}

Bindings/Packages/com.virtualmaker.bindings/Runtime/VirtualMaker.Bindings.asmdef

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
"excludePlatforms": [],
99
"allowUnsafeCode": false,
1010
"overrideReferences": true,
11-
"precompiledReferences": [
12-
"Newtonsoft.Json.dll"
13-
],
11+
"precompiledReferences": [],
1412
"autoReferenced": true,
1513
"defineConstraints": [],
1614
"versionDefines": [],

Bindings/Packages/manifest.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"dependencies": {
3-
"com.unity.collab-proxy": "1.17.2",
3+
"com.unity.ai.navigation": "1.1.5",
4+
"com.unity.collab-proxy": "2.3.1",
45
"com.unity.feature.development": "1.0.1",
5-
"com.unity.ide.rider": "3.0.15",
6-
"com.unity.ide.visualstudio": "2.0.16",
6+
"com.unity.ide.rider": "3.0.28",
7+
"com.unity.ide.visualstudio": "2.0.22",
78
"com.unity.ide.vscode": "1.2.5",
8-
"com.unity.test-framework": "1.1.31",
9+
"com.unity.test-framework": "1.1.33",
910
"com.unity.textmeshpro": "3.0.6",
10-
"com.unity.timeline": "1.6.4",
11+
"com.unity.timeline": "1.7.6",
1112
"com.unity.ugui": "1.0.0",
12-
"com.unity.visualscripting": "1.7.8",
13+
"com.unity.visualscripting": "1.9.2",
1314
"com.unity.modules.ai": "1.0.0",
1415
"com.unity.modules.androidjni": "1.0.0",
1516
"com.unity.modules.animation": "1.0.0",

0 commit comments

Comments
 (0)