Search Unity

[RELEASED] Data Bind for Unity

Discussion in 'Assets and Asset Store' started by coeing, Feb 16, 2015.

  1. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
  2. mmvlad

    mmvlad

    Joined:
    Dec 31, 2014
    Posts:
    87
    @coeing yep, I meant that. Thanks a lot! Waiting for 1.15!
     
  3. mmvlad

    mmvlad

    Joined:
    Dec 31, 2014
    Posts:
    87
    @coeing In one of my contexts, I subscribe to a listener and can't find a way to unsubscribe when this context is destroyed. How would you suggest to handle this? Or you just don't allow contexts to subscribe to events?
     
  4. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    There is no specific place to do something before a data context is destroyed, because it's just a plain C# class. So you would need some custom logic for that.

    As long as the data context is registered to an event of another object, it is not destroyed (i.e. garbage collected) anyway: https://stackoverflow.com/questions/298261/do-event-handlers-stop-garbage-collection-from-occurring

    One way to start with would be to add Init/Deinit methods to the data context where you register/unregister to the events. But probably a cleaner solution would be to keep this out of the data context and do it in a class which uses the data context.

    E.g. when I am using StrangeIoC there is a Mediator for each view which has access to the data context and can manipulate it depending on events that happen in the logic.
     
  5. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Fixed the issue (https://bitbucket.org/coeing/data-bind/issues/87/not-possible-to-assign-a-reference-as-data), it was indeed introduced in 1.14 and will be fixed with 1.15. Hopefully I will have time to release it on Friday.
     
  6. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    The new version 1.15 of Data Bind was just submitted and is now in review :)

    If there are any issues you are still missing, there is a public issue tracker where everybody can add their wishes, bug reports, ideas, feedback,...:

    https://bitbucket.org/coeing/data-bind/issues

    The main additions:
    - Single Initializer for data context node connectors, so only one LateUpdate call per frame instead of one per connector
    - Several bugfixes

    Here is the full changelog:
    * Issue #87 Allow all references if no object type is provided for GameObjectComponentSelectionField

    * Issue #86 Enum value conversion from int

    * Issue #82 Compute initial value of ComparisonCheck in its constructor

    * Issue #84 Add SelectableInteractableProvider

    * Issue #83 Add example for accessing Nth item of a collection via data binding

    * Issue #81 Set DataContextNodeConnector to not initialized when context changed to be able to reinitialize it correctly

    * Issue #79, #81 Use single initializer to initialize data context node connectors

    This way only one LateUpdate is called instead of one for each connector. Additionally initializations are made that are triggered by parent initializations (e.g. in GameObjectItemsSetter). This prevents one frame delays of the childs.

    * Issue #80 Using ToggleIsOnProvider instead of deprecated ToggleIsOnGetter in FunWithBooleans example

    The new version will be available in a few days in the Unity Asset Store:

    https://www.assetstore.unity3d.com/#!/content/28301
     
  7. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
  8. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    326
    Hi,

    So I'm now working on adding controller support on my game, and I would like to use the automatic UI navigation system from Unity with the EventSystem.

    Cause the EventSystem needs to know about the view (gameobject) and right now everything is only data (contexts).
    A good exemple of one of my screen, a list of quest:
    - So I have a collection of QuestContext displayed in a scrollview
    - When I click one, I send a ButtonClickCommand that set a "IsSelected" prop to true on the quest, and set "IsSelected" to false on the others. That, to show a highlight graphic on the selected quest.

    Now, I would like to use the left stick to switch the selected quest in the list view.

    What workflow do you suggest ?

    Thanks

    EDIT: I just saw "Event Trigger Command" and "Unity Event Trigger" but don't undestand how to use them... by the way I'm not on the latest version, to risky to update in the project currently
     
    Last edited: Oct 31, 2018
  9. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    I have not much experience with the controller input in Unity and for other input (touch + mouse) I use a custom solution, so I guess I can't help you that much.

    In the end you should have a SelectNextQuest() and SelectPrevQuest() method on the context which contains the list of quests. You can invoke the methods from the UI by using a Command where you set the path (SelectNextQuest/SelectPrevQuest) and call its InvokeCommand() method from a Unity event. Or you can call the methods directly if you have a reference to the context somewhere.
     
  10. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    465
    Hello @coeing
    If I instantiate object runtime which has ButtonClick binding, what should I call that it will pass event to the parent context which is up above in the scene hierarchy?
     
  11. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Hi @nicloay,

    The ButtonClickCommand (like all the UnityEventCommands) are meant to register themselves on the Unity event they were created for. Therefore they use the Target binding to get the mono behaviour where the Unity event is implemented.

    So if you setup the Target binding right after you instantiated the object, it might do still register itself correctly in the OnEnable() method. Normally the connection is made on a Prefab (where the ButtonClickCommand and its Target are both defined).
     
  12. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    465
    @coeing, So.. is there the way to force setup target binding from code?
     
  13. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    As I said, it's not really meant to be used that way. Of course you can always derive from the ButtonClickCommand and call one of the protected methods (check out UnityEventCommand.OnEnable and UnityEventCommand.RegisterListeners(TBehaviour target)) and see if that works.

    But in your case it would maybe better to register yourself to the onClick event of the button and use the Command behaviour of DataBind, which just takes the path to the context method to call. Than you can just call the Command.InvokeCommand() method when the button click event was triggered.
     
  14. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    465
    I see.
    Thanks for the comment.
    I tried to make isolated test, and it works as you described. Don't know why it doesn't work in my live project.
    Thanks.
     
  15. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    465
    @coeing I found what was my issue.

    I have object pool which enable disable objects, so when they instantiated they are not under the context and they lost connection to the context.
    Thanks for your well documented comments in code I found "OnContextChanged" method in CommandClass.

    So now when my object become visible by the object pool controller i just force call this method
    GetComponent<ButtonClickCommand>().OnContextChanged();

    and button command works well.
     
  16. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    I see. Good to hear that you found the issue :) Yes, the OnContextChanged method (it's from the base class DataBindingOperator) has to be called when the game object moves in the hierarchy. Maybe it's a good idea to call GetComponents<DataBindingOperator>() on your enabled game object and call OnContextChanged for each, in case you have some other data binding scripts on that game object in the future.
     
  17. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    465
    @coeing, Yes, I will try this. As I found that on ios I still have a problem.
    Thanks.

    upd1:
    Can't figure out what's the problem. here is a log from xcode. Maybe it related somehow to additional argument used by command.
    Code (CSharp):
    1. NullReferenceException: A null value was found where an object instance was required.
    2.   at AlbumContext.OpenPageOrPopup (PaintCraft.Canvas.Configs.PageConfig pageConfig) [0x00000] in <filename unknown>:0
    3.   at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    4.   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
    5.   at Slash.Unity.DataBind.Foundation.Commands.Command.InvokeCommand (System.Object[] args) [0x00000] in <filename unknown>:0
    6.   at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <filename unknown>:0
    7.   at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00000] in <filename unknown>:0
    8.   at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, Boolean pressed, Boolean released) [0x00000] in <filename unknown>:0
    9.   at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () [0x00000] in <filename unknown>:0
    10.   at UnityEngine.EventSystems.StandaloneInputModule.Process () [0x00000] in <filename unknown>:0
    11. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    12.   at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    13.   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
    14.   at Slash.Unity.DataBind.Foundation.Commands.Command.InvokeCommand (System.Object[] args) [0x00000] in <filename unknown>:0
    15.   at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <filename unknown>:0
    16.   at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00000] in <filename unknown>:0
    17.   at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, Boolean pressed, Boolean released) [0x00000] in <filename unknown>:0
    18.   at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () [0x00000] in <filename unknown>:0
    19.   at UnityEngine.EventSystems.StandaloneInputModule.Process () [0x00000] in <filename unknown>:0
    20. UnityEngine.Logger:LogException(Exception, Object)
    21. UnityEngine.Debug:LogException(Exception)
    22. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    23. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    24. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    25. UnityEngine.EventSystems.StandaloneInputModule:Process()
     
    Last edited: Nov 8, 2018
  18. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    465
    @coeing Could you check this test case in attachments. (made on unity 2017.4)
    It reproducible on the editor (SetActive is called before SetParent) so ButtonClick Doesn't work properly.

    Also if you will try to use just OnContextChanged on iOS you will probably still get the error because of the constant data provider parameter for the command. which does not initialize properly, and OnContextChanged doesn't help.
     

    Attached Files:

  19. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Thanks for the sample project, I will have a look soon, when I've got time.
     
  20. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Hi @nicloay,

    I had a look at your example. The problem is that you call SetActive(true) before you anchor the new game object under your parent (which has the context holder). Therefore the game object can't find the context.

    Either put the SetActive call after the SetParent:
    Code (CSharp):
    1.  
    2.         GameObject clone = GameObject.Instantiate(_button);
    3.         clone.transform.SetParent(_button.transform.parent, true);
    4.         clone.GetComponent<RectTransform>().anchoredPosition = Vector3.zero;  
    5.         clone.SetActive(true);    
    Or call OnContextChanged on the context operators of the new game object:

    Code (CSharp):
    1.  
    2.         GameObject clone = GameObject.Instantiate(_button);
    3.         clone.SetActive(true);                  
    4.         clone.transform.SetParent(_button.transform.parent, true);
    5.         clone.GetComponent<RectTransform>().anchoredPosition = Vector3.zero;  
    6.      
    7.         // Update context operators of new game object as their context may have changed
    8.         var contextOperators = clone.GetComponentsInChildren<IContextOperator>(true);
    9.         foreach (var contextOperator in contextOperators)
    10.         {
    11.             contextOperator.OnContextChanged();
    12.         }
     
  21. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    465
    @coeing Yes. thanks for checking this. I used the first solution (changed the order) because OnContextChanged() didn't work on iOS.
     
  22. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    About your exception on iOS: Check your method OpenPageOrPopup in AlbumContext. You are accessing a variable there which is null.
     
  23. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Alright. Could you tell me what didn't work with OnContextChanged() on iOS? What did fail?
     
  24. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    465
    @coeing, I mean that when I tried "OnContextChanged" solution (first time when I noticed the problem), it worked fine in editor, but on iOS it had a problem. So if "OnContextChanged" solution works for you on iOS then it's probably problem somewhwere in my code.
     
  25. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    I see. I can't guarantee that it's not a problem on my side, I just hear from it for the first time. So if you get some error message or crash dump, feel free to post it :)
     
  26. StephanieRowlinson

    StephanieRowlinson

    Joined:
    Jul 23, 2014
    Posts:
    99
    Hi,
    I'm considering buying this asset (databinding <3), but I have 2 questions first:

    - I assume I can use this completely from code without using the editor? We have sections of UI that are autogenerated based on the selected object.

    - Has anyone compared the performance of your asset with other approaches? Our project has a lot of UI and one of the components is a list of a 1000 objects, so performance is kind of important. ^^;
     
  27. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    465
    for 1000 object you have to use object pooling. In my case I wrote my custom datagrid which took data from databind and add children only those which visible in the frame (another one was no just inactive but even not in hierarchy because of data pooling).
    And all of those stuff is not related to databind as databind just bind data to component and you are asking about UI optimization.
     
    Last edited: Jan 2, 2019
    coeing likes this.
  28. StephanieRowlinson

    StephanieRowlinson

    Joined:
    Jul 23, 2014
    Posts:
    99
    You're right about the pooling and a big list would be one only a handful of properties to look up, so it's the wrong example. With that said, I've been reading this blog post and I'm still curious how this tree traversal scales when dealing with larger contexts.
     
  29. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Hi @SRowlinson ,

    Thanks for checking out my asset. As @nicloay already mentioned (thanks!), lists with thousands of entries need an optimization anyway, so there won't be that many lookups at a time.
    The lookups themselves are not explicitly optimized as there were no reports that they are a bottleneck. If you have a collection of items (like with your list entries) it is just an access by index.
    Multiple string-based lookups are only required to get a data property of a data context in a hierarchy (e.g. GameContext.FeatureXContext.SubFeatureYContext.ButtonClickedCommand). In my experience those cases don't occur too often. Even if they do, the lookup is done only once during initialization.

    That's an interesting use case. The asset was designed with a non-programmer in mind who uses the editor and can easily connect the UI to the data of the application without having to write code. The data contexts are the glue which are handled completely by code, but are read (and their methods invoked) by the UI scripts.
    In recent updates though I tried to make the scripts configurable by code, the main reason being to test them. Anyway I can't guarantee that it will work completely work out for you.

    I think the easiest way to find out is to buy the asset and give it a try. If it doesn't suit you, a refund is quickly done, so there's no financial risk involved :)
     
  30. TigerHix

    TigerHix

    Joined:
    Oct 20, 2015
    Posts:
    19
    Just bought the asset but I am kind of new to the MVVM model. I am wondering what is the best "design pattern" to implement a dynamically generated list? I assume I just need to create two types of contexts, one for the item and one for the collection, and I will update the collection context after the list content is loaded.
     
  31. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Hi @TigerHix (cute profile photo :) ),

    Thanks for trying out my asset.

    Yes, you are thinking in the right direction. I would suggest to have a look at the "Collection" example first. There you have a data context which contains a data collection of items (which are of a ItemDataContext type). The data collection is basically a list, but with additional events that are triggered, when something in the list changes.

    On UI side you can work with the GameObjectItemsSetter first. That script creates a new game object from a prefab for each item in a data collection and assigns this item to the context holder of the game object.

    But before I go on with more details, looking at the "Collection" example might be easier as long explanations :) Let me know if you have further questions afterwards.

    Cheers
    Christian
     
    TigerHix likes this.
  32. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    The new version 1.16 of Data Bind was just submitted and is now in review :)

    If there are any issues you are still missing, there is a public issue tracker where everybody can add their wishes, bug reports, ideas, feedback,...:

    https://bitbucket.org/coeing/data-bind/issues

    Here is the full changelog:
    • Issue #88 Add an ActiveSetter for a collection of game objects
    • Issue #89 Add unit tests to test xml serialization
    • Show public fields in context holder inspector

    The new version will be available in a few days in the Unity Asset Store:

    https://www.assetstore.unity3d.com/#!/content/28301
     
    nicloay likes this.
  33. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Aaaand it's already through the review :)

    https://www.assetstore.unity3d.com/#!/content/28301

    As the asset is in a state where it is quite stable, I'll do further updates only all 6 months from now on. Of course if major bugs are found, the update will be done as quickly as possible.

    The further updates are mainly to guarantee that Data Bind still works with new versions of Unity.
     
  34. Jochanan

    Jochanan

    Joined:
    Nov 9, 2016
    Posts:
    78
    Do you have any example of usage the CollectionAnyFilter class? @coeing
     
  35. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    No, unfortunately not. But you can check the usage of the similar class
    Code (CSharp):
    1. CollectionAggregation.Sum()
    which is used in the Aggregations example.

    In general those classes are meant as data providers which capsule a data collection and provide a single value. They are set up inside the data context.
     
    Jochanan likes this.
  36. Jochanan

    Jochanan

    Joined:
    Nov 9, 2016
    Posts:
    78
    I have tried to create Any aggregation using this line of code
    Code (CSharp):
    1. this.anyHighlightedProperty = CollectionAggregation.Any(this.Tabs, tab => tab.Highlight, highlight => highlight);
    I would like to take a collection of items and check, whether any of them has property Highlight set to true.
    Unfortunatelly, when the Highlight property in the collection Item is changed, the anyHighlightedProperty is not updated. Is it how it suppose to work? Do i have to implement listener for every item in the collection to listen to the changes instead? @coeing

    EDIT: I did it using CollectionObserver for now, but i would gladly re-use some of the other component(s)
     
    Last edited: Apr 3, 2019
  37. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    In this case you need to add a public property HighlightProperty to the tab data context which returns the data property backing field:

    Code (CSharp):
    1. this.anyHighlightedProperty = CollectionAggregation.Any<TabContext, bool>(this.Tabs, tab => tab.HighlightProperty, highlight => highlight);
     
    Last edited: Apr 3, 2019
  38. Jochanan

    Jochanan

    Joined:
    Nov 9, 2016
    Posts:
    78
    How would i need to change it to get the tab itself instead of bool?
    Code (CSharp):
    1. private readonly IDataProvider<TabContext> anyHighlightedTabProperty;
    EDIT: Another thing. I have noticed, that everything bound to Highlight stopped working. When i attached for example LogicalBoolFormatter to Highlight, it always returns false no matter what was filled in the Highlight property. As soon as i make that property private, it worked again...
     
    Last edited: Apr 4, 2019
  39. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    The Any aggregation is supposed to always return a bool value (like the LINQ function it is based on). What you probably need is a First aggregation which returns the first item of a collection that fulfills a given predicate. Such an aggregation doesn't exist yet.

    You have to keep the private backing field for the data property and only have to add the public getter property. Otherwise the backing field won't be found and the data will be used as a normal property without a data property behind it. Like this:

    Code (CSharp):
    1.  
    2.  
    3.         private readonly Property<string> textProperty =
    4.             new Property<string>();
    5.  
    6.         public string Text
    7.         {
    8.             get
    9.             {
    10.                 return this.textProperty.Value;
    11.             }
    12.             set
    13.             {
    14.                 this.textProperty.Value = value;
    15.             }
    16.         }
    17.  
    18.         public Property<string> TextProperty
    19.         {
    20.             get
    21.             {
    22.                 return this.textProperty;
    23.             }
    24.         }
     
    Jochanan likes this.
  40. sameer-mirza

    sameer-mirza

    Joined:
    Nov 14, 2011
    Posts:
    36
    Hi again @coeing ,

    Do you have suggestions on how to introduce Undo/Redo to a system using DataBind ? How would the command pattern fit in? Do you think the Command classes which are part of the DataBind framework would have a role?

    Best,
    Sameer.
     
  41. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Hi @sameer-mirza,

    No, I don't think DataBind can help you with a Undo/Redo system. The command class is the base class for actions that are triggered in the UI to forward them to the data context. It is not related to the command pattern.
     
  42. MoFaShi

    MoFaShi

    Joined:
    Oct 25, 2015
    Posts:
    31
    I have just bought your asset and I have one question.
    I used dataContext.PlayerName = "ABC" to change a property, but nothing happened.
    I used dataContext.SetValue("PlayerName", "ABC"), it worked, but it is a little inconvenient in this way.
    so how can I use Property to change data?
     
  43. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Hi @MoFaShi
    Thanks for buying Data Bind for Unity and trying it out.

    Your data context class should look like this:
    Code (CSharp):
    1.  
    2. using Slash.Unity.DataBind.Core.Data;
    3.  
    4. public class TestDataContext : Context
    5. {
    6.     private readonly Property<string> playerNameProperty = new Property<string>();
    7.  
    8.     public string PlayerName
    9.     {
    10.         get
    11.         {
    12.             return this.playerNameProperty.Value;
    13.         }
    14.         set
    15.         {
    16.             this.playerNameProperty.Value = value;
    17.         }
    18.     }
    19. }
    20.  
    If so it should be possible to set the player name by the property setter: dataContext.PlayerName = "ABC"

    If it still doesn't work, please check out the examples or send me a small test project, so I can check it.
     
  44. MoFaShi

    MoFaShi

    Joined:
    Oct 25, 2015
    Posts:
    31
    thanks, it works.
     
  45. MoFaShi

    MoFaShi

    Joined:
    Oct 25, 2015
    Posts:
    31
    I'm trying to activate an Image component by Active Setter, but got an error, is this a bug?

    InvalidCastException: Can't cast value 'Image (UnityEngine.UI.Image)' of binding 'Reference: Image' to type 'UnityEngine.GameObject'
    Slash.Unity.DataBind.Core.Presentation.DataBinding.GetValue[T] () (at Assets/Slash.Unity.DataBind/Scripts/Core/Presentation/DataBinding.cs:149)
    Slash.Unity.DataBind.Foundation.Setters.GameObjectSingleSetter`1[T].get_Target () (at Assets/Slash.Unity.DataBind/Scripts/Foundation/Setters/GameObjectSingleSetter.cs:38)
    Slash.Unity.DataBind.Foundation.Setters.GameObjectSingleSetter`1[T].OnObjectValueChanged () (at Assets/Slash.Unity.DataBind/Scripts/Foundation/Setters/GameObjectSingleSetter.cs:91)
    Slash.Unity.DataBind.Core.Presentation.DataBinding.OnValueChanged () (at Assets/Slash.Unity.DataBind/Scripts/Core/Presentation/DataBinding.cs:278)
    Slash.Unity.DataBind.Core.Presentation.DataBinding.OnTargetValueChanged (System.Object newValue) (at Assets/Slash.Unity.DataBind/Scripts/Core/Presentation/DataBinding.cs:269)
    Slash.Unity.DataBind.Core.Presentation.DataContextNodeConnector.OnValueChanged (System.Object newValue) (at Assets/Slash.Unity.DataBind/Scripts/Core/Presentation/DataContextNodeConnector.cs:311)
    Slash.Unity.DataBind.Core.Presentation.DataContextNodeConnector.Init (System.Object initialValue) (at Assets/Slash.Unity.DataBind/Scripts/Core/Presentation/DataContextNodeConnector.cs:143)
    Slash.Unity.DataBind.Core.Presentation.DataContextNodeConnectorInitializer.ExecuteInitializations () (at Assets/Slash.Unity.DataBind/Scripts/Core/Presentation/DataContextNodeConnectorInitializer.cs:34)
    Slash.Unity.DataBind.Core.Presentation.DataBindRunner.LateUpdate () (at Assets/Slash.Unity.DataBind/Scripts/Core/Presentation/DataBindRunner.cs:56)
     
  46. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Hi @MoFaShi ,

    No, it's the expected behaviour. The ActiveSetter needs a reference to a GameObject, not to a mono behaviour (e.g. Image). So just drag the whole game object 'Image' on the reference field of the ActiveSetter and it should work :)

    There is also an example especially for the ActiveSetter usage, so you can also check that out if you have still problems using it.

    Cheers
    Christian
     
  47. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    100
    I have a scenario where I am comparing values on a GUI element; first is an array of Custom context (Resources.3.Amount, Resources.16.Amount) and the second being an array of constant.

    Code (CSharp):
    1.         public override void Init()
    2.         {
    3.             if(this.First.Length != this.Second.Length)
    4.             {
    5.                 throw new Exception("Building Comparison Provider: First & Second lengths don't match");
    6.             }
    7.             this.comparisonCheck = new BuildingComparison[this.First.Length];
    8.             for (int i = 0; i < this.First.Length; i++)
    9.             {
    10.                 this.AddBinding(this.First[i]);
    11.                 this.AddBinding(this.Second[i]);
    12.                 this.comparisonCheck[i] = new BuildingComparison(this.First[i], this.Second[i], this.Comparison);
    13.             }
    14.         }
    The problem I'm encountering is I'm trying to find a way of updating the constant value. I'm aware of onContextChanged but is there a way to update the constant?
     
  48. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    Hi @SirStompsalot ,

    A constant value can't be updated, because it's really constant and the data provider won't trigger a "value changed" event if you change the constant value by code somehow.

    But that might not be the core of your problem here. If you could send me the whole script I can check it, with the code snippet of the Init method alone I don't have enough information.

    Cheers
    Christian
     
  49. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    The new version 1.17 of Data Bind was just submitted and is now in review :)

    If there are any issues you are still missing, there is a public issue tracker where everybody can add their wishes, bug reports, ideas, feedback,...:

    https://bitbucket.org/coeing/data-bind/issues

    Here is the full changelog:

    • Updating to Unity 2018.1 as minimum version and 2019.1 as recent version
    • Issue #90 Use ToggleIsOnProvider instead of deprecated ToggleIsOnGetter in ActiveSetter example
    • Aggregations Example - Use data property instead of plain property in Any filter

    The new version will be available in a few days in the Unity Asset Store:

    https://www.assetstore.unity3d.com/#!/content/28301
     
  50. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    230
    naby7u likes this.