Search Unity

NData - MVVM framework for NGUI

Discussion in 'Assets and Asset Store' started by Art Of Bytes, Mar 15, 2012.

  1. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    New NData update is now available in Asset Store!
    http://u3d.as/content/art-of-bytes/ndata-for-ngui/2KC

    Release Notes:
    • LastItemSelected, FirstItemSelected properties support in collections
    • AOT compilation issues fix
    • Physics colliders affected by visibility binding
    • Overridable sprite name creation in sprite binding
    • Overridable value applier in TextBinding
    • Initial UITable items’ visibility fix
     
  2. pmws

    pmws

    Joined:
    Sep 18, 2012
    Posts:
    7
    Hey,

    im getting this: (Filename: /Applications/buildAgent/work/d9c061b1c154f5ae/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)

    NguiTextBinding.UpdateBinding - context is null when i am trying to compile a Project with NDATA on iOS 5.11. Any Ideas?

    Runs fine in the editor and on android..

    Thanks!
     
    Last edited: Sep 18, 2012
  3. pmws

    pmws

    Joined:
    Sep 18, 2012
    Posts:
    7
    Hey,

    forget about my last post. Hadn't slept for 40 hours.
    However, I still have trouble compiling Projects using NDATA for ios. Even the DemoScene that comes with ndata wont work.

    ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) System.Threading.Interlocked:CompareExchange (EZData.NotifyPropertyChanged,EZData.NotifyPropertyChanged,EZData.NotifyPropertyChanged)' while running with --aot-only.

    at EZData.Property.add_OnChange (EZData.NotifyPropertyChanged value) [0x00000] in <filename unknown>:0
    at NguiBooleanBinding.UpdateBinding () [0x00000] in <filename unknown>:0
    at NguiBinding.Start () [0x00000] in <filename unknown>:0

    (Filename: Line: -1)

    and so on...

    Any ideas? Im using the latest NDATA , Unity 3.55 and xcode 4.41. SDK version is 5.11

    thanks!
     
    Last edited: Sep 19, 2012
  4. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi pmws,

    If a project with NData works fine in editor and in android builds, but fails to work on iOS device, it's most likely the Player Settings. We're currently using the following settings in our projects (highlighted settings are critical for correct functioning on iOS):
    .

    We were checking demo project from the latest NData version recently and with those settings it worked on iPhone as expected.
    Also if you are running in a simulator, then SDK Version should be "iOS Simulator latest".
     
  5. pmws

    pmws

    Joined:
    Sep 18, 2012
    Posts:
    7
    Thanks for the quick response. Looks like setting Strip Call Optimization to fast, did the trick. Thanks so much. I m going to try on my real project now...
     
  6. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Great to hear that!
    Please, let us know if you have any other questions.

    Good luck with your project!
     
  7. iRetrograde

    iRetrograde

    Joined:
    Oct 13, 2011
    Posts:
    93
    How's it going guys?

    I have a question in regards to usage of NData/NGUI within my game.

    I have several menu pages and I'm one to trim down my code as much as possible but I'm also a freak about making sure that everything works properly. So, I got a question about when I call View.SetContext( myEzDataContextObj ).

    Will this cause the visual representation of my data in my menus to disappear if it can't find that context property anymore? Perhaps someone can link me to answers if applicable.

    I.E. If I'm IN my Game Session Page and I go to my Facebook Friend Invite Page and I switch contexts in between.

    1. Will the NGUI components in the Game Session Page react to the data context having changed? (will they disappear/mess up?)
    2. When I reload the context data for Game Session Page are there ways for me to minimize the impact of switching contexts if any if the data has not changed?
    3. Are there large overheads regarding this and should I just keep switching contexts to a minimum?
     
  8. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi,

    Current implementation of view doesn't react to context change and assumes that it's only set on view creation. However, it's possible to do the trick with something like that after setting the new context:

    Code (csharp):
    1.  
    2. foreach (NguiBinding b in View.gameObject.GetComponentsInChildren<NguiBinding>())
    3.    b.UpdateBinding();
    4.  
    In that case UI within this view will change its state according to the new context. If some properties are missing in new context, most bindings will act like "default" value was received (like getting false in Boolean bindings, or empty strings in text bindings). Anyways, such context switching is not recommended, it may be OK for small UIs and if it doesn't make a difference in your particular case, you can go with it, but for larger UIs it may cause spikes in performance.

    Another way of solving your problem would be having multiple views. From your description, it can be assumed, that you have dedicated context for each page, in that case you can have separate view for each page too, each assigned its own context, then you won't need to switch. In order to do that, find the place where your View is defined and add the pack of page specific views next to it. Then add root context to every page root object in UI objects' hierarchy and specify it in it's corresponding view field.

    If something is still not clear, please let us know.
     
  9. iRetrograde

    iRetrograde

    Joined:
    Oct 13, 2011
    Posts:
    93
    Hey AoB,

    I got everything to work more or less (after quite a while of digging through my code and how things were being loaded) and it was boiling down to adding an UIRepositionable component on that UITable to get it to work. Not sure if _uiRepositionable is supposed to be created at runtime and the Awake() function registers it, or if your documentation needs a little update.

    Having said that, I'm still having some issues. Table is getting populated but items don't seem to be respecting their UITable paddings or positions....

    This is a screenshot of what the table initializes to (please read further):



    Once I noticed this, i then selected an object, diabled/enabled a random UISprite in the table and the objects refreshed, to weird positions that don't seem anything related to the padding that I had entered in UITable.



    If you could maybe point me towards the right direction, that would be great. I'm currently using 1.0.7. I quite like the framework but I'm really hoping to figure out the rest of these caveats soon since I'm not yet very familiar with NGUI or NData. Cheers!
     
  10. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    We're trying to reproduce this behavior, and see what could go wrong, could you meanwhile confirm that it doesn't make a difference if you set Padding.Y to 75 or to 0. From the picture you attached, it looks like vertical intervals between items were definitely non-zero and seem to be about the value you specified, for those values you specify in Padding field are table items' padding, not the whole table content padding.

    Also your table is positioned at the center of a screen with its pivot, if your table items are of a fixed width, you can move the table to the left, so items will be positioned within a screen. Anyways, if there's still be problems, it also would be helpful to take a look at item template root object (Table_PlayFriends -> 0 for example).
     
  11. iRetrograde

    iRetrograde

    Joined:
    Oct 13, 2011
    Posts:
    93
    Hey AoB,

    I figured out what was going wrong after checking your site and seeing that version of NGuiItemSourceBinding. Pressing on each item of the list wasn't working either and figured I'd check the site for info and saw it there. The old code instead of calling UITable to get repositioned, it was calling reposition on the UIRepositionable component. I must have skipped a few files when updating for some reason...

    The vertical offset was definitely being caused by the 75 I had in there. I don't remember where the X offset problem was coming from but it's gone after doing a bunch of other work. Thanks for the help, gonna try to get the rest working.

    Cheers!
     
  12. gwaredd

    gwaredd

    Joined:
    Oct 22, 2012
    Posts:
    8
    Hi,

    I am having a similar issue to pwms, the game works fine on all platforms except iOS. Whenever I load a scene with NData bindings either the game crashes with the "Attempting to JIT compile" error (below) or the bindings don't work.

    I have gone through and verified the build settings in the player are set as is suggested in this thread (Script call optimisation set to Fas but no Exceptions). Setting this causes it to crash, setting it to "Safe but Slow" is just does not work. This is the same for the NData demo as well as my own code.

    Any ideas? FYI - I'm using the Unity 4 beta, iphone 4S, iOS 6.


    Unhandled Exception: System.ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) System.Threading.Interlocked:CompareExchange (EZData.NotifyPropertyChanged,EZData.NotifyPropertyChanged,EZData.NotifyPropertyChanged)' while running with --aot-only.

    at EZData.Property.add_OnChange (EZData.NotifyPropertyChanged value) [0x00000] in <filename unknown>:0
    at NguiTextMultiBinding.UpdateBinding () [0x00000] in <filename unknown>:0
    at NguiMultiBinding.Start () [0x00000] in <filename unknown>:0
    at NguiTextMultiBinding.Start () [0x00000] in <filename unknown>:0
     
  13. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi gwaredd,

    We are investigating the issues with Unity 4 and will let you know as soon as we have the new solutions.
    Be sure, we will support all features of the new Unity and iOS 6, because we have our own iOS projects with NData and that is our best interest to have it working.
     
  14. gwaredd

    gwaredd

    Joined:
    Oct 22, 2012
    Posts:
    8
    I have a workaround for now but I look forward to the official fix :)
     
  15. adam718

    adam718

    Joined:
    Mar 11, 2012
    Posts:
    58
    Hi!
    Thank you for your great work on NGUI.
    I also love to use NGUI and you make NGUI user use it more easily.
    Binding was what I experienced in Windows WPF for the first and I thought it was good idea.

    Yesterday i made list control but unfortunately it didn't work.
    I found reason that when I used UIGrid as item container it didn't work but UITable worked.
    I want to know why? and if so, could you list Bindingable UI Components?

    PS. I can't also get in http://tools.artofbytes.com/ndata/tutorials/simple-tutorial in any browser....

    Thank you,
    Regards,
    Adam.
     
    Last edited: Nov 13, 2012
  16. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi Adam!

    Thank you for using NData and for you feedback!

    Out website is accessible now.
    We have submitted the fixes today, so update will be available soon - after AssetStore team approve

    Cheers
     
  17. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95
    Hi gwaredd, what was your work-around for this issue?

    Hi AOB, have you a fix for nData, Unity4 and iOS?

    Thanks
     
  18. moonrabbit

    moonrabbit

    Joined:
    Sep 14, 2012
    Posts:
    2
    Hi AOB, Does 1.0.8 (Nov 15th) version fix the iOS 4 issue? I updated it to the version and still getting JIT compiling issue.
     
  19. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi guys,
    We are working on Unity 4 fixes, and they will be available soon!
     
  20. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Great! I'd like to ask you again to consider providing the source in the package as well. If you end up using NData it's mission critical to your app, and not having the source in a worst case situation is a bit of a risk. Most packages on the Asset Store are source code based, and in fact I won't buy anymore that don't provide the source for exactly that reason.

    ty!
     
  21. gwaredd

    gwaredd

    Joined:
    Oct 22, 2012
    Posts:
    8
    I decompiled the dll into source form and dropped that into the project ;) (http://www.reflector.net/)
     
  22. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi guys,
    Don't worry, we'll include the source code to the next update ;)
     
  23. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95
    Thanks, saves me mucking about with XCode settings.

    Looks like AOB is on the case. I will also wait for the official fix.

    Ta
     
  24. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95
    Hi, I am trying to implement the NguiPopupListSourceBinding without success. Specifically I don't know what Display Value Path does and also there must be something specific regarding path which I am not doing.

    Is there an example implementation or some documentation regarding binding popup lists?

    I am adding the binding script to the same object as the NGUI popup list script, but the list then disappears. Similarly I get the following error

    Failed to call function OnSelectionChange of class NguiPopupListSourceBinding
    Calling function OnSelectionChange with no parameters but the function requires 1.

    Thanks, Peter
     
  25. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi Peter!

    We've added Popup List Binding Tutorial to our website.
    Hopefully it will help.

    If you have any further questions, we'll be happy to answer!

    Cheers,
     
  26. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95
    Excellent tutorial. Thank you for your quick response. I have become a great fan of nData for NGUI. While I have found the learning curve quite steep (have not used this programming model previously, and not C# at this context level), I have managed to create quite complex interfaces utilising the nData MVVM pattern.

    Also, the quality of your tutorials/examples continues to improve. This one was well structured, succinct and well explained.

    I eagerly await the release of the next version of nData with the iOS/Unity4 fix so that I can give a glowing review on the asset site.

    Thanks, Peter
     
  27. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi Peter!

    Thank you very much!
    We love MVVM are really happy to hear that you like the approach too!

    We are trying to improve and can do this thanks to your and other guys feedback, so if you have any other comments or questions, we would really appreciate them!

    Cheers and good luck with your projects!
     
  28. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Thanks AOB for the update and the new source.
    Makes me feel a little more comfortable!

    It seems to work, but now I have another 3rd party code failing on an AOT which did not happen before.
    What exactly did you do in your source to get rid of this?

    ty!
     
  29. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95
    Thanks AOB, this update is working fine under Unity4/iOS (iPad). Excellent!
    Cheers, Peter
     
  30. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95
    Hi AOB,

    As mentioned previously, I have become a big fan of nData and the MVVM for NGUI.

    As a developer of educational programs, the interface is a major component of development, more so than in game development. nData for NGUI offers enhances development by allowing the logical code to separated from the interface.

    I have also mentioned that the learning curve is quite steep. More experienced C# programmers might grasp the subtleties more quickly, but I am guessing there are a number of programmers like myself that would have benefited from a quick "how to" or cheat sheet. The sorts of things for this "how to" sheet would include specific examples. My suggested structure would go like this:

    1) Properties: How to change a variable with a binding (you do this well already). Show the bi-directional nature of some bindings. Give explicit examples for bool, text, and numeric variables bindings

    2) Options. List the options for bindings (e.g. the visibility binding with its reference variable)

    3) Functions. Show how to call a function inside the main context via a binding. Show how to link variables from this function to data outside the context (i.e. in the main body of the code). (I create a context property that represents the main class and use this to pass the results out of context to the main code, but I am not sure this is the correct way to do this?)

    4) Context. Explain the relationship of Context to the main body of the code and how to pass data back and forth

    5) Collections. I had not used these before. As an essential component some concrete examples on the "how to" sheet would help others. Specifically how to use GetItem, SelectedItem, SelectedItemIndex, etc to access data. How to collections equate to arrays.

    6) What are the efficient ways to program using nData, i.e. what are optimal techniques and which are not advised.

    Specific things I have tried to do includes nested collections. Is this possible (I haven't succeeded yet)?

    7) Show how and when to make separate EZData Context classes. Show how to use these to efficiently organise and access data.

    I prefer to organise as much of the context data outside the main context as possible, having it call other classes. Is this an efficient or inefficient process from nData point of view?

    Also, when using the popuplistbinding, I wanted to update a property in context with the selected item from the popup list. I wasn't sure how to do this. OnClick is no good as it is triggered before the item is selected. So I modified the OnClick binding to make a new binding that uses OnSelectionChange() instead of OnClick. Is this sort of thing advisable or problematic (works fine by the way).

    Anyway, just some thoughts to help others see the benefits of the nData MVVM model.

    Regards, Peter
     
  31. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    2sonicviz:
    According to http://docs.unity3d.com/Documentation/Manual/TroubleShooting.html:
    The major problem is that, the thing responsible for detection of all existing types during the compilation doesn't seem to work well with generic types in some cases, not only "methods that are used only via reflection or from native code", but also other cases like deep nested function calls with generic arguments. And the worst part - it's quite unpredictable what portion of code will cause the problem. So, general recommendation is to keep code straightforward and simple. And in case of a problem with some specific type, workaround provided in unity troubleshooter seems to work too.
     
  32. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi Peter!

    Thank you very much for your feedback and the tutorial structure proposal! We will add new tutorials step-by-step according to it!
    Any further comments and improvements suggestions are very welcome!

    Cheers,
    Yours ArtOfBytes
     
  33. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95
    Hi AOB,

    1) Thoughts on how to detect a combination keypress, e.g. Ctrl F5?. Currently I have to add an OnGUI to read the event.
    2) Proper way to capture a selection from a popup list as the selection is made (my 'hack' was to change the OnClickBinding so that it detected OnSelectionChange instead.
    3) Proper way to access an external function (i.e. outside of the Context) from a function in the Context. Case in example. I have an increment and decrement buttons bound to separate functions in the Context. These separate functions both call a single external function, passing a parameter. This external function updates a property in Context as well as other duties. Currently I have a property in context that represents the ViewModel (ie ThisViewModel) and I call the external function from within the Context by ThisViewModel.UpdateIncrement(); Works, but not sure the correct way to do this.

    With thanks, Peter
     
  34. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi Peter,

    1) It could be something like that:
    Code (csharp):
    1.  
    2. void Update()
    3. {
    4.   if (Input.GetKeyDown(KeyCode.F5)  (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)))
    5.   {
    6.     Debug.Log("Ctrl-F5 detected");
    7.   }
    8. }
    9.  
    2) If you need to receive an event when the selection is changed, then the best way is to add a handler to the Collection.OnSelectionChange event. Like that (according to the popup tutorial):
    Code (csharp):
    1.  
    2. public class ViewModel : MonoBehaviour
    3. {
    4.   public NguiRootContext View;
    5.   public Ui Context;
    6.  
    7.   void Awake()
    8.   {
    9.     ....
    10.     Context.SampleColors.OnSelectionChange += HandleSelectionChange;
    11.     View.SetContext(Context);
    12.   }
    13.  
    14.   private void HandleSelectionChange()
    15.   {
    16.     Debug.Log("Selection was changed to " + Context.SampleColors.SelectedItem.Name);
    17.   }
    18. }
    19.  
    it however won't be invoked when no selection change occurs, like when user drops down the menu and then clicks the same item that is already selected. If you need to detect an event in this case too, then you'll have to deal with control itself.

    3) the solution you described is ok. Context is a part of ViewModel and it's ok for it to know about the same things ViewModel knows if that's required for your task. The way how exactly it accesses the ViewModel is up to you. You can, for example, modify the constructor of Context to receive via arguments all it needs to know about external world (including ViewModel). So it could be something like Context = new Ui(this); and then whatever you need to do with the ViewModel inside of that constructor.

    Please, let us know if anything else is unclear.
    Good luck.
     
  35. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95
    Thanks AOB, this is helpful and reminds me to use the different scopes of nData, NGUI and Unity itself to achieve complex outcomes.

    As with all tools, the more I use nData with NGUI, the more efficient interface construction becomes. I love being able to construct the interface, give it its latent functionality (e.g text fields, passwords, buttons, controls) and then simply hook it into the logic and functionality in the model (via ViewModel). Ideal for complex simulations.

    Keep up the good work and thanks for your responses.

    Regards, Peter
     
  36. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi Peter!

    Thank you for your valuable feedback and comments!

    Yours ArtOfBytes
     
  37. adam718

    adam718

    Joined:
    Mar 11, 2012
    Posts:
    58
    Hi!
    I attached NGUICheckedBinding to check control.
    I also assigned OnChecked(bool) to UICheckBox component.
    I try to get value from binding in OnChecked() but even if checkbox is checked, binding value is not changed.
    How can I get changed value when checkbox is checked / unchecked.

    Thank you.
     
  38. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198

    Hi Adam,

    Using NGUICheckedBinding assumes that you have a data context with bool property and this property is specified in the binding Path field. In this case you can add a handler to the OnChange event of this property and access the updated value of the property there. Key moment in that solution is that you don't handle any events in control, but in data bound to it.

    However, in the case you described, it looks like you may need to know the state of the control, rather then a state of a data. argument of OnChecked handler is the new state of a checkbox, and also UICheckBox has a property isChecked, it can be accessed anywhere withing the gameobject like: Debug.Log("Checked: " + ((UICheckBox)GetComponent<UICheckBox>()).isChecked);

    Changes in controls happen first, at this moment you get OnChecked event that you assigned directly to the control, no change to bound data has occurred at this point. Then binding detects a change and changes the bound property. Property, in turn, triggers OnChange event, in this event new value of property is already available. Accessing something in data context (ViewModel) from the controls and their control-specific events (View) is not a good idea. Ideally ViewModel and View interact only via bindings.

    General recommendation is to not mix the events and data from different layers of logic. If you operate on the level of controls and have OnChecked or similar handlers, it usually means that you are interested in this specific control behavior and then it's natural to read the state directly from control. On the other hand, if your logic resides in data context, and you don't care how exactly data property was changed, then it means that you should react to data change events and don't interact with controls at all, but only have a binding that will automatically keep the data and the control in sync.

    There's also a checkbox tutorial that you may find interesting: http://tools.artofbytes.com/ndata/tutorials/checkbox-tutorial

    If anything is still unclear, please let us know.
    Good luck.
     
  39. soulis6

    soulis6

    Joined:
    Apr 21, 2011
    Posts:
    22
    I have a question similar to Launchpad's:

    I'm using itemsourcebinding to create a list of objects, which works great, but I want something inside that created prefab to access data in the root ViewModel. So, sort of the reverse of your example in item source binding, where you specify Item.SelectedItem.Name. Is there a way to access the root context from within a collection?
     
  40. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi,

    Currently it's not possible. Item context overrides root context, so within the list items you can only bind to the item context. However, it seems logical to introduce additional field to base binding class that will define a scope where properties should be looked for. Then it'll be possible to specify whether binding path should be resolved in the local context (like it is done now) or in the global context, so you can access properties outside the items. What do you think? We'll see if this change goes smooth, and most likely it will be available in the next update.

    Also, if you need it urgent, you can look at FindRootContext method in NguiUtils.cs and how it's called in NguiBinding.cs. That's where the context is selected, so you should be able to tweak it there, while we're working on an update.
     
  41. soulis6

    soulis6

    Joined:
    Apr 21, 2011
    Posts:
    22
    That sounds good, I think it'd be really helpful.

    The tricky part is I don't' want to change it for all of the stuff in the item template, just a couple things. I tried editing the FindRootContext to change the context for a few specific bindings, but it didn't' seem to make a difference, still acts like it can't find the path for those.
     
  42. dsfds

    dsfds

    Joined:
    Aug 19, 2012
    Posts:
    16
    Could you give a few more examples in the package?
    Also could you explain like how to do positioning in viewmodel? for a button?
    Eg: If i enter 1 in a input box, the button will move up by 1 pixel automatically? where would you put these kind of code?
     
  43. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Greetings!

    There are some tutorials at http://tools.artofbytes.com/ndata/tutorials, they are mostly demonstrating the alternative way of how to do things from original NGUI scenes. And since we don't re-distribute the NGUI package they are not included with NData, but you should be able to follow them on site without much problem.

    As for positioning of controls based on data viewmodel - in general it's not a good idea. Layout of UI controls is a part of view and should exist completely there. However if you still need to position something in UI based on data - there's a "local position binding" in the NData package. You can add it to the game object you want to move around and enter a path to the Vector3 or Vector2 property in its Path field. This way the whole position of the object will be bound to the vector property.

    If you want something exactly like in your example, you can freely add your own custom bindings, one for position.y only would look like:
    Code (csharp):
    1.  
    2. public class LocalPositionYBinding : NguiNumericBinding
    3. {
    4.     protected override void ApplyNewValue(double val)
    5.     {
    6.         var pos = transform.localPosition;
    7.         pos.y = (float)val;
    8.         transform.localPosition = pos;
    9.     }
    10. }
    11.  
    then, if you bind position to the same numeric property that you have your input field bound to, it'll work like you described.

    Good luck and have fun!
     
  44. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi there!

    We are happy to announce the new big NData update, that includes the following features:

    - Predefined list items support in item source bindings (to make list with predefined number of fully custom items, without item template)
    - Vector2 and Texture2D properties supported in vector bindings in addition to Vector3
    - Object references added in scene validation tool messages for quick navigation to errors
    - Automatic sprites resize to pixel perfect state in sprite binding
    - More alignments supported in texture binding
    - Some basic math transforms supported in position and scale bindings
    - Localization key binding
    - Context scope modifiers supported in bindings' paths
    - Audible binding
     
  45. Rhyo

    Rhyo

    Joined:
    Jan 11, 2013
    Posts:
    2
    Hi,

    I recently purchased NData and finding it quite useful. Is it possible to define NData properties and collections etc in multiple classes and combine them into a single context. I want a single global context but I want to be able to define properties etc for that global context in multiple classes (and .cs files).

    So by way of an example, can I do the following (or similar) and how do I do it.

    Code (csharp):
    1.  
    2. public class myFirstContext : EZData.Context
    3. {
    4.     Property myFloat
    5.     Property myString
    6. }
    7.  
    8. public class mySecondContext : EZData.Context
    9. {
    10.     Property myInteger
    11.     Collection myCollection
    12.  
    13.     static void OnClickEvent()
    14.     {
    15.         // do some stuff to handle event
    16.     }
    17. }
    18.  
    19. public class myViewModel
    20. {
    21.     public NguiRootContext View;
    22.     public static my???? Context;  // What should this be?
    23.  
    24.     void Awake()
    25.     {
    26.         Context = new ????;  // What should this be?
    27.         View.SetContext(Context);
    28.     }
    29. }
    30.  
    31. // This works fine, since Context is static
    32. // I include it for completeness
    33. public class myLogic()
    34. {
    35.     void someFunction()
    36.     {
    37.         myViewModel.Context.myCollection.Add(new myItem);
    38.     }
    39. }
    40.  
    Many thanks.


    EDIT:
    It would also be nice if I could do the following
    Code (csharp):
    1.  
    2. public class myLogic()
    3. {
    4.     void someFunction()
    5.     {
    6.         // note the extra reference to 'mySecondContext'
    7.         myViewModel.Context.mySecondContext.myCollection.Add(new myItem);
    8.     }
    9. }
    10.  
     
    Last edited: Jan 11, 2013
  46. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi, Rhyo

    If you need something like sub-contexts, it could look like this:

    Code (csharp):
    1.  
    2. public class myFirstContext : EZData.Context
    3. {
    4.     Property myFloat
    5.     Property myString
    6. }
    7.  
    8. public class mySecondContext : EZData.Context
    9. {
    10.     Property myInteger
    11.     Collection myCollection
    12.  
    13.     static void OnClickEvent()
    14.     {
    15.         // do some stuff to handle event
    16.     }
    17. }
    18.  
    19. public class myRootContext : EZData.Context
    20. {
    21.     public myFirstContext First { get; private set; }
    22.     public mySecondContext Second { get; private set; }
    23.  
    24.     public myRootContext()
    25.     {
    26.         First = new myFirstContext();
    27.         Second = new mySecondContext();
    28.     }
    29. }
    30.  
    31. public class myViewModel
    32. {
    33.     public NguiRootContext View;
    34.     public static myRootContext Context;
    35.  
    36.     void Awake()
    37.     {
    38.         Context = new myRootContext();
    39.         View.SetContext(Context);
    40.     }
    41. }
    42.  
    43. // This works fine, since Context is static
    44. // I include it for completeness
    45. public class myLogic
    46. {
    47.     void someFunction()
    48.     {
    49.         myViewModel.Context.Second.myCollection.Add(new myItem);
    50.     }
    51. }
    52.  
    this way, your bindings' paths will look like "First.myFloat", "First.myString", "Second.myInteger" or "Second.myCollection"
    Depth of the sub-contexts hierarchy can be arbitrary, so feel free to design your sub-contexts structure as you need for your project.

    Also, in case you want all of the properties exist in a single context, without sub-contexts hierarchy, but still want to define parts of it in different files, you could use partial classes.

    If anything else is still unclear, please let us know. Good luck!
     
  47. Rhyo

    Rhyo

    Joined:
    Jan 11, 2013
    Posts:
    2
    Thanks for speedy and excellent answer. Both methods you outlined work very well, thanks again :)
     
  48. scritchy

    scritchy

    Joined:
    Dec 30, 2010
    Posts:
    94
    Hi. was this update meant to resolve the "ExecutionEngineException"?

    I'm still getting it in our project, with the most up to date package on the asset store, on iOS.


     
  49. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    It fixed it for me. Did you make sure to remove any dll's from the old version? New one is source, which seemed to solve some of the issues with external dll's compiled in VS.(as one possible cause for it)
     
  50. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi, scritchy.

    iOS exceptions were fixed since Version 1.0.9 (Core functionality source code is included to distribution). Since then, we have a number of reports, that it helped. As sonicviz correctly suggests, please, make sure you don't have any dll-s in NData folder, since 1.0.9 it comes in source code, and the files from older versions could be a possible issue.

    If the problem is still there, more details on error would be helpful in investigation.