Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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
    Hi all, it's been a while, sorry for the delay. Now, to the questions.


    It should work absolutely the same way for int, and in fact binding you provided works well. See the attached modification of HealthBar example. btw Log call in Foo setter is not supposed to be called when value is set from view.
     

    Attached Files:

  2. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    There was a fix for this MissingReferenceException recently, are you using the latest NData version? Just in case, the fix is just try/catch around context update. to just ignore the outdated references and then clean them up.
     
  3. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    But then, how to decide which one of the templates should be instantiated? You can always modify the original NguiListItemTemplate as you need it in your project and select appropriate template based on your specific logic. Would that be reusable in other applications? What would be the typical use-case?
     
  4. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Thank you very much for the hint. GetGetMethod workaround is already apllied, will be available with the next update.
     
  5. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    "ActionsList.SelectedItem.Action.testString" Path seems to be fine, the only restrictions are that Action class has to be inherited from EZData.Context and both Action and testString have to be public properties, not the fields. If that's not the case, we could take a look at the test scene with the wrong behavior.
     
  6. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    It is hard to say what's wrong, without more details. Are the "Accept request" and "Reject request" windows created dynamically, or they exist in the same hierarchy as "Frient request"? Maybe you could provide the test scene with this setup, or at least scene hierarchy screenshot with this described windows?
     
  7. concave

    concave

    Joined:
    Aug 28, 2012
    Posts:
    49
    does someone else experienced massiv loading time on startup using ndata... splash screen for about 10sec...
     
  8. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    I get those loading times when building as development build. Try turning that off and see if it improves things i you have it on.
     
  9. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95
    Hi,
    I have a brand new project, Unity 4.2.2, NGUI 3.0.3e, nDATA 1.0.17

    I have added a text file to Assets called smcs.rsp with the line -define:NGUI_3

    Without the smcs.rsp file I get 2 errors, the first being:

    Assets/NData/NGUI/NData/Advanced/NguiFadeVisibilityBinding.cs(38,38): error CS0246: The type or namespace name `UICheckbox' could not be found. Are you missing a using directive or an assembly reference?

    With the smcs.rsp file I get 14 errors, the first being:
    Assets/NData/NGUI/NData/NguiSpriteBinding.cs(22,48): error CS0122: `UIAtlas.Sprite' is inaccessible due to its protection level

    What am I missing? This is reproducible on both Mac and Win platforms?

    Thanks, Peter
     
  10. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,457
    Hi ArtOfBytes,

    As a long time user of NDATA, I've been a happy customer and you guys have done a remarkable job to allow NGUI to do data binding.

    Recently there have been many improvements in NGUI and the coming of Unity's new GUI system which is based on NGUI.
    The biggest change in NGUI 3.0 has been a revamped event system which allows for greater flexibility and power.

    On the asset store, I noticed that Daikon Forge Gui (www.daikonforge.com/dfgui/) has a very unique way of doing DataBinding using their event system that does not require plumbing code. This approach is much more convenient and lessen the code base.

    Question: Would you consider in a future update of NDATA to leverage the new NGUI event system to do do databinding more like Daikon Forge so that we don't need the plumbing code that is currently required.

    Cheers.
     
  11. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    That define doesn't work for me either Launchpad. So i just added a define in one of my files. #DEFINE NGUI_3. And that worked fine.
     
  12. Nezabyte

    Nezabyte

    Joined:
    Aug 21, 2012
    Posts:
    110
    awhile back I mentioned about having to do a workaround to use integer number bindings to avoid weird results for incrementing/decrementing. turns out another weird issue cropped up: the possibility of the text binding showing a float value instead of integer. no idea why this is happening.

    at the minimum I think there's a formatting setting I can use to force to only display the numbers before the decimal point?

    $damageInt.jpg
     
  13. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369


    One use case would be I have a model that takes in 4 types of Contexts

    This is the class hierarchy
    SliderItem : BaseUIItem : Context
    ButtonItem : BaseUIItem : Context
    RadioButtonItem : BaseUIItem : Context

    Then I have an EZData.Collection<BaseUIItem> collection

    then I can add collection.Add(new SliderItem) collection.Add(ButtonItem) etc...


    I know it's a hacky way but I've made something that maps EZContext to type of object instantiated.



    Also one other question is with the NguiProjectedPositionBinding can you remove the need for the anchor using this code

    var ss = worldCamera.WorldToViewportPoint(_wsPosition);
    ss = nGUICamera.ViewportToWorldPoint(ss);
    ss.z = 0;
    gameObject.transform.position = ss;

    This would give you the proper UI position.

    Sorry I'm bombarding you with questions but your system has become quite an integral part of my codebase:) It's a great framework one of the best I've used.
     
    Last edited: Nov 1, 2013
  14. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,457
    As a long time user of NDATA, I have to say that's you guys have done an amazing job at bringing Databinding to NGUI.

    Recently NGUI 3.0 has revamped its event system quite drastically and version "C" now supports anonymous delegates.
    It is also known that Unity's new GUI is based on NGUI so it's going to be very nice for NGUI users.

    Even though NGUI is really a very good GUI system for a long time, there are increasingly more GUI options on the asset store. One of the best one that's come along is I noticed on the asset store Daikon Forge.

    http://forum.unity3d.com/threads/194561-RELEASED-Daikon-Forge-GUI-Library

    The most interesting part of this GUI is its native support for Databinding natively without writing all of the plumbing code.

    This leads me to wonder if its possible in a future update of NDATA, would it be possible to leverage NGUI's new event system so that we no longer have to do the plumbing code ?

    Cheers and thanks for all the great work on this project.
     
  15. yustinusadika

    yustinusadika

    Joined:
    Sep 3, 2013
    Posts:
    8
    The "Accept" and "Reject Request window" were fixed but the data inside it is going to be dynamic, based on the request chosen.
    Thanks for your reply anyway, i have found another solution for this rather than forcing to make it worked using this point of view :D
    Love NData :D
     
  16. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95

    Thanks Enzign. That helped me prove that the define macro was indeed working. What I had to do was make the Sprite class in UIAtlas.cs in NGUI public to get around the protection level issue, but all sweet now.
     
  17. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Yep, this was an issue with me here after upgrading. Instead of changing UIAtlas.Sprite to public through, you should change references in NData to use UISpriteData. UIAtlas.Sprite was depreciated for 3.0.
     
  18. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    You can always have custom ItemTemplate class, that does the item switching logic. It'll be game specific, thus not re-usable as a generic solution, but absolutely valid in your project.

    New NguiProjectedPositionBinding is available in the latest update, btw, cheers.
     
  19. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    o_O weird indeed. You can of-course use the format to force its display to int, but it's not supposed to be so. We'll check that.
     
  20. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    There's an update already available on asset store with sprite binding fix. UIAtlas.Sprite is now UISpriteData for NGUI 3.
     
  21. tyshock

    tyshock

    Joined:
    Jun 20, 2013
    Posts:
    6
    ArtOfBytes,

    I am considering a purchase of your product, but I wanted to ask a couple of questions. I've done MVVM in WPF, so i'm sold on that methodology as long as it works.

    My first question involves dynamically loading in prefabricated views at runtime. What I would like to do is have a single VM but have multiple views that could work with that VM. The views would be, for example, a 'tablet ui view', a 'phone ui view' and a 'desktop ui view'. At runtime, I would determine the platform I am running on and instantiate the matching view prefab in my scene. At that point, I would hope that things would 'just work', or at most I would have to invoke a 'bind()' function to initiate binding. Is this easy to do with your framework?

    My other question involves creating my own custom bindings for custom control prefabs. For example, say I have a prefab with a root gameobject and an attached MonoBehaviour of type 'DisplayCardScript'. DisplayCardScript has two properties that I wish to bind, string 'DisplayName' and int 'Quantity'. Is it easy to create a custom MonoBehaviour that would allow NData to properly handle these bindings back to a given VM?

    Thanks in advance for any feedback.
     
    Last edited: Nov 18, 2013
  22. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi,

    you can easily have multiple views, and if you assign the context to the view in Awake (or in start but before bindings scripts start), then the view will resolve all its bindings correctly and it will just work. If actual view instantiation is delayed, you can still force bindings resolution by calling UpdateBinding on bindings' scripts (like it's done in NguiItemDataContext when items are dynamically instantiates via the items source binding).

    Custom bindings and custom controls are a solid part of our own projects, over the time we've re-factored the binding classes hierarchy, so that it's easily extendable, and all bindings that come with NData can be used as a reference.
     
  23. tyshock

    tyshock

    Joined:
    Jun 20, 2013
    Posts:
    6
    Thank you for the reply. You have a new customer! :D
     
  24. scritchy

    scritchy

    Joined:
    Dec 30, 2010
    Posts:
    94
    hi guys. Just wanted to let you know that google has just marked your artofbytes website as filled w/ malware and chrome will no longer let me visit it. maybe somebody has hijacked it?!

    the chrome result page:

    What is the current listing status for artofbytes.com?
    Site is listed as suspicious - visiting this web site may harm your computer.

    Part of this site was listed for suspicious activity 12 time(s) over the past 90 days.

    What happened when Google visited this site?
    Of the 35 pages we tested on the site over the past 90 days, 34 page(s) resulted in malicious software being downloaded and installed without user consent. The last time Google visited this site was on 2013-11-16, and the last time suspicious content was found on this site was on 2013-11-16.
    Malicious software is hosted on 1 domain(s), including rkfhafg.ddns.info/.

    This site was hosted on 1 network(s) including AS36351 (SOFTLAYER).

    Has this site acted as an intermediary resulting in further distribution of malware?
    Over the past 90 days, artofbytes.com appeared to function as an intermediary for the infection of 1 site(s) including u.to/.

    Has this site hosted malware?
    No, this site has not hosted malicious software over the past 90 days.

    How did this happen?
    In some cases, third parties can add malicious code to legitimate sites, which would cause us to show the warning message.

    Next steps:
    Return to the previous page.
    If you are the owner of this web site, you can request a review of your site using Google Webmaster Tools. More information about the review process is available in Google's Webmaster Help Center.
     
  25. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Thanks for the observation, already working on it. Must have been some exploit in the CMS we're using.
     
  26. Nummo

    Nummo

    Joined:
    Apr 1, 2013
    Posts:
    1
    Hi, Art Of Bytes!
    Your guys makes a good job. But if I properly understood a concept of MVVM pattern user actions should processed by model view. Model is domain model or near with it. Am I right that domain model is some instance of EZData.Context? Why domain model should process button click events and so on? Why domain model should handle how to display action results? I think a root context should be view model in MVVM pattern and we should bind on button click event to view model, not for domain model. It's not clear for me.
    Thanks!
     
  27. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    Hi, in fact EZData.Context objects are on the view model layer. We found out that in many cases (for rather simple games mostly) model / viewmodel separation gives too much overhead, therefore examples don't illustrate that separation and have model merged into viewmodel, and it may look that it's MV rather than MVVM, but feel free to add the separate model layer behind this setup, and leave only view model stuff in contexts.
     
  28. Eysar82

    Eysar82

    Joined:
    Jun 21, 2013
    Posts:
    4
    Hi,

    since updated my Android SDK to the latest Version, i assume Ndata don´t work any more. All bindings in NGUI Work on PC and on iOS, but not in Android anymore. Any idea where may the issue occurs?

    Thanks

    Issa
     
  29. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    I'm trying to do a sort of slot-machine looking circular list, where the items that scroll off the bottom should eventually re-appear on the top. I've got a table and scroll view with list item templates for the tiles and a source item binding to the list, but I'm not sure how to get it to scroll in a circle. Any ideas? Should I keep removing the last item from the EZData.Collection and re-adding it to the front, and try to manually adjust the scroll location each time? Or is there an easier way to accomplish this?
     
  30. JRuby

    JRuby

    Joined:
    Sep 3, 2013
    Posts:
    3
    Hi ArtOfBytes,
    Love the asset, bought it a few days ago, getting tons of use out of it.

    Some suggestions for improvements to the Projected Position Binding:
    1: It seems like it only works with Bottom Left anchors. This is OK but the debug text says any corner anchor should work. Please update the text or allow it to work with all corner anchors.
    2: The target camera cannot be specified by path. When working with multiple viewports and multiple UI viewports it would be very nice to be able to bind this and then set it in the viewmodel instead of having to set it in the view.

    Thanks! Great work!
     
  31. JRuby

    JRuby

    Joined:
    Sep 3, 2013
    Posts:
    3
    Ended up writing the camera binding myself:

    NguiCameraBinding.cs
    Code (csharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. [System.Serializable]
    7. public abstract class NguiCameraBinding : NguiBinding
    8. {
    9.     private EZData.Property<Camera> _cameraProperty;
    10.  
    11.     private bool _ignoreChanges = false;
    12.    
    13.     protected override void Unbind()
    14.     {
    15.         base.Unbind();
    16.        
    17.         if (_cameraProperty != null)
    18.             _cameraProperty.OnChange -= OnChange;
    19.  
    20.         _cameraProperty = null;
    21.     }
    22.    
    23.     private void Bind(NguiDataContext context)
    24.     {
    25.         _cameraProperty = context.FindProperty<Camera>(Path, this);
    26.         if (_cameraProperty != null)
    27.         {
    28.             _cameraProperty.OnChange += OnChange;
    29.             return;
    30.         }
    31.     }
    32.    
    33.     protected override void Bind()
    34.     {
    35.         base.Bind();
    36.            
    37.         var context = GetContext(Path);
    38.         if (context == null)
    39.         {
    40.             Debug.LogWarning("NguiCameraBinding.UpdateBinding - context is null");
    41.             return;
    42.         }
    43.        
    44.         Bind(context);
    45.     }
    46.    
    47.     protected void SetCameraValue(Camera val)
    48.     {
    49.         _ignoreChanges = true;
    50.         if (_cameraProperty != null  _cameraProperty.GetValue() != null)
    51.             _cameraProperty.SetValue(val);
    52.         _ignoreChanges = false;
    53.     }
    54.    
    55.     protected Camera GetCameraValue()
    56.     {  
    57.         if (_cameraProperty != null)
    58.         {
    59.             var go = _cameraProperty.GetValue();
    60.             if (go != null)
    61.                 return go;
    62.         }
    63.        
    64.         return null;
    65.     }
    66.    
    67.     protected abstract void ApplyNewValue(Camera val);
    68.    
    69.     protected override void OnChange()
    70.     {
    71.         base.OnChange();
    72.        
    73.         if (_ignoreChanges)
    74.             return;
    75.        
    76.         ApplyNewValue(GetCameraValue());
    77.     }
    78. }
    NguiProjectedCameraBinding.cs
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. [System.Serializable]
    4. [AddComponentMenu("NGUI/NData/Projected Camera Binding")]
    5. [RequireComponent (typeof(NguiProjectedPositionBinding))]
    6. public class NguiProjectedCameraBinding : NguiCameraBinding
    7. {
    8.     private Camera _targetCamera;
    9.  
    10.     public override void Start()
    11.     {
    12.         base.Start();
    13.     }
    14.    
    15.     protected override void ApplyNewValue(Camera value)
    16.     {
    17.         _targetCamera = value;
    18.         LateUpdate();
    19.     }
    20.    
    21.     void LateUpdate()
    22.     {
    23.         GetComponent<NguiProjectedPositionBinding>().targetCamera = _targetCamera;
    24.     }
    25. }
    26.  
    this adds the desired functionality to the projected position binding
     
  32. Pythagoras

    Pythagoras

    Joined:
    Aug 9, 2013
    Posts:
    8
    Greetings,

    I understand that list items that are added as templates with Items source binding have a context with local scope.
    But what if my list items are clickable buttons to which I want to attach an OnClick binding that would call a command in another context ?
     
  33. Pythagoras

    Pythagoras

    Joined:
    Aug 9, 2013
    Posts:
    8
    Newer NGUI version 3.5.0 breaks compatibility with current Ndata version.
     
  34. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    ^ Came here to say the same thing. The localization methods are different now in 3.5.0.
     
  35. Mathius777

    Mathius777

    Joined:
    Jul 26, 2012
    Posts:
    32
    I have a gameObject in a view model and I want to have it so the "Icon" property of my inventory binds to this game object and places the game object at the location of the item in the inventory. Is there any binding for gameobjects like this? Sprite binding won't work, as it is a custom generated object I need to display in my inventory.
     
  36. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    267
    Hi there,

    First of all: Really nice work with NData! I like the way it's possible to separate view and view logic with it.

    I wanted to dive into your addon a bit more and create some bindings myself. However, I quickly realized that it's nearly impossible to write own generic bindings. The Property class uses a generic type parameter, which is really nice to work with if you know the specific type you are working with.

    But as the bindings I write should work no matter which type the property is, I would require a Context.FindProperty method which doesn't require the type of the property and would return the Property base class. Furthermore the Property base class would need an (abstract) method like

    Code (csharp):
    1.  object GetObjectValue()
    to get the current value. The OnValueChange event is already there, which is great.

    Did I oversee something? Is it planned to adjust the architecture that way?

    Here is the use case I like to handle: We have a prefab for a card which visualizes a CardViewModel. The prefab contains the bindings. Now we don't want to change the prefab, so I set up a NguiChildContextBinding which binds a path as the context of a game object:

    Code (csharp):
    1.  
    2.     public abstract class NguiChildContextBinding : NguiBinding
    3.     {
    4.         #region Fields
    5.  
    6.         public GameObject Target;
    7.  
    8.         private NguiChildContext childContext;
    9.  
    10.         private Property childContextProperty;
    11.  
    12.         #endregion
    13.  
    14.         #region Methods
    15.  
    16.         protected override void Bind()
    17.         {
    18.             base.Bind();
    19.  
    20.             if (this.Target == null)
    21.             {
    22.                 return;
    23.             }
    24.  
    25.             var context = this.GetContext(this.Path);
    26.             if (context == null)
    27.             {
    28.                 return;
    29.             }
    30.  
    31.             this.childContextProperty = this.FindProperty(context, this.Path);
    32.             if (this.childContextProperty == null)
    33.             {
    34.                 Debug.LogWarning("No child context at path " + this.Path + " found.");
    35.                 return;
    36.             }
    37.  
    38.             this.childContextProperty.OnChange += this.OnChildContextChanged;
    39.  
    40.             this.childContext = this.Target.AddComponent<NguiChildContext>();
    41.             this.childContext.SetContext((Context)this.childContextProperty.GetObjectValue());
    42.         }
    43.  
    44.         protected abstract Property FindProperty(NguiDataContext context, string path);
    45.  
    46.         protected override void Unbind()
    47.         {
    48.             base.Unbind();
    49.  
    50.             if (this.childContextProperty != null)
    51.             {
    52.                 this.childContextProperty.OnChange -= this.OnChildContextChanged;
    53.             }
    54.  
    55.             this.childContextProperty = null;
    56.             Destroy(this.childContext);
    57.             this.childContext = null;
    58.         }
    59.  
    60.         private void OnChildContextChanged()
    61.         {
    62.             var context = this.childContextProperty.GetObjectValue();
    63.             Debug.Log("Child context changed to " + context);
    64.  
    65.             this.childContext.SetContext((Context)context);
    66.         }
    67.  
    68.         #endregion
    69.     }
    70.  
    Code (csharp):
    1.  
    2.     public class NguiChildContext : NguiDataContext
    3.     {
    4.         #region Public Methods and Operators
    5.  
    6.         public void SetContext(Context c)
    7.         {
    8.             this._context = c;
    9.  
    10.             var bindings = this.gameObject.GetComponentsInChildren<NguiBinding>();
    11.             foreach (var binding in bindings)
    12.             {
    13.                 binding.ClearContextCache();
    14.                 binding.UpdateBinding();
    15.             }
    16.  
    17.             var multiBindings = this.gameObject.GetComponentsInChildren<NguiMultiBinding>();
    18.             foreach (var binding in multiBindings)
    19.             {
    20.                 binding.ClearContextCache();
    21.                 binding.UpdateBinding();
    22.             }
    23.         }
    24.  
    25.         #endregion
    26.     }
    27.  
    What I needed to do now to get it mostly generic, was to add the GetObjectValue method to the Property base class and override FindProperty method for each specific binding (E.g. NguiCardViewModelBinding). This is not very elegant, of course, but it works.

    As you can see the child context is using nearly the same logic as the NguiItemDataContext, in the end it is a list with one item. Maybe there's an easier way for me to achieve what I want?
     
    Last edited: Feb 25, 2014
  37. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    267
    I just discovered MasterPath which provides the functionality I needed :)

    Nonetheless, a base FindProperty method would be great. This would allow for very generic extensions, e.g. a BooleanBinding which checks if a value is null/not null.
     
  38. jaybennett

    jaybennett

    Joined:
    Jul 10, 2012
    Posts:
    165
    Any ETA on this fix?
     
  39. xAvatarchikx

    xAvatarchikx

    Joined:
    Aug 17, 2012
    Posts:
    69
    How to bind my model to ViewModel?
    public class CharacterBase : MonoBehaviour
    {

    private int _maxLife = 100;
    private int _currentLife = 100;
    private string _entityName = "N/A";

    .....
    }
    That changes when the model changed my ViewModel?
     
  40. jaybennett

    jaybennett

    Joined:
    Jul 10, 2012
    Posts:
    165
    This problem came up two weeks ago, we need a fix. I don't have a previous version of NGUI to fall back to, so its completely broken.
     
  41. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    If you're not using localization, you can fix it by editing these two files:
    NguiUtils.cs, change line 204 to
    Code (csharp):
    1.  output += Localization.Get(key);
    NguiLocalizationKeyBinding.cs comment out line 18
     
  42. jaybennett

    jaybennett

    Joined:
    Jul 10, 2012
    Posts:
    165
    Thanks dude <3
     
  43. jaybennett

    jaybennett

    Joined:
    Jul 10, 2012
    Posts:
    165
    This is odd... the website for Art of Bytes is offline now.

    I need those code snippets for VS :( anyone have them still?
     
    Last edited: Mar 22, 2014
  44. Art Of Bytes

    Art Of Bytes

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

    We are terribly sorry for the inconvenience!
    We had a really tough time here, site will be accessible very soon.

    Please, find the VS snippets in this attachment - View attachment $EZDataSnippets.zip

    Thank you very much for your patience and your support!

    Cheers,
    Your Diversido Team
     
    Last edited: Apr 11, 2014
  45. Art Of Bytes

    Art Of Bytes

    Joined:
    Jun 8, 2011
    Posts:
    198
    The new NData version with the latest NGUI compatibility is already submitted to AssetStore, so it will be available very soon
     
  46. chirhotec

    chirhotec

    Joined:
    Mar 30, 2010
    Posts:
    47
    I'm new to MVVM and this package. I've been reading up on the documentation, examples, and MVVM in general, but it just hasn't fully 'clicked' yet.

    First, just to confirm my understanding of MVVM, the View is essentially the GUI, the Model is the data structures, and the ViewModel is the game logic that acts on the data (either relating it to the GUI, or modifying the data based on GUI input)? In a previous post (page 2), you wrote something along the lines of the 'model knows everything about the ViewModel and can use its properties'. Shouldn't it be the other way around, with the model just being storage and the ViewModel acting on it?

    Second, I'm confused on what the "Context" is, and how it relates to the Model and/or ViewModel. I didn't see anything about "context" in standard MVVM literature. In the NData examples that I've seen, it sometimes seems to be used in the Model and sometimes in the ViewModel, which only seems to muddle the line between Model and ViewModel. Which classes are supposed to extend the Context?

    Finally, I'm probably confused partially because I already have a full data model, tied to server and local storage, and am not really sure how to integrate or refactor it to work with NData. We purchased NData because we have a pretty complex data model and GUI (purely GUI based game in this example), and it was cumbersome to ensure that the GUI always reflected all the data changes; so we're hoping that NData can help ease that process.

    As for the data itself, I think its pretty standard use case: We have a root object in which we can access all other data. It contains app specific data (list of achievements, leaderboards, configuration settings), and user specific data. The user data contains some properties, but also has collections of other objects, specifically potential opponents and current games in play. Each of those contains properties and other sub objects. Its structured like this, in part, so that we can easily serialize the data to json and store to disk (or send object updates to the server), and we can deserialize the data from JSON (either from server responses, or reloading the locally stored json data). Currently, all these structures extend ScriptableObject so that we can pass them around in PlayMaker, but if necessary, I can live without that for the sake of making it work with this system.

    We then have multiple NGUI panels that display, modify or create different data objects. Typically only one panel is active at a time, but there are some panels that are always persistent (for example, the application header bar shows the player's available in-game currency).

    So, in terms of how this can be integrated with NData....

    • Would I typically have a different ViewModel for each Panel (View?) ?
    • Do I need to create a nested Context structure for each ViewModel ?
    • Do these context structures just mirror the structure of the underlying data model?
    • Where does external game logic fit in (ie, server calls, reading from local storage, other game management classes)? Does it need to modify the Model or the ViewModel?
    • If it modifies the Model, how are these changes reflected to the ViewModel?
    • If it modified the ViewModel, do I need a different ViewModel that these functions operate on? Would those changes be reflected to the other VMs, and thus the GUI?

    Sorry for the bombardment of questions. Just trying to wrap my head around it all.
     
    Last edited: Mar 25, 2014
  47. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    267
    Hi chirhotec,

    Maybe you already found the answers to your questions, here are just some that I can answer immediately as I am working with NData, too.

    Yes, you are right, the model has no knowledge about the view model, the view model on the other side has a reference to read and write from the model.

    In the examples the NData guys use the "Context" to be the model and the view model as well. If you just have simple use cases this avoids the complexity which is added by having them split into view model and model. I find it cleaner to have them separated as well plus there are some other benefits (e.g. our game logic is completely separated from Unity). So in our project "context" is just another name for the view model.

    In my opinion you can start like this. Anyway, sometimes you want your view models more centered on the models, e.g. you would use a general ItemViewModel for the item lists as well as for the item detail view. Probably it's more common to have it centered on the models.

    You need a way to inform the view model if something in the model changed. In most cases this would be an event like PropertyChanged or more specific ones. The view model can register for this events during initialization.

    Hope my information helped a bit :)
     
  48. realblues

    realblues

    Joined:
    Dec 10, 2010
    Posts:
    10
    I got an error with example "ColorsPopupList"

    Error is following:
     
    Last edited: Apr 15, 2014
  49. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    267
    Hi,

    Here's one change I had to make to NguiBaseBinding because I got an exception with hierarchical master paths (NguiBaseBinding.cs, line 55):

    Code (csharp):
    1.                
    2. if (!_masterPaths.ContainsKey(lastAddedDepth))
    3. {
    4.     _masterPaths.Add(lastAddedDepth, lastAddedPath);
    5. }
    6.  
    The if block was added. I'm not sure if this is the correct way of doing it, but it removed the exception for me. Maybe you can check if having the MasterPath script multiple times in a hierarchy works as intended and provide a fix with the next update if necessary.
     
  50. chirhotec

    chirhotec

    Joined:
    Mar 30, 2010
    Posts:
    47
    @coeing, your post was very helpful indeed. Thank you!