Bind to subclass context
Ziboo opened this issue · comments
Hello,
First of all, thank you for this asset :)
I'm trying to use Databinding and trying to bind my context to a bool from subclass
I have a monobehaviour D3D_Engine with subclass like that
D3D_Engine
- D3DApp
-D3DEvent
- public bool IsGalleryEnable
I can't find a way to access this boolean
It seams that I can only bind to variables on the firstlevel of the monobehaviour
Btw: I derived D3D_Engine to ObservableBehaviour and my subclass to ObservableObject
Thanks
You want to use a property binder to bind to a object within an object.
https://github.com/NVentimiglia/Unity3d-Foundation/wiki/1)-Databinding#binding-context
In your UI 'root' you will place a BindingConext pointing to the 'root' monobehaviour. Create a new 'child' game object under the root and add a binding context. Set it to property binding and select the name of the 'child' object within the 'root' object.
This will allow you to bind to child objects within parent objects.
Code
public class RootObject: MonoBehaviour
{
public Profile ChildObject {get;set;}
}
UI
-> GameObject With BindingContext pointing to Root Object
-> -> GameObject with BindingContext pointing to ChildObject
Ok I see
One thing that is annoying though, the MonoBinding take the first monobehavior on the gameobject, is it possible to add the possibility of choosing which monobehavior to target ?
That is a good point, I will look into that as I have run into that myself.
For now, open two inspectors, select the binder, and lock it. Then select the element with the unlocked binder.