jbruening / ugui-mvvm

Unity3D uGUI mvvm databinding via the standard IXChanged interfaces used in wpf (INotifyPropertyChanged, INotifyCollectionChanged, etc)
Other
214 stars 41 forks source link

PropertyBinding issue #42

Open alexanderlarsen opened 2 years ago

alexanderlarsen commented 2 years ago

I'm experiencing an issue with the PropertyBinding. It works mostly perfect but when I want to do a TwoWay binding, the target needs to have two UnityEvents. If there is only one, the dropdown won't appear and the single UnityEvent that does exist in the Target class won't get automatically assigned.

Steps to reproduce:

  1. Create new class with one property and one UnityEvent (that is invoked when the property changes)
  2. Create source class that implements INotifyPropertyChanged and has a property
  3. Add a PropertyBinding component to some GameObject
  4. Add the first class as the target and assign its property
  5. Select Mode = TwoWay
  6. Add the other INotifyPropertyChanged class as the source and select its property
  7. Run play mode and change the two properties

Behavior: Source updates target property but not vice versa

If I create two UnityEvents in the target class and select one of them in the dropdown (making sure it's invoked when the property changes ofc), everything works. So it seems that the PropertyBindingEditor class needs to have something selected in the dropdown for two way data binding to work. It won't select the single UnityEvent automatically behind the scenes. I assume that was the idea, to hide the dropdown and select event automatically if there is only one event but unfortunately it doesn't work.

I simply love this data binding implementation, so I really hope there is a way to fix this. I think the problem is in the PropertyBindingEditor somewhere, but my knowledge of EditorGUI scripting and reflection isn't enough to fix it myself.