Skip to content

Commit fd96986

Browse files
committed
fix view properties in binding editor
fix CollectionBinding (template reusing)
1 parent 496e465 commit fd96986

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

UnityWeld/Binding/CollectionBinding.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ private void PutTemplateToPool(Template template)
228228
_pool.Add(template.ViewModelTypeName, pool = new Queue<Template>());
229229
}
230230

231+
template.gameObject.SetActive(false);
231232
pool.Enqueue(template);
232233
}
233234

UnityWeld/Binding/Internal/PropertyFinder.cs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public static class PropertyFinder
1515
/// <summary>
1616
/// List of types to exclude from the types of components in the UI we can bind to.
1717
/// </summary>
18-
private static readonly HashSet<Type> hiddenTypes = new HashSet<Type>{
18+
private static readonly HashSet<Type> hiddenTypes = new HashSet<Type>
19+
{
1920
typeof(AbstractMemberBinding),
2021
typeof(OneWayPropertyBinding),
2122
typeof(TwoWayPropertyBinding)
@@ -24,24 +25,31 @@ public static class PropertyFinder
2425
/// <summary>
2526
/// Use reflection to find all components with properties we can bind to.
2627
/// </summary>
27-
public static IEnumerable<BindableMember<PropertyInfo>> GetBindableProperties(GameObject gameObject) //todo: Maybe move this to the TypeResolver.
28+
public static BindableMember<PropertyInfo>[] GetBindableProperties(GameObject gameObject) //todo: Maybe move this to the TypeResolver.
2829
{
30+
BindableMember<PropertyInfo>[] bindableProperties;
2931
using(var cache = gameObject.GetComponentsWithCache<Component>())
3032
{
31-
return cache.Components
32-
.SelectMany(component =>
33-
{
34-
var type = component.GetType();
35-
return type
36-
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
37-
.Select(p => new BindableMember<PropertyInfo>(p, type));
38-
})
39-
.Where(prop => prop.Member.GetSetMethod(false) != null
40-
&& prop.Member.GetGetMethod(false) != null
41-
&& !hiddenTypes.Contains(prop.ViewModelType)
42-
&& !prop.Member.GetCustomAttributes(typeof(ObsoleteAttribute), true).Any()
43-
);
33+
bindableProperties = cache.Components
34+
.SelectMany(component =>
35+
{
36+
var type = component.GetType();
37+
return type
38+
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
39+
.Select(p => new BindableMember<PropertyInfo>(p, type));
40+
})
41+
.Where(prop => prop.Member.GetSetMethod(false) != null
42+
&& prop.Member.GetGetMethod(false) != null
43+
&& !hiddenTypes.Contains(prop.ViewModelType)
44+
&& !prop.Member
45+
.GetCustomAttributes(typeof(ObsoleteAttribute), true)
46+
.Any()
47+
).OrderBy(prop => prop.ViewModelTypeName)
48+
.ThenBy(prop => prop.MemberName)
49+
.ToArray();
4450
}
51+
52+
return bindableProperties;
4553
}
4654
}
47-
}
55+
}

UnityWeld_Editor/OneWayPropertyBindingEditor.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ protected override void OnInspector()
4747
Type viewPropertyType;
4848
ShowViewPropertyMenu(
4949
new GUIContent("View property", "Property on the view to bind to"),
50-
PropertyFinder.GetBindableProperties(targetScript.gameObject)
51-
.OrderBy(prop => prop.ViewModelTypeName)
52-
.ThenBy(prop => prop.MemberName)
53-
.ToArray(),
50+
PropertyFinder.GetBindableProperties(targetScript.gameObject),
5451
updatedValue => targetScript.ViewPropertyName = updatedValue,
5552
targetScript.ViewPropertyName,
5653
out viewPropertyType

UnityWeld_Editor/TwoWayPropertyBindingEditor.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ protected override void OnInspector()
7575
Type viewPropertyType;
7676
ShowViewPropertyMenu(
7777
new GUIContent("View property", "Property on the view to bind to"),
78-
PropertyFinder.GetBindableProperties(targetScript.gameObject)
79-
.OrderBy(prop => prop.ViewModelTypeName)
80-
.ThenBy(prop => prop.MemberName)
81-
.ToArray(),
78+
PropertyFinder.GetBindableProperties(targetScript.gameObject),
8279
updatedValue => targetScript.ViewPropertyName = updatedValue,
8380
targetScript.ViewPropertyName,
8481
out viewPropertyType

0 commit comments

Comments
 (0)