Set whether AttributeBinding is one-way binding or two-way binding

WeiYiHua

Member
Hello, in my game project, there will be a situation where an Attribute is bound to multiple values. For example, the left-hand item and the right-hand item in UCC integration are bound to an attribute at the same time.

In the present case, such multiple bindings can only be one-way. For example, ItemObjectBinding in UCC integration is one-way, although it still has the problem of not being able to synchronize properties in real time.

So I decided to expand AttributeBinding and add a bool to AttributeBindingBase indicating whether it is a two-way binding to control whether to call Attribute.Bind() or directly register the Attribute.OnAttributeChanged event when binding.

Is this solution feasible? Please let me know if there is a better way, thanks!

(This solution should be able to solve the problem of ItemObjectBinding at the same time)
 
From my testing I found that it was very tricky to get a two way Binding on multiple objects.
The way the binding works is by essentially redirecting the "set" and "get" call to the property rather than attribute value.
So if you try to bind it to multiple objects it just won't work because it cannot redirect the "set" and "get" to two different places.

The only way I think it could work is if the bound property was the one that was redirected to point to an external get/set this way they could all point to the same thing.
The issue is that I don't think this will be possible in a "proper" way. You'd need to have access to the set/get of the property and that would only be possible through reflection which could lead to perfromance issues if there are too many.


Your solution of listening to the on attribute change event does seem to be a cleaner way to do it. But if something changes one of the object bound to the attribute I don't know how you'd be able to tell the attribute it should call that event without all the stuff I explained above.

As long as you only cahnge the attribute value and never the property directly I thing that will work well, but unfortunatly I don't think this is an assumption I can make for all projects.

It's a tricky problem.
If you do find a generic solution that works do let me know
 
You're right. In my project, one-way binding means literally syncing the value of the attribute to the property, but not the other way around. This avoids the tricky issues that come with multiple two-way bindings, while still allowing for one-way syncing of an attribute to multiple properties when necessary.

I admit that this may be an approach that only works effectively in my project, so I'll only be making modifications to it within the context of my project. Thank you for your response!
 
Top