Search Unity

[RELEASED] Code Control - Easy MVC for Unity

Discussion in 'Assets and Asset Store' started by Jorisvanleeuwen, Feb 22, 2015.

  1. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    That is it. Is the first parameter "Rocket" the name of the object that the Controller will be attached to, or the name of the rocketModel?
     
  2. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    The first parameter, which is also optional, is the name of the prefab it will instantiate.
    Code (csharp):
    1. // "Rocket" is the path and name of the prefab in the Resources folder
    2. Controller.Instantiate<RocketController>("Rocket", rocketModel);
    Let me know if anything else pops up!
     
  3. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Got it. Thanks!
     
  4. Extrakun

    Extrakun

    Joined:
    Apr 2, 2009
    Posts:
    69
    Hi,

    I am deeply interested in your framework. I have a few questions though

    1. In your MVC, where is the game logic handled, inside controller or the model?
    2. Will it work on mobile (Android and ios), and WebGL?
     
  5. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Just wondering. What does the future hold for CodeControl?
     
  6. Extrakun

    Extrakun

    Joined:
    Apr 2, 2009
    Posts:
    69
    Hi, is this framework still supported?
     
  7. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
  8. Extrakun

    Extrakun

    Joined:
    Apr 2, 2009
    Posts:
    69
    Shame, Unity can use a few more alternatives to the MVC frameworks out there.
     
  9. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Hi, I started using Code Control in a new project and I'm wondering if maybe it is a bad idea if it is not being supported anymore.

    Could you please let me know the status of this asset?

    Regards, Dan
     
  10. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi guys, I'm terribly sorry for this late response.. I was under the impression that this forum would send me emails for every post on this thread, but it somehow stopped doing so.

    The game logic would be handled inside the controller. The model just contains data that the controller uses. Check out this page for more information about the responsibilities of each component.

    WebGL is not tested. iOS is not tested as thoroughly as Android but it should work fine.

    I'm currently working on a few other projects, so there will be no new feature for Code Control in near future. I'm always up for fixing issues though! Really bothers me I was unaware of your posts..

    Sorry again guys for my late response. I am still supporting Code Control and will answer all of your questions to my best extend. I will try and figure out how to turn on notifications again.
     
    Last edited: Aug 6, 2015
  11. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Hi,

    Great! I'm am glad Code Control will still be supported. There is a minor issues with Code Control in Unity 5.1.2:

    Assets/CodeControl/Scripts/Editor/CodeControlMonitorWindow.cs(61,22): warning CS0618: `UnityEditor.EditorWindow.title' is obsolete: `Use titleContent instead (it supports setting a title icon as well).'
     
  12. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Setting a title icon? Sounds interesting.. Thank you TokyoDan, I will take a look!
     
  13. cspeer504

    cspeer504

    Joined:
    Sep 26, 2012
    Posts:
    11
    Joris,

    I am very happy with this asset. It's a great light-weight MVC solution that keeps it simple. One question I have, is how a view gets an instance to the controller to send it user actions/input. I know several ways to get it done, but I'd like to stick with the vision of this asset so I use it "correctly". Do I getComponent (since controller is on the same GO as view), do I pass a "this" instance after the controller uses getComponent<view>, or do I use Message to communicate?

    All are viable options, but what is your suggestion in context of Code Control?

    Also, I'd like to add that I checked out the Example, but it only had one View that didn't communicate to the controller. :)
     
    Last edited: Aug 23, 2015
  14. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi cspeer504, thank you for the post! Great to hear you like it!

    The view should not get a reference to the controller in any case, as it should focus on just the interaction/visualization within the context of its purpose. Using CodeControl I'd suggest to use callbacks (delegates/actions) to communicate from view to controller and call the view's public methods to communicate from controller to view. You could assign the model to the view and make it listen to its changes to update, but in my opinion you should keep the view separate from the model to make the view reusable for other controllers using different model types. It's up to you to follow that conventions of course!

    In the following example I tried to setup the perfect communication scheme between the model, controller and view.

    Code (CSharp):
    1. public class UserListModel : Model {
    2.  
    3.     public List<string> Usernames;
    4.  
    5. }
    6.  
    7. public class SubmitUsersMessage : Message {
    8.  
    9.     public List<string> Usernames;
    10.  
    11. }
    12.  
    13. public class UserListView {
    14.  
    15.     public Action<string> OnAddUser;
    16.     public Action OnSubmit;
    17.  
    18.     private UserListModel model;
    19.  
    20.     public void UpdateList(List<string> usernames) {
    21.         // Update ui elements to display given usernames
    22.     }
    23.  
    24.     private void Awake() {
    25.         // Assign handlers to UI logic to add a user and submit
    26.         // ... += OnAddUserButtonClicked();
    27.         // ... += OnSubmitButtonClicked();
    28.     }
    29.  
    30.     private void OnAddUserButtonClicked() {
    31.         string username = "new user"; // Get username from ui
    32.         if (OnAddUser != null) {
    33.             OnAddUser(username);
    34.         }
    35.     }
    36.  
    37.     private void OnSubmitButtonClicked() {
    38.         if (OnSubmit != null) {
    39.             OnSubmit();
    40.         }
    41.     }
    42.  
    43. }
    44.  
    45. public class UserListController : Controller<UserListModel> {
    46.  
    47.     private UserListView view;
    48.  
    49.     protected void OnInitialize() {
    50.         view = GetComponent<UserListView>();
    51.  
    52.         view.UpdateList(model.Usernames);
    53.  
    54.         // Start listening to view's callbacks
    55.         view.OnAddUser += OnAddUser;
    56.         view.OnSubmit += OnSubmit;
    57.     }
    58.  
    59.     protected override void OnModelChanged() {
    60.         // Update list whenever the model changes
    61.         view.UpdateList(model.Usernames);
    62.     }
    63.  
    64.     private void OnAddUser(string username) {
    65.         model.Usernames.Add(username);
    66.         model.NotifyChange(); // Calls 'OnModelChanged', updating the view
    67.     }
    68.  
    69.     private void OnSubmit() {
    70.         SubmitUsersMessage message = new SubmitUsersMessage() {
    71.             Usernames = model.Usernames
    72.         };
    73.         Message.Send<SubmitUsersMessage>(message);// Could be listened to by another controller
    74.  
    75.         model.Delete(); // Destroys the controller, including its view as it is attached
    76.     }
    77.  
    78. }
    To summarize:
    • Controller to View: call methods
    • View to Controller: actions/callbacks
    • Controller to Model: change field values
    • Model to Controller: override OnModelChanged
    • Model to View: via Controller
    • View to Model: via Controller
    I hope this helps, let me know if you still have questions! Note that CodeControl does not force this controller/view communication to keep things simple and open for different implementations.
     
    Last edited: Aug 23, 2015
    cspeer504 likes this.
  15. cspeer504

    cspeer504

    Joined:
    Sep 26, 2012
    Posts:
    11
    Perfect response! This would be a great snippet to add to your website tutorials: "Processing User Input". I know views are supposed to be open to the user to design, but it really helps to see how they are intended to work in the MVC without adding unnecessary coupling. I do love how open Code Control is to flexibility.

    I've made a cheat sheet chart that highlights intended use for MVC through Code Control. I like to post this stuff on my wall so I can quickly glance at the design. Would you mind giving this a look and make sure the info is valid? I don't mind if you want to share it to help others as well.

    https://drive.google.com/file/d/0B8NEEka-fNDMS0U4XzB1bHd2ZHM/view?usp=sharing
     
    Last edited: Aug 23, 2015
  16. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Ha, awesome graph! Looks 100% valid. Only thing I could think of is noting at tip 2 that usually controllers instantiate other controllers (using Controller.Instantiate) based on their models.

    Thanks, I appreciate it! I'm thinking about adding this kind of code snippets/charts as a third section to the tutorial page of the site (intro/tuts/snippets). This looks like a neat and simple chart that's helpful to more people. I'm posting the picture here in the thread so others can see, if you don't mind (let me know if otherwise).


    Thanks again!
     
    Last edited: Aug 24, 2015
  17. cspeer504

    cspeer504

    Joined:
    Sep 26, 2012
    Posts:
    11
  18. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Made the change in image! Let me know if you stumble upon anything else ;)
     
  19. cspeer504

    cspeer504

    Joined:
    Sep 26, 2012
    Posts:
    11
    Hey everyone. I found myself doing a lot of manual setup at the beginning of my project by creating an MVC file for every actor in my game and doing a lot of copy/pasting, changing names, etc... This, of course, leads to human error and fixing those afterwards. So, I made a custom editor script to create these for you! With just a little setup, all you have to do is enter your actor/object's name and the rest is handled for you.

    1. Download and import this unity package. This populates the following files:
      Assets/CodeControl/MVCTemplates/Editor/MVCCreatorEditor.cs // This is the custom editor file.
      Assets/CodeControl/MVCTemplates/ControllerTemplate.txt // These are the text based file templates.
      Assets/CodeControl/MVCTemplates/ModelTemplate.txtAssets/CodeControl/MVCTemplates/ViewTemplate.txt
      upload_2015-8-28_19-17-13.png
    2. Open Assets/CodeControl/MVCTemplates/Editor/MVCCreatorEditor.cs and change the "TODOs" to your liking, then save.
    3. Click Windows->Template Generation->Code Control MVC Creator
    4. When the MVC Creator window pops up, type the name of the object that will have an MVC, then click "Create MVCs"
    5. Go to your MVC folder and you will see all three files created for you with some handy starting code.
    If you have issues, please e-mail me. Hopefully this helps everyone else as much as it helped me out!
     
    zeb33 likes this.
  20. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
  21. Dan2013

    Dan2013

    Joined:
    May 24, 2013
    Posts:
    200
    @softlion

    I think JSON is already much more popular than XML.
    If you may want to do some researches for JSON serializers, I suggest to have a look at Full Serializer and JSON.NET For Unity asset. Full Serializer (from Full Inspector asset) is free and supposed to work on any platform/devices.


     
  22. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Full serializer looks interesting! I assume you mean this https://github.com/jacobdufault/fullserializer? Another project of mine is soon to be finished so I'll have more time to work on an update to possible support JSON.
     
  23. GamePowerNetwork

    GamePowerNetwork

    Joined:
    Sep 23, 2012
    Posts:
    257
    I just purchased this assets and I'm already extremely pleased with the ease of it. I've purchased other (visual MVC) plugins on the asset store and they were great.. but they added more confusion during development time then I wanted or needed.

    Thank you to @softlion for developing this and I hope he continues supporting it because Unity needs this!

    Also I'd like to +1 the JSON support. I'm using Parse.com backend with my game and saving JSON would be so much better than XML. :)

    Keep up the great work!
     
  24. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Thank you PyroStudios for the feedback and kind words, really awesome!

    Almost done with another project and planning on implementing JSON support after its release!

    Thanks again!
     
    zeb33 likes this.
  25. 21312313123321

    21312313123321

    Joined:
    Dec 5, 2014
    Posts:
    13
    Just bought as part of the 'Sensible Sale', happy so far but would really like some changes...

    1 - By default it renders the full path of every object, so I get things like "mycompany.project.foldera.folderb.SomeClass", the problem is that all the buttons do not scale to the text width so I can't see it. (Would be better to render just the class name).

    2 - It would be cool to be able to only scan for views/models in a specific folder. This way I can split my app into contexts and your editor can show only the areas I am currently interested in. At the moment, even your example project is displayed even when I am not running it (within the relationships tab).

    3 - The ability to instantiate a controller so it is added to the existing GameObject. At the moment we can only add as a child...

    4 - The ability to zoom in/out would be very handy, not essential but I can't see why not...

    Some of these issues I have worked around (ie type.ToString() to type.Name etc) but I think those aspects make the tool not live up to what its aim is. The MVC code is fine, general MVC stuff really not ground breaking (which was all I expect/need anyway) - its the editor that matters :D
     
  26. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi 21312313123321, thanks for the feedback!

    That's a valid point. Maybe it should only show just the class name unless there are multiple classes of the same name.

    I really like this idea! Putting it on my list :D This will be helpful for all monitors.

    Could you give an example/short code snippet of what you mean and would like to do?

    It sounds obvious enough.. I'll consider this features when more people request it but until then I'll focus on features that are more heavily needed.

    Thanks again!
     
  27. 21312313123321

    21312313123321

    Joined:
    Dec 5, 2014
    Posts:
    13
    Thank you for the quick reply, was expecting a longer wait! :D

    'Could you give an example/short code snippet of what you mean and would like to do?'

    So at the moment we can create a controller and choose its parent transform, but really it would make more sense to add it as a component of a gameobject instead.

    Controller.Instantiate<CounterUiController>(model,gameobject);

    Now 'gameobject' will have the CounterUiController as a component (not as a new game object child).

    We can then also have:

    Controller.InstantiateChild<CounterUiController>(model,transform);

    To have the same effect as having it parented to the transform.

    Really it comes down to I don't want a separate gameobject for every controller in the game when having it as a component is likely the scenario most people would expect as the default behaviour...
     
  28. 21312313123321

    21312313123321

    Joined:
    Dec 5, 2014
    Posts:
    13
    Update:

    Concerning the 'Controller.Instantiate<CounterUiController>(model,gameobject);' idea...

    ...to me I think it feels better because we are Instantiating a MonoBehaviour and we associate them with gameobjects, not there related transformation in the scene graph ;)
     
  29. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    That's interesting. I think it might be better to make the component variant an extension method on the gameObject and rename it to gameObject.AddController<T>(model), as it is not really instantiating anything.

    This will mean when one controller is destroyed or an associated model is deleted all the other added controllers/models will be destroyed/deleted as well.. something to keep in mind. I'll add it to the list for the next update though!
     
    21312313123321 likes this.
  30. Dan2013

    Dan2013

    Joined:
    May 24, 2013
    Posts:
    200
    Yes it is.
     
  31. Unreal-Vision

    Unreal-Vision

    Joined:
    May 6, 2013
    Posts:
    58
    Hi Softlion,

    The MVC framwork seems quiet easy to use.
    Compared to uFrame (Included new ECS), what are the advantages?
    uFrame is not so easy to use for big production and we are searching for some alternative.

    Thanks,
     
  32. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi Unreal Vision!

    I have no experience using uFrame. From what I can see the main difference would be that Code Control is purely a code based framework with insightful monitors that visualize what is happening in code while running your game. Code Control's data models can be saved (serialized) while having references to each other and controllers enforce a single initialization path, making sure there is no separate code for initializing-from-game and initializing-from-load. In addition, Code Control is designed to be as light weight and easy to learn as possible to distinct from other frameworks on the Asset Store.

    Let me know if you need something else!
     
  33. GamePowerNetwork

    GamePowerNetwork

    Joined:
    Sep 23, 2012
    Posts:
    257
    Hi @Unreal Vision I use uFrame and now CodeControl. Both products are great... however personally I feel CodeControl takes out that extra layer of overhead when it comes to developing code. The visual editor in uFrame is really nice and kudos to the guys that made it. But if you really want to hit the ground running I'd suggest Code Control.

    Code Control takes the MVC pattern and brings it more inline with Unity's component convention. uFrame on the other hand (minus ECS) adds an extra layer on top of Unity's component convention and hides it away a little more. That's just my personal take on it, as a user of both products.

    In summary I think they're both great products.. it's just a choice of, do you want to do pure coding without adding an extra layer of framework (use Code Control).... or do you want to visually layout your code with diagrams and have framework code generated for you (use uFrame).
     
  34. Unreal-Vision

    Unreal-Vision

    Joined:
    May 6, 2013
    Posts:
    58
    Thanks PyroStudios,

    Perfect explanation! It's time to buy CodeControl :)
     
  35. GamePowerNetwork

    GamePowerNetwork

    Joined:
    Sep 23, 2012
    Posts:
    257
    Hi @softlion I just noticed a slight issue with Controller.Instantiate

    It works perfectly with 3D objects and objects in the 3D space. However when using it for UI elements there's a problem. First, here is the warning Unity throws whenever a prefab using a UI element is set in the Controller.Instantiate

    ----------
    Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.
    UnityEngine.Transform:set_parent(Transform)
    Controller:Instantiate(Object, Model, Transform) (at Assets/CodeControl/Scripts/Source/Controller.cs:111)
    Controller:Instantiate(Object, Model) (at Assets/CodeControl/Scripts/Source/Controller.cs:82)
    Revolt.WO.GameManager:Awake() (at Assets/Game/Scripts/GameManager.cs:20)
    ----------

    And when the game is run, sure enough the scaling is off when the prefab is instantiated. Seems SetParent needs to be used instead.
     
  36. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Thank you for noting PyroStudios! You can change that in the Controller's source code yourself for now, I'll be sure to add it in the next update.
     
  37. cspeer504

    cspeer504

    Joined:
    Sep 26, 2012
    Posts:
    11
    It sounds like you already have your mind set @Unreal Vision, but just to add my two cents. I first tried UFrame before Code Control. I really, really, really wanted to like UFrame. Not just because I dropped a good amount of cash for it, but because a lot of people like it and it looks very useful. However, it turned out to be more overhead than I wanted in my one-man-team projects.

    Also, it was super hard to learn at the time I jumped in. I started using UFrame end of August when 4.6 recently came out. Most of their documentation was on older versions and out of date. The documentation and tutorial videos that did target 4.6 were tailored to people who were already comfortable with the earlier version. So that ended up being a very frustrating four week learning phase for me. I eventually got it working, but ended up not liking it anyway, haha.

    I then tried Code Control and quickly picked it up. I had started making games with it in just an hour or two after purchasing it. It's very lightweight and flexible, so that's nice. If you write code in C#, check out the template files I posted earlier in this forum. They save you time of manually having to create a model file, view file, and controller file every time you need one.
     
  38. iamsam

    iamsam

    Joined:
    Dec 22, 2013
    Posts:
    233
    @cspeer504 Thanks a lot for the template files and the flowchart, they surely helped me :).

    I was wondering if it would be possible for @cspeer504 or @softlion to post a quick video or a small project to demonstrate multiple controllers. For example just a small demo on how one can press a button to change the color of an object and then use the same message to change color of another object. I am still a bit confused on how one instantiates multiple controllers.

    Thanks.
     
  39. iamsam

    iamsam

    Joined:
    Dec 22, 2013
    Posts:
    233
    Another quick question. How do you work with UI bindings, do you use the Unity event system and plug in your Views (call their methods) or is there a more clean way to do it? Also can I use other plugins available in the asset store such as Easy save to save the models rather than the system provided with the asset?
     
  40. daeuk

    daeuk

    Joined:
    Mar 3, 2013
    Posts:
    67
    just bought this asset.. trying to learn mvc...
    however, i seem cannot instantiate a prefab following the tutorial.
    1) followed the c# on 'making a controller'
    2) attached the controller in a prefab
    3) created an empty gameobject and attached the ExampleGame script

    i dont see the cube prefab i have created. any thoughts?
     
  41. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    My apologies again guys for the late response. Unity seems to make my account unfollow this thread every other week...

    The messaging system in Code Control is global so messages can't be targeted directly to a single controller. If a cube controller needs to listen to a specific UI button that is created for just that controller, then the UI button should be created by the cube controller itself as it belongs to just that instance.

    There is no specific view implementation required in Code Control to make it as adaptable as possible. To implement Unity UI elements one should listen to these from a controller and send out messages accordingly.

    Code Control has its own logic for saving and storing models which will probably not be supported by other assets.

    Thank you for the purchase! To instantiate a specific prefab as controller opposed to an empty gameobject, the path/name of the prefab relative to the Assets/Resources folder should be included:
    Code (CSharp):
    1. // Instantiate specific prefab with controller and assign model
    2. Controller.Instantiate<ExampleController>("TestPrefabs/MyCubePrefab", model);
    I hope that answers all of your questions! Thank you guys!
     
  42. Setmaster

    Setmaster

    Joined:
    Sep 2, 2013
    Posts:
    239
    Will I get bad performance if I have multiple listeners for the same message?
     
  43. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi Setmaster!
    No, the performance will stay stable. It's the same as having multiple listeners to a delegate/action in C#.

    I hope this answers your question. If not, let me know!
     
  44. InsomniaLab

    InsomniaLab

    Joined:
    May 14, 2014
    Posts:
    3
    Was considering purchasing this asset since it looks like a simpler way for me to implement MVC, but I see that you mentioned that models/model data won't show up in the inspector since they're not a subclass of Unity's MonoBehaviour.

    Is there any way to change this? Not having the ability to show model data in the editor so it can be easily inspected at runtime would really make this a no go for me. Don't public classes marked with [System.Serializable] show up in the editor? Is there something else going on in your model implementation that makes the data unable to appear in the editor?
     
  45. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi InsomniaLab,

    With some tweaks it is possible to display serializable typed values in the inspector. You'd need the change the following line of code in the Controller class:
    Code (CSharp):
    1.     public abstract class Controller<T> : AbstractController
    2.         where T : Model {
    3.  
    4.         protected T model { get; private set; } // Change this to the line below
    5.         [SerializeField] protected T model;
    6.  
    7.         ...
    The ModelRef(s) are not serializable, so referenced models will not be displayed. Be sure to make the models that need to be serialized a [System.Serializable] though.

    I hope you'll find what you are looking for!
     
  46. PadreMontoya

    PadreMontoya

    Joined:
    Aug 15, 2015
    Posts:
    3
    @softlion Just FYI - I hit a bug and had to tweak model.cs to get past it. In a nutshell:

    PlayerModel contains a PartyModel
    PartyModel contains eight HeroModels

    If I call Model.SaveAll(), that works - it writes the manifest and 10 XML files.

    When I try to Model.Load(), however, I get:

    Code (CSharp):
    1. System.ArgumentException: An element with the same key already exists in the dictionary.
    2.   at System.Collections.Generic.Dictionary`2[System.String,Model].Add (System.String key, .Model value) [0x0007e] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404
    3.   at Model.Register () [0x0001e] in C:\Users\Anthony\Documents\Unity\exponential-heroes-unity-project\Assets\Vendor\CodeControl\Scripts\Source\Model.cs:526
    4.  
    I fixed it with this code change. (See comment) If this makes sense, you might want to include it permanently.

    Code (CSharp):
    1.     private void Register() {
    2.         if (isSerializing) { return; }
    3.         if (isRegistered) { return; }
    4.         isRegistered = true;
    5.  
    6.         if (!sortedInstances.ContainsKey(id))  // <-- Added this.  It resolved my issue (so far)
    7.             sortedInstances.Add(id, this);
    8.        
    9.         if (!typeSortedInstances.ContainsKey(GetType())) {
    10.             typeSortedInstances.Add(GetType(), new List<Model>());
    11.         }
    12.         typeSortedInstances[GetType()].Add(this);
    13.  
    14.         instances.Add(this);
    15.     }
     
  47. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi PadreMontoya, thank you for the post!

    Are possibly you loading models without deleting the models you are trying to load? That could result in this error.. Even though, I will include this fix in the next update! Thanks again!
     
  48. Deleted User

    Deleted User

    Guest

    I want to load individual models. I have my backend data coming in. I convert it to an xml string. This string should become a Model or update a Model. I want to add or replace the xml into the current blobs just for that Model.

    Something like this:

    string xml = JsonService.xmlHash;
    ModelBlobs blobs = Model.SaveAll();
    // edit blobs to add or replace the xml for a particular model
    Model.Load (blobs, null, null, null);
     
  49. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    If I understand you correctly you want to, based on data coming in from the backend, change existing serialized xml data on the frontend? If so, it might be better to make the backend send change-commands to the front-end instead of new serialized data and change the runtime Code Control models accordingly. Altering serialized data would be more of a hassle than changing the actual models at runtime in my experience.
     
  50. Deleted User

    Deleted User

    Guest

    Basically I want what Load() does but for just one Model. So instead of passing the entire ModelBlobs, just pass a ModelEntry. So adding/changing ModelEntries in the current ModelBlobs.

    Like this:

    string xml = JsonService.xmlHash[key];
    ModelBlobs blobs = Model.SaveAll();
    ModelEntry entry;

    if (blobs[Id] != null) {
    entry = blobs[Id]; // looks like i have to convert the string back to ModelEntry here
    entry.SetType(xml);
    } else {
    entry = new ModelEntry(Id, xml);
    }

    Model.Load (blobs, null, null, null);

    I don't want to have to parse through the json for every property on every model. I just want to load the xml.
     
    Last edited by a moderator: Dec 8, 2015