Search Unity

Ez Bind - Professional Data Binding Solution

Discussion in 'Assets and Asset Store' started by sharkyro, Mar 22, 2017.

  1. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Ez-Bind_Facebook-@1200x630.png
    Ez Bind on the Asset Store can be found here.

    Data binding is a general technique that binds variables together and synchronizes their values.

    In a data binding process, each data change in the bind Source is reflected automatically in the Observers that are bound to it. Ez Bind is a one-to-many solution (one Source - to - many Observers)

    You can bind properties and variables between different classes and you can virtually bind everything, even between different scenes.

    Ez Bind performs automatic cleanup of removed (destroyed) objects, having a solid software architecture with a modular design. This allows the binding of data without the need of writing code.

    This approach is used for the MVVM (Model-View-ViewModel) pattern that is very popular in the C# world.

    Ez Bind has been optimized for all the mobile platforms.

    DOCUMENTATION | VIDEOS | SUPPORT

    Features
    - Professional Data Binding
    - Scene Independent Data Binds
    - Data Binding Across Different Scenes
    - Intelligent Bind System
    - Clean Custom Inspector
    - Optimized for Mobile
    - Easy to Use. Intuitive design
    - Supports all platforms
    - Comes with full C# source code
    - Dedicated support
    - Tutorials on our YouTube Channel

    As game devs ourselves, we are dedicated to continually improving and expanding our assets, based on everyone's feedback, and also providing top-notch support.
     
    Last edited: Mar 7, 2018
    shyamarama likes this.
  2. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
  3. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
  4. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    501
    looks cool!
     
  5. FatIgor

    FatIgor

    Joined:
    Sep 13, 2015
    Posts:
    29
    Great asset, very straightforward to setup directly in the inspector, but if I could make one suggestion, when binding to text, would be nice if I could add a modifier in the inspector rather than having to do it in code.

    e.g.

    Observer
    Text

    Source
    Float

    This sets text.string=float.toString();

    Would be useful if in the inspector could have the equivalent of text.string="some text"+float.tostring();
     
  6. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi,

    Thank you for the suggestion. We have considered something similar but ultimately we decided against it for the first release of the asset due to efficiency concerns. We will keep searching for a solution that scales well, aiming to include it in a future release.

    Cheers,
    Alex
    EZ ENTERTAINMENT
     
  7. Zanderfax

    Zanderfax

    Joined:
    Nov 2, 2016
    Posts:
    25
    Hello all!

    I have a quick question.. Is it possible to bind to an EZDataManager Array Element?
     
  8. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hello @Zanderfax,

    Unfortunately, at the moment, it is not possible to bind to elements of Arrays or Lists. We were unable to find a viable and efficient solution to this issue.

    Cheers,
    Alex.
     
  9. Zanderfax

    Zanderfax

    Joined:
    Nov 2, 2016
    Posts:
    25
    Thanks for the info Alex.

    As a side note both the EZBind and EZDataManager assets are excellent!

    Z
     
  10. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Thank you @Zanderfax ! :)
     
  11. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    183
    Is anyone else getting a "[EzBind] - Error when adding a new bind named "nameHere" : An element with the same key already exists in the dictionary." on scene change?

    Not entirely sure what is going wrong here.

    Thanks in advance!
     
  12. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @Meatloaf4,

    As discussed over email, the issue comes from our old singleton implementation in v1 of the asset. If anyone else has this problem, please email us for the fix.

    Cheers,
    Alex.
     
  13. WhiteGfx

    WhiteGfx

    Joined:
    Apr 10, 2017
    Posts:
    16
    Hi, just quick question regarding import Ez Assets. All packages are great ;)

    Maybe you know this issue but for sure, If new project ic created in Unity 2017.1.1p3 (mac osx 10.12.6) (2d, disabled analytics) and selected to add only these assets (Bind, DataManager, DefineSymbols, Polly) Im getting this error:

    Assets/Plugins/Ez/Bind/Scripts/Editor/BindResources.cs(5,10): error CS0234: The type or namespace name `Internal' does not exist in the namespace `Ez'. Are you missing an assembly reference?

    Assets/Plugins/Ez/Bind/Scripts/Editor/BindResources.cs(14,23): error CS0246: The type or namespace name `GTexture' could not be found. Are you missing an assembly reference?

    Only fixed when Im import EzBind again manually. Which package from (DataManager, DefineSymbols, Polly) break the bind asset source files? Must be something about shared folder. When fix will be available on asset store? Or do you already have fixed package?

    Let me now if problem is confirmed or if you need more info. Thank you
     
  14. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hello @WhiteGfx!

    We are aware of this issue. In order to reduce project clutter and not have duplicate resources that are used separetely by each asset, we have a common infrastructure for handling the editor/inspector and its resources. An unfortunate side-effect has been the issue you encountered - caused by the evolution of the editor infrastructure in the case of different assets.

    A major update and overhaul of all assets is currently in production - this will bring big changes both on the editor side as well as runtime optimisations and new functionalities. To avoid problems such as the one you have encountered, we will update all assets at once so, at this time, we cannot give you a definitive timeframe for the update - we want it to be as soon as possible, of course :).

    In the mean time, to avoid the editor errors, a simple workaround is to manually import our assets in a specific order:
    - always import Ez Define Symbols first
    - import Ez Ads/Ez Data Manager/Pooly - generally in any order, but we can confirm this works :)
    - always import Ez Bind last

    Cheers,
    Alex.
     
    WhiteGfx likes this.
  15. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hello everyone!

    We're very excited to announce EzBind - Live Data version 2.0! Check out the introduction to the new version and the tutorial on how to upgrade on our YouTube channel:

    EzBind - Live Data v2.0 Introduction:


    Upgrade Guide for Ez assets - from version 1.x to version 2.x:


    Cheers!
     
  16. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    Hello @sharkyro - I had a question before i buy EZ Bind - I have created a data system based on scriptable objects - I store almost all of my data in scriptable objects and have a system that can serialize and deserialize a list of scriptable objects to disk for persistance/saving/etc. I would like to buy EZ Bind and do data binding from these scriptable objects to things in the game. Does EZ Bind support binding to source data from a scriptable object?
     
  17. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @Rocktavious! The answer is yes - starting with v2.0, EzBind fully supports binding to/from ScriptableObjects.

    At the moment, the only limitation is that it is not permitted to bind on Arrays/Lists nor on their members. You can, however, bind serializable custom classes - and, if a serializable list or array is member of that class, it will be synchronized as well (but only in whole, you still can't bind members). Since ScriptableObjects are serializable, you shouldn't experience any problems.

    Cheers,
    Alex.
     
  18. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    @sharkyro Thanks, and double thanks for the mention on lists - as that was going to be my next question. Does that mean it is permitted to bind to list members for a field on a gameobject?
     
  19. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    I purchased EzBind - but i noticed it does not have support for Unity 2017.3's Assembly Definitions files. I have a large project and not having these Assembly Definitions files really drags down compile times. Is this something you guys are looking into?

    I tried adding some into the folder structure but it looks like you guys have circular dependencies between the "shared" code and the other Ez tools (i also installed EzDefine)

    This will make Assembly Definitions impossible to implement untill you fix the circular dependencies.

    Happy to provide any guidance on what needs to be fixed and/or where the place the Assembly Definitions files.
     
  20. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    Also it looks like you cannot move the top level Ez folder to anywhere else in the project - you get errors when you open the control panel from the Quick tooling saying Texture is Empty and/or not finding the settings scriptable objects.
     
  21. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    @Rocktavious ok, let's take it one step at a time :)

    No, as I said, it is not possible to bind on array/list members. From personal experience, it's always best to bind variables with clear names, otherwise their significance can easily be forgotten.

    All Ez tools were designed to have a shared editor code base for the Inspector and the Control Panel. There is nothing to fix, as the system was designed like this to make the editors consistent.

    At the moment, we don't have plans to support Assembly Definitions - they're too new and they are not a suitable solution for the vast majority of our users - as per Unity's recommendation this should either be implemented at project level or not at all.

    If you want to implement this yourself, I can suggest we move this discussion to our support email (support@ezentertainment.eu) and we will do our best to provide assistance.
    If the support for this feature is a deal-breaker for you, the only option is to offer you a refund.

    This should not happen; all tools work correctly, even when moved from the default location (this was tested on Unity 5.6 and 2017.x). It might be a Unity bug (fixable by restarting Unity).

    Best Regards,
    Alex.
     
  22. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    @sharkyro Thanks for the speedy reply!!!

    Makes sense on the list thing - If your data is stored in a list, do you guys have a recommended way to databind to get around this limitation? Essentially what i'm trying to do is i have a List of a custom class and i'd like to spawn a prefab for each item in that list and then data bind the data for each item in the list to the data on the prefab such that the prefab can update itself with the specific data its been handed?

    As for the Assembly def's happy to take it to support e-mail i'd really like to get this implemented as it really speeds up our workflow compile times when we don't have to wait for all our 3rd party assets to recompile each time. I'll reach out.

    As for the moving of the folder it looks like it took 2 restarts - not sure why - it recompiled after each restart and only on the 2nd restart after the move of the Ez folder into the plugins folder did it actually open the control panel without any errors. Thanks!!!!

    I look forward to getting into the databinding aspect now - and we can workout the assembly defs via e-mail.
     
  23. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    This premise is really simple and is something that we are using all the time - but not for "setup" data, only for variables that can change at runtime :)

    We developed EzBind as a quick and efficient way to synchronize, at runtime, variables that are value types - because those are the real pain to synch. If you're only working with custom data classes, why bind when you can just get a reference once and be done with it?
    Also, are you binding to data that is being modified at runtime? Based on your description, it doesn't seem you're in need of data binding (at least not in the aforementioned scenario).
     
  24. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    @sharkyro - Well this is just one of the examples i'm trying to bind for - i have other situations where i'd like binding that is similar to your examples.
    But this is "Runtime" binding for a list - the list of data starts empty and during runtime is filled with data through actions taken by the user - when the list is updated i'll be spawning prefabs for each list item and take the data injected into the list and setting up the prefab with that list entries data - the prefab will have editors inside of it that edit some of the data which i'd like to be 2 way bound back to the source data (which is in a list in a scriptableobject) and then my scriptableobject data system will be saving that list data to disk at intervals or when the user initiates a save.

    Maybe i'm missing something but it seems like data binding would be really helpful to decouple all of that and allow it to be setup in the inspector without writing much, if any, code.
     
  25. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    @Rocktavious Don't worry, you're not missing anything - your point of view is quite clear. I was just explaining our philosophy behind EzBind - to facilitate syncing value types and to have a one-to-many model (one source, many observers).

    Just a quick example on our approach, just to give you an idea, nothing else - let's say for generic player data (name, health, currency, xp, etc...). We have all of these on a central, easily accessible (both from code and Inspector) singleton reference (we have EzDataManager for this exact purpose). All variables are setup as sources on different binds. Scripts that are responsible for changing values work directly on the central reference (the bind source). Anyone else (scripts, UI) is just updated when the source value changes.

    Important observation: no 2-way binding, you need a new bind (except for references, see below). Common scenario: 1 source, 20 observers, several listeners. To have 2-way binding would bring unjustifiable overhead by checking the observers for changes, as well. And any debugging would be a major pain.

    All of the above doesn't mean EzBind won't work with references (for serializable custom data types). Take a look at the example below:
    Code (CSharp):
    1. [Serializable]
    2. public class CustomDataClass
    3. { /* all your data */}
    4.  
    5. [Serializable]
    6. public class CustomDataList
    7. { public List<CustomDataClass> myList; }
    8.  
    9. public class DataHolder : MonoBehaviour // OR ScriptableObject
    10. {
    11.     public CustomDataClass myData;
    12.     public CustomDataList myDataList;
    13. }
    I think it covers your scenario. A few key notes:
    • You can bind variables of CustomDataClass (DataHolder.myData) or CustomDataList (DataHolder.myDataList), but not individual List members
    • Since both CustomDataClass and CustomDataList are reference types, EzBind will pass around the reference to the source, not a copy! Weather you like it or not, any changes to observer(s) will affect the source - as explained above, this is something we always try to avoid. In this case there's no overhead.
    • DataHolder must inherit from Unity's Component or ScriptableObject classes
    Cheers,
    Alex.
     
    Last edited: Mar 16, 2018
  26. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    @sharkyro - Your example is almost identical to what i'm trying to do - but i think the key is `EzBind will pass around the reference to the source, not a copy! Weather you like it or not, any changes to observer(s) will affect the source.` and while you say this is something you always try to avoid - i think in my case this is exactly what i want, because i can guarentee that there will only be 1 observer spawned for each item in the list.

    It sounds like what i would do is have CustomDataClass as a property on a top level controller script of my prefab that the spawning system spawns that prefab and sets the data for the item in the list it spawned for somehow (was hoping EzBind could do this part, and maybe i still can with a bit of code and an "index" into the list given at spawn time, by binding to the list and pulling out the index item) and then inside the prefab all the sub gameobjects and elements can bind to variables and things within the CustomDataClass? Seems like that would achieve the decoupling i want such that the prefab doesn't have to know about the list (or might but know how to get its index) and the things inside the prefab don't have to know where their data comes from, just that some variable will be "bound/updated" for them and they can display it, keeping nice separation of concerns.

    Thanks for working through this with me. I think i have a clear path forward to test out this type of databinding in my project!
     
  27. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    This behaviour is 100% not a problem as long as you are aware of it and it is what you need.

    Unfortunately, the approach you have described won't work out of the box.

    Before making a different suggestion, I need to understand exactly how your data list works. Generally speaking, we pool prefabs and we spawn their clones - so we have 1 pooled prefab, but we can spawn any number of its clones. In the data list will there be one entry for each prefab or one entry for each clone of the prefab (or there will be only 1 clone/prefab so it's the same thing)?
     
  28. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    @sharkyro It'll be a single prefab that needs to change its data when spawned to the data for 1 item in the list.

    Here is basically a trimmed down (trival but hopefully illustrates the want) example:
    Code (CSharp):
    1.  
    2. [Serializable]
    3. public class CustomData {
    4.     public string title;
    5.     public string description;
    6. }
    7.  
    8. public class DataManager : ScriptableObject{
    9.     public List<CustomData> DataList;   <- there will be multiple different CustomData items in this list
    10. }
    11.  
    12. public class SpawnableData : MonoBehaviour {
    13.     public CustomData Data;
    14.  
    15.     void OnSpawned()
    16.     {
    17.         ... apply the data and/or use binds to sub components to fill their GUI elements ...
    18.     }
    19. }
    20.  
    So then some spawning mechanism (pooly + custom code probably) will spawn the prefab 1 time for each of the items in the DataManager's DataList that has the SpawnableData behavior on it and somehow injects the data for the index it spawned for into the SpawnableData's Data reference. The the rest of the system takes over either through code or data binding the fields in CustomData of the SpawnableData field to other sub components (GUI elements). So the sub components don't have to know anything about the DataManager and we dont' have to hook directly into the DataManager, just the prefab for the SpawnableData has the bindings to the GUI elements - such that if i provide a UI element for the field "title" then it'll update the specific CustomData's title field reference in the DataManager - so my scriptableObject serialization system can save the changes to disk and everything is decoupled nicely.
     
    Last edited: Mar 16, 2018
  29. Paulo-Henrique025

    Paulo-Henrique025

    Joined:
    Dec 12, 2010
    Posts:
    230
    HI Alex, you seem to have a really cool Asset here! I want to inquire about its performance. I am currently using an in-house made solution for biding and MVVM, it uses reflection to set and update values, for small screens with a dozen binds its working fine but I found myself cornered on how many binds I can use without causing frame stuttering when turning on the objects(first set of binds value).

    The situation is a character selection in a 4 player split screen game, each character selection has ~70 binds, a single player already has a stutter when enabling this UI object, 4 player(~280 binds) is an unbearable 1s of a frame freeze.

    Performance wise, can I expect something better than straight reflection out of EZ Bind?

    Also, is there any platform limitation? I guess PS4, Switch, XOne, all should work fine.
     
  30. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    @Rocktavious You won't have the option to select members of CustomData class in the inspector (only whole CustomData variables).

    You could de-structure the DataList inside the DataManager and use binds to pass around these references (that will work 2-way, as you want them). My suggestion would be to start playing a bit with the example scene and then gradually introduce your own scenarios and see just how you can integrate EzBind. Then you can see what works for you and what doesn't and, based on that, we can take the discussion further.
     
    Last edited: Mar 19, 2018
  31. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @Paulo-Henrique025 !

    Indeed, EzBind is making use of reflection, however we have it heavily optimized. All the expensive work is done on initialization (so scene loading takes a bit longer), but updating values is done quickly and efficiently.

    In your case, have you run Unity's profiler to check where the bottleneck is? Based on your description, it may be the reflection but it could also be due to rendering. Are your binds one-to-one and what are you binding - our terminology for binds might differ (see below)?

    Our solution for binding is one-to-many, meaning that one value (called source) can update a multitude of targets (called observers). Our test baseline was 1 source string updating 1000 observer strings on scripts + 100 observer UIText fields, without frame loss, on a mobile device (no string manipulation, just duplication).

    There are no platform limitations. We are focused mainly on mobile development ourselves, so we made sure that EzBind is optimized and performs well in the mobile environment. We also have clients developing for PS & Xbox and there were no performance issues.
     
    Last edited: Mar 19, 2018
  32. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    @sharkyro
    Ok i've been playing around with EzBind some and it seems like you can only bind to actual class members? Will you guys eventually be supporting binding to Properties or Class Indexers?
    IE

    Code (CSharp):
    1. [Serializable]
    2. public struct ColorEntry {
    3.     public Color Color;
    4.     public Color ColorblindColor;
    5. }
    6.  
    7. [CreateAssetMenu(menuName = "RGL/Data/ColorPallete")]
    8. public class ColorPallete : ScriptableObject {
    9.    
    10.     public bool ColorblindMode = false;
    11.    
    12.     public List<ColorEntry> Pallete;
    13.    
    14.     void Awake() //Create
    15.     {
    16.         Pallete = new List<ColorEntry>();
    17.     }
    18.    
    19.     public Color color {   <- Unable to bind to this?
    20.         get {
    21.             if (ColorblindMode)
    22.             {
    23.                 return Pallete[0].ColorblindColor;
    24.             } else {
    25.                 return Pallete[0].Color;
    26.             }
    27.         }
    28.     }
    29.    
    30.     public Color this[int index] {  <- Unable to bind to this?
    31.         get {
    32.             if (ColorblindMode)
    33.             {
    34.                 return Pallete[index].ColorblindColor;
    35.             } else {
    36.                 return Pallete[index].Color;
    37.             }
    38.         }
    39.     }
    40. }
    Thanks!
     
  33. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @Rocktavious

    Binding on properties is supported at the moment, as long as the property is fully defined (has both getter & setter). A private/protected setter would make the color property above available for binding. Just be careful not to set properties with private getters as sources or properties with private setters as observers - although the configuration will be accepted, the binds will not work properly.

    At the moment, binding on a class indexer is not supported.
     
  34. XCPU

    XCPU

    Joined:
    Nov 5, 2017
    Posts:
    145
    Having a bit of problem with Ez Data Bind, seems I can no longer download or import it. (decrypt errors)
    Not sure if its a store problem or not at this point, Data Manager and Pooly seem okay though.
     
  35. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @XCPU

    Unfortunately, it's an asset store bug. We've opened a ticket almost a week ago but still have no solution from Unity. As an alternative, drop us an email at our support address (support@ezentertainment.eu) and we'll send you the latest EzBind version. Please be so kind as to include your invoice number in the email.

    Kind Regards,
    Alex.
     
    XCPU likes this.
  36. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    Hey @sharkyro I'm back again - after fumbling to try and get EzBind to work in my use case, i had to give up and move to something else, but now i'm back and have time again to try and solve this. I'd like to re-explain my situation -

    I have 2 Scriptable objects
    Code (CSharp):
    1.  
    2. public class CustomData : ScriptableObject {
    3.     public string Title;
    4.     public string Description;
    5. }
    6.  
    7. public class CustomDataList : ScriptableObject {
    8.     public List<CustomData> Items;
    9. }
    10.  
    The idea being that you create a bunch of CustomData things and then maybe throw a few of them into the CustomDataList - and hand to some UI Manager the CustomDataList SO so it can take each item in that list and spawn a prefab for each - i've blocked code for that generic spawning of a list to something like this
    Code (CSharp):
    1.  
    2. public class UIManager : MonoBehaviour
    3. {
    4.     public CustomDataList Data;
    5.     public UIItem Prefab;
    6.  
    7.     private void OnEnable()
    8.     {
    9.         foreach (CustomData item in Data.Items)
    10.         {
    11.             UIItem obj = Object.Instantiate<UIItem>(Prefab, transform);
    12.             // How do i assign CustomData to the spawned objects binds / how can i even setup the binds?
    13.         }
    14.     }
    15. }
    16.  
    So the 2 problems i'm having is:
    1: How do I setup binds on the UIItem prefab object to bind to data of CustomData (that will be dynamically set at runtime)
    2. How do I tell the binds configured on the prefab to use "this instance" of CustomData you've been spawned for without having to write something like CustomDataHolder and apply that to the prefab.
    Code (CSharp):
    1.  
    2. public class CustomDataHolder : MonoBehaviour {
    3.     public CustomData Data;
    4.     public string Title {
    5.         get { return Data.Title; }
    6.     }
    7. }
    8.  
    The sticky point for me is that it would be super nice to have this kind of spawn a object for each item in a list and have the databinds work for that specific item in the list this prefab was spawned for to other parts of the prefab's components without having to write any code as a concept in EzBind.

    This would allow for a fairly generic system to spawn a list of things (maybe even pooly - if it supports spawning for list.Count times) and then you only need to setup the binds on the prefab via the inspector and then every new CustomData SO you create, all you have to do is add it to the list in CustomDataList and when the game starts up it'll spawn that extra thing into the UI with the prefab showing its data (and if a designer wants the prefab to expose more fields of CustomData - they can do so by adding more binds and not have to write code in CustomDataHolder to expose the vars for binding - such as exposing the Description field from the original CustomData object).
     
    Last edited: Jul 23, 2018
  37. Roni92pl

    Roni92pl

    Joined:
    Jun 2, 2015
    Posts:
    396
    What about two-way binding? Al;so you really should consider support for collections, it's so basic stuff, it makes it almost unusable for GUI, where mvvm pattern is mostly needed.
     
    iddqd likes this.
  38. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @Rocktavious !
    I would recommend doing this with the help of local binds. Local binds work just like regular binds, but they only work as long as the GameObject holding their script is active & enabled. The advantage they bring is that they only work as long as needed and they only require locally unique names (unlike global binds configured on EzBind/EzBindExtension).

    Just set up an EzBindLocalBinds script on your prefab and make the necessary configuration. These binds only allow linking on their own GO and on ScriptableObjects.

    Let's go with your example and assume 2 local binds called "LocalTitle" and "LocalDescription" configured on the prefab. They both have observers on configured via the inspector and need to have the source assigned after being created (as their source SOs are dynamically created). It can be done like this:
    Code (CSharp):
    1.  
    2. public class UIManager : MonoBehaviour
    3. {
    4.     public CustomDataList Data;
    5.     public UIItem Prefab;
    6.  
    7.     private void OnEnable()
    8.     {
    9.         foreach(var item in data.Items)
    10.         {
    11.             // take note that UIItem must inherit from UnityEngine.Object
    12.             UIItem obj = Instantiate<UIItem>(Prefab, transform);
    13.  
    14.             var localBinds = obj.GetComponent<EzBindLocalBinds>();
    15.             // Set item.Title as source for the local bind LocalTitle:
    16.             localBinds.AddSourceToLocalBind("LocalTitle", item, "Title");
    17.             // Sets item.Description as source for the local bind named "LocalDescription"  
    18.             localBinds.AddSourceToLocalBind("LocalDescription", item, EzBind.GetReferenceName(new { item.Description }));
    19.         }
    20.     }
    21. }
    The difference between the first and the second option is the following:
    • In the first case, we knew that the name of the field (under item) is "Title", so we could hard-code it
    • In the second case, the name of the field was not known and we could not hard-code it. For such cases, EzBind offers the GetReferenceName() helper class, but that class must be invoked as shown above.
    For more details, please consult the manual, as it lists all available methods to add/remove binds, sources and observers from code and also shows examples.

    As explained above it can be done, but it needs a little bit of code. :)
    As for Pooly - just like EzBind, it was designed to be an Editor Extension - thus it is meant to work with Transforms. Maybe in the future that will change, as ECS (Entity Component System) will become widespread, but right now it is not feasible to do so.
     
  39. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @Roni92pl !

    Since these 2 are, by far, the questions we receive most often, I will take a bit of time to go into a detailed answer and clarify matters as best as I can.

    1. Two-way binding
    How it works now: As you know, EzBind is not 1-to-1 binding, instead it is 1-to-many (1 source, many observers). Every frame, the system checks if the value of the source has changed and, if it did, it automatically updates the values of the observers and invokes the listener methods.

    Implications of 2-way binding:
    The good: we get 2-way binding. Yay!
    The bad: before, there was 1 check/bind (the source). Now we have 1 for each observer, as well. 10 observers = 11x overhead; 20 observers = 21x overhead; etc. This happens, of course on each individual bind! Our asset is meant to work well on mobile; such a drop in performance is not acceptable!
    The ugly: 1 source, 10 observers. In the same frame, the values of observers 2, 4 and 8 change. Which one takes precedence? What should the bind do? (additional overhead in the form of priorities is not an option)


    The alternative: Place your source on a script that is universally accessible and work with it directly. We've designed EzDataManager to do just that (and much more), but you can easily have global variables in an easily accessible location.
    And if you absolutely MUST bind 2-way (in our expericence, we've only encountered this need when working with input-fields), you can create a second bind pointing the other way around.

    2. Binding on Collections
    How it works now: You can bind on collection items, with some limitations, as described in my post above. You can do this on local or global binds, it doesn't matter, as long as your collection class inherits from UnityEngine.Object.

    If you want to bind on collection items, you will have to do it through code, for the time being. You can check out the manual to see the available methods for adding source/observers to binds.
     
  40. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    Thank you @sharkyro that works beautifully - and since i already needed specialized code to spawn/Instantiate each of the items from the SO list of items it fits really nicely into the system. I was not aware of the LocalBinds improvements (had to update EZBind)

    One really happy EZBind customer here!!
     
    sharkyro likes this.
  41. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    501
    Just wanted to stop by to say that I finally implemented EZBind in one of my projects and it's really great - I'll continue to use it for all project from now on - Great job, Thanks!
     
    sharkyro likes this.
  42. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    @sharkyro I think i found a bug with EzBind (i'm using version 2.2) with Unity 2017.4 LTS

    Repro:
    - create a prefab with a local binds component
    - select the prefab asset in the project view
    - add new bind in the local binds component
    - close unity
    - reopen unity
    - select the prefab asset in the project view
    - notice your new bind on the local binds component did not get saved

    It seems like changes to the component when modified on the prefab asset are not automatically saving their data to the prefab asset - BUT if you drag the prefab into the scene, make the changes and the hit the Apply button to save the prefab changes back to the asset it does save the data. I have validated this by watching whats in the prefab asset file when using text format asset files and can clearly see this happening without shutting unity down.

    Thanks for listening and hopefully you can fix this bug!
     
  43. hottabych

    hottabych

    Joined:
    Apr 18, 2015
    Posts:
    107
    Let's say I associate an int number of coins with a UI Text coin counter. I bind them. Okay, I collect coins, they are displayed on the counter.
    But what if I want coin number change not to be instantly displayed, but lerp it using a coroutine, e.g. on collecting a pack of 100 coins, the counter scrolls from 0 to 100 (for 2 seconds).
    Does it make Ez Bind useless?
     
  44. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    44
    @hottabych - You could write a generic behavior that does the lerping - and then have ezbind to set the "next value" on the Lerping behavior and that behavior slowly lerps its UI text value on each update trying to keep the UI in-sync with the value of its "next value" that ezbind is setting. Cheers
     
    hottabych likes this.
  45. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    183
    Is it possible to do some cross scene data binding with EZ bind.

    For example, setup a source on the EZBind then use a EZBindObserver on a component in another scene to link up to that source?

    Thanks in advance!
     
  46. artfabrique

    artfabrique

    Joined:
    Nov 8, 2012
    Posts:
    25
    How to trigger Bolt CustomEvent on Flow from EZ Bind? I want to trigger an event when a certain value changes.
     
  47. artfabrique

    artfabrique

    Joined:
    Nov 8, 2012
    Posts:
    25
    When I try to bind Color variable from Bolt Variables to Unity UI Image Color I get an error:

     
  48. artfabrique

    artfabrique

    Joined:
    Nov 8, 2012
    Posts:
    25
  49. SpyrosUn

    SpyrosUn

    Joined:
    Nov 20, 2016
    Posts:
    144
    Hi there, based on what I am reading looks like this will not be possible to achieve with EZ Bind, but since this is core to my data I am wondering whether I can do it somehow. My easy save 3 savegame data is loaded in a structure which I call GameData. This is defined like :

    [Serializable]
    public class GameData {
    // This is simply the name of the file where the player data is stored
    public string pd = "GameData.es3";
    public Player player;
    }

    And Player is like :

    [Serializable]
    public class Player {
    public int level;
    public int xp;
    }

    I want to be able to use the player xp as source (GameData.Player.xp). I am only able to reach to Player through the data bind, but I can't get a level deeper to reach xp, which is a really big problem for the way my data classes are designed.

    This kinda looks to me like a very casual scenario to data binding frameworks though, so I am wondering whether I am missing something. Is there a way to do that ?

    I do have a way of doing this by setting GameData as a MonoBehavior class and lose the containing manager gameobject. It does work this way, but it would be nice if I could go deeper into variables through object references.

    Thanks !
     
    Last edited: Jan 8, 2019
  50. JuanJSAR

    JuanJSAR

    Joined:
    Feb 21, 2014
    Posts:
    47
    As it is no longer available for purchase, could someone share it?