Search Unity

NData - MVVM framework for NGUI

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

  1. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    NGUI since 3.5.6 supports databinding.

    In a future version, can NData leverage this new feature so as to create less boiler plate code for the bindings.
     
  2. Grimatoma

    Grimatoma

    Joined:
    Mar 29, 2013
    Posts:
    1
    Hi, Quick question about using NData. Also It is amazing to use and very easy, there was somewhat of a learning curve but I am making some very powerful dynamic guis right now :)

    I currently have a table in a uiscroll view that is populated by a collection that is in a collection itself ie:
    StoresTable.SelectedItem.ItemsTable
    I have it all working but when I scroll one of the ItemsTable that has more items and then switch to another ItemsTable with less, the uiscroll view does not reset and the items are stuck offscreen. since with MVVM I do not/(should not?) have access to the view, how do i tell the view that it needs to run the ResetPosition () on the uiscroll view
     
  3. linghunchongxin

    linghunchongxin

    Joined:
    Mar 20, 2014
    Posts:
    6
    hello,I very like to use NDate,now i have a problem on Ngui Item Source Binding.
    I find item templates is create dynamic, this is good,but layout is depending on UITable.
    So the layout of these items is only created with one direction ->or down or up.
    of course ,I can bind two or more Ngui Item Source to layout ,but I want you can set create direction to script.
    Wish NDate do better !
     
  4. realblues

    realblues

    Joined:
    Dec 10, 2010
    Posts:
    10
    Is it Stopped Developping? it is very sad T.T

    I am your big fan. It is still productive very much. much more than ngui's property binding.

    please keep updating.
     
  5. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    It seems a dead product. Should be removed from Asset Store.

    Which is a great pity, because it was a great product.
     
    nicloay and realblues like this.
  6. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    540
    I agree it's very great framework. but it has a luck of normal API documentation. and no support here

    BTW. could someone help me to check following script.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4.  
    5. [System.Serializable]
    6. [AddComponentMenu("NGUI/NData/PlayAnimation Binding")]
    7. public class NguiPlayAnimationBinding : NguiBooleanBinding, IVisibilityBinding {
    8.     NguiVisibilityControl _nvc = new NguiVisibilityControl();
    9.     public bool Visible { get { return _nvc.Visible; } }
    10.     public bool ObjectVisible { get { return _nvc.ObjectVisible; } }
    11.     public bool ComponentVisible { get { return _nvc.ComponentVisible; } }
    12.     public void InvalidateParent() { _nvc.InvalidateParent(); }
    13.  
    14.     bool newValue;
    15.  
    16.     public override void Awake()
    17.     {
    18.         base.Awake();
    19.         _nvc.Awake(gameObject);
    20.         newValue = DefaultValue;
    21.     }
    22.  
    23.     float timeoutBeforeHide;
    24.     protected override void ApplyNewValue(bool newValue)
    25.     {
    26.      
    27.         if (animation != null && this.newValue != newValue)
    28.         {
    29.             this.newValue = newValue;
    30.             float maxTime =0.0f;
    31.             foreach (AnimationState state in animation){
    32.                 if (newValue){
    33.                     state.speed = +1.0f;
    34.  
    35.                 } else {
    36.                     state.speed = -1.0f;
    37.                     state.time = state.length;
    38.                     maxTime = Mathf.Max(maxTime, state.length);
    39.                 }
    40.             }
    41.             if (newValue){
    42.                 StopCoroutine("WaitAndHide");
    43.                 _nvc.ApplyNewValue(true);
    44.  
    45.             } else {
    46.                 timeoutBeforeHide = maxTime;
    47.                 StartCoroutine("WaitAndHide");
    48.             }
    49.  
    50.             animation.Play();
    51.         }
    52.     }
    53.  
    54.     IEnumerator WaitAndHide(){
    55.         yield return new WaitForSeconds(timeoutBeforeHide);
    56.         _nvc.ApplyNewValue(false);
    57.     }
    58.  
    59.     [ContextMenu("Hide All")]
    60.     void HideAll(){
    61.         _nvc.Awake(gameObject);
    62.         _nvc.ApplyNewValue(false);
    63.     }
    64.  
    65.     [ContextMenu("Show All")]
    66.     void ShowAll(){
    67.         _nvc.Awake(gameObject);
    68.         _nvc.ApplyNewValue(true);
    69.     }
    70. }
    71.  
    I have to play standard unity animation and then hide/show the object. I've done this script. but looks like that NguiBooleanBinding has a complex logic, and then i close the scene and go back. another NguiBooleanBinding game objects which is children of my Animation Binding object show following error

    Update1:

    I found problem part of code.
    At class NguiBooleanBinding there is following part of code

    Code (CSharp):
    1. protected override void Bind()
    2.     {
    3.         base.Bind();
    4.        
    5.         var context = GetContext(Path);
    6.         if (context != null)
    7.         {
    8.             _properties[typeof(bool)] = context.FindProperty<bool>(Path, this);
    9.             _properties[typeof(int)] = context.FindProperty<int>(Path, this);
    10.             _properties[typeof(Enum)] = context.FindEnumProperty(Path, this);
    11.             _properties[typeof(float)] = context.FindProperty<float>(Path, this);
    12.             _properties[typeof(double)] = context.FindProperty<double>(Path, this);
    13. #if !UNITY_FLASH
    14.             _properties[typeof(decimal)] = context.FindProperty<decimal>(Path, this);
    15. #endif
    16.             _properties[typeof(string)] = context.FindProperty<string>(Path, this);
    17.         }
    18. ...
    19. }
    So here we have an Dictionary which contains links to the different type of property. And the problem is that, for int32 property FindEnum return the int value. so if you have just one property with type int32 this code will return 2 object. And S*** happens here
    Code (CSharp):
    1.     protected override void Unbind()
    2.     {
    3.         base.Unbind();
    4.        
    5.         foreach(var p in _properties)
    6.         {
    7.             if (p.Value != null)
    8.             {
    9.                 p.Value.OnChange -= OnChange;
    10.                 _properties[p.Key] = null;
    11.                 break;
    12.             }
    13.         }
    14.     }
    See. you unsubscribe only from one type, i don't know maybe enum maybe int. and then exit from here. So this Binder component still has unsubscribed delegate, so it won't be destroyed on level unload, and then you went this scene and come back, this code will fire again and drop you the message that root gameObject (on which this component was attached to) could not be found.

    So workaround - not to use enum and comment that row. or maybe don't exit from cycle on unbind, method, but as i remember it give some strange exception.
     
    Last edited: Nov 11, 2014
  7. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    540
    Could someone let me know, is there any better alternatives?
    I'm very tired to fix bug in this package.
    It doesn't clean all events properly on object destroy. and then you switch the scenes, some object scripts won't destroyed, and then you come back, they still listen context variable events, and give you some exceptions.

    It still works on PC platform, but on WP it break the whole application.
     
  8. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    It's a pain, but they refuse to update it anymore so I had to rate it 1 star on Asset Store and warn people not to buy it.

    re: Replacement for NData
    I've been using NData MVC with Messenger Extended from the Unity wiki.

    I'm currently playing with the new Unity gui in 4.6 and it feels pretty good to use, better than NGui workflow imo.
    All it needs is a few more advanced controls.

    I'm probably going to drop NGui and standardise on the new Unity gui once it's official.

    In terms of using a UI architecture as a replacement for NData I've been looking at different architectures for data binding, messaging, and/or MVC based varients.

    Foundation is free https://www.assetstore.unity3d.com/en/#!/content/15647 but seems to have a bug atm

    IOC and dependency injection is interesting but has its own set of issues that in some ways seem as bad as what its supposed to fix.

    UFrame is also IOC/DI looks interesting, but expensive and not sure about the pattern use of MVVM based on some forum threads from smart people. Still, a lot of people seem to like it.
    Still thinking about investing in it.

    StrangeIOC in particular suffers from this, with files all over the place and very nebulous indirection so it's hard to picture the control flows in anything but a very simple app.

    Zenject seems more lightweight than StrangeIOC and I'm currently looking at it.

    StrangeIOC and Zenject are both free open source on the Asset Store.

    Anyone else have suggestions?
     
  9. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    271
    Hi @sonicviz,

    Thanks a lot for the suggestions! Will look into them as we are using NData at the moment, too, with many custom extensions/fixes. I was even planning to build up an own, clean Data Binding asset if there is interest in it. But let's see what is around already :)

    Let me know what you think of Zenject, it looks interesting!

    Cheers
    Christian
     
    Last edited: Dec 1, 2014
  10. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Hi Christian,
    MinIOC also popped up on Asset Store https://www.assetstore.unity3d.com/en/#!/content/25562

    Zenject and MinIOC look like the most lightweight and modular, but still evaluating.

    [as an aside this post yesterday on Javascript framework craziness also applies to Unity application frameworks, and I agree with the modular library conclusion http://www.breck-mckye.com/blog/2014/12/the-state-of-javascript-in-2015/ ]

    StrangeIOC honestly looks convoluted and a brainstrain, so forget that imo.

    I did pick up uFrame yesterday on the sale, but while it looks nice it's confusing to get a handle on as the tutorials/examples are all over the place due to different versions. He needs to really stop development for a week or two and put some work into solidifying the learning content on it. I'll keep playing with it but not sure if I''ll risk a production app on it yet.

    Another alternative that just occurred to me is adapting this Easy MVVM Example https://code.msdn.microsoft.com/Easy-MVVM-Examples-fb8c409f or the VERY Easy MVVM "MVVMExtraLite" https://code.msdn.microsoft.com/VERY-Easy-MVVM-MVVMExtraLit-9a24e749
    I found these after jumping to Visual Studio 2013 Community with the Unity plugin.


    So we have some options! Just keep it light, modular, replaceable AND performance oriented is my gut feel atm.
     
  11. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    271
    Definitively modular and replaceable! We are having already a pretty solid own framework here for our logic (parts of it already available at http://slashgames.org/framework) and on the other side there are great UI systems, so all I am looking for is a nice man in the middle :)

    I just played around with some ideas yesterday and posted on the forums (http://forum.unity3d.com/threads/data-bind-for-unity.283252/) to see if there is some interest in a data binding module. I will probably have to post some screenshots how the module would look like from the UI and logic side. A simple example (LabelBinding) is already up and running, I might just take that.
     
  12. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Looks good, I'll add it to the list to test.

    Edit: ah, dll's only? I'm really only interested in source solutions atm so I can see what's going on.
     
    Last edited: Dec 2, 2014
  13. nventimiglia

    nventimiglia

    Joined:
    Sep 20, 2011
    Posts:
    153
    Kind of late to the game.

    If you need databinding with uGUI you can try out Foundation. It supports a MVC or MVVM design. It is free. It comes with a complete lobby example scene which should cover 90% of use cases.

    http://mmofoundation.com
     
  14. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    271
    I can give you access to the source code, if you like :) Do you have a github account?
     
  15. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
  16. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    271
    Alright, you are in :) Let me know if you have any problems and feel free to give me as much feedback (positive and negative) as you like.
     
  17. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    coeing likes this.
  18. coeing

    coeing

    Joined:
    Mar 17, 2011
    Posts:
    271