Search Unity

[RELEASED] Code Control - Easy MVC for Unity

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

  1. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Thank you for clarifying. Loading a single model that has been saved in a group is not supported in Code Control as it potentially has references to the other models. If you want to change something without too much manual labor you would have to load all models that were saved in that group, make the change, and save them back to ModelBlobs.

    You could query the ModelEntry from the ModelBlobs as you are doing in your example, manually go through the XML (using the XmlDocument class), change values of properties and serialize and save it back into the ModelBlob. Note that this has not been tested as Code Control is not designed for this use.

    Thank you again for clarifying, I hope you will get to a solution.
     
  2. cavila

    cavila

    Joined:
    Jun 4, 2013
    Posts:
    67
    Hi Softlion,

    I'm starting to get acquainted with Code Control. The first thing I noticed is the lack of encapsulation of the framework in a namespace. Is this something that's planned for the future?

    thanks.
     
  3. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi cavila!
    This is planned to be implemented in the next update!
     
    cavila likes this.
  4. vzheng

    vzheng

    Joined:
    Dec 4, 2012
    Posts:
    38

    UnauthorizedAccessException: Access to the path "SomePath" is denied.


    iOS 9.2,Xcode 7.2,
     
  5. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
  6. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Update: Code Control patch 1.0.3 was just accepted and is now live on the Asset Store.

    Patch notes:
    - Put all Code Control components in a CodeControl namespace
    - Fixed monitor title warning message in Unity 5.1.2 and up
    - Fixed bug "Element already exists in dictionary" on model register
     
  7. cavila

    cavila

    Joined:
    Jun 4, 2013
    Posts:
    67
    Saw the new namespacing, awesome!
     
  8. gravyleaves

    gravyleaves

    Joined:
    Mar 19, 2014
    Posts:
    28
    Is it possible to have multiple controllers of the same type that use separate models?
    In a local multiplayer game I want each player to have its own controller and model of a basic type. Message flow monitor doesn't seem to allow display copies of one controller.

    Also when I broadcast a global message, only one controller picks it up, not both. How can I get around this?
     
  9. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi gravyleaves!
    Yes this is possible! Take a look at the example project; the TurretController is being instantiated multiple times, each having its own TurretModel. To implement local multiplayer in your game you could store the (xbox)controller index in the model of your controller.
    Code (CSharp):
    1. class PlayerModel : Model {
    2.     public int PlayerIndex;
    3. }
    4.  
    5. class PlayerController : Controller<PlayerModel> {
    6.     private void Update() {
    7.         // Use model.PlayerIndex to target correct (xbox)controller
    8.     }
    9. }
    10.  
    11. class GameManager : MonoBehaviour {
    12.     private void Awake() {
    13.         for (int i = 0; i < 4; i++){
    14.             PlayerModel model = new PlayerModel();
    15.             model.PlayerIndex = i;
    16.             Controller.Instantiate<PlayerController>("PlayerPrefab", model);
    17.         }
    18.     }
    19. }
    If you start listening to the message in the controller's OnInitialize method, all instances of that controller should be picking up the message. Can you provide some of the code so I can take a look?
     
  10. gravyleaves

    gravyleaves

    Joined:
    Mar 19, 2014
    Posts:
    28
    That was part of it. The other part was one of the controllers intercepting the other's messages. Thanks for the help!
     
  11. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    I'm not sure if I understand.. can you clarify?
     
  12. gravyleaves

    gravyleaves

    Joined:
    Mar 19, 2014
    Posts:
    28
    Probably not well... My setup was complicated where one controller was intercepting messages after initialization of a separate identical controller before the global initialization message reached the controller which did the intercepting.

    If somehow I could get a reference to controllers when instantiating them I could have an easier work around, but it's fixed now in any case.
     
  13. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Yes indeed, the idea is to decouple controllers and communicate through messages. Are your problems now fixed? :D
     
  14. marshmatter

    marshmatter

    Joined:
    Oct 2, 2013
    Posts:
    42
    How is platform support for Code Control?
     
  15. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi marshmatter!

    PC and Android are tested most. iOS is also tested and performed fine. WebGL is not tested as it was still in beta during Code Control's release. Game consoles are also not tested.

    If it works or does not work for a specific platform, please let us know on this thread! Thank you!
     
  16. Extrakun

    Extrakun

    Joined:
    Apr 2, 2009
    Posts:
    69
    Hi two quick questions:

    1. Can logic to be implemented in the model instead of the controller?

    2. Will references to normal objects (not models) inside a model be serialized properly, and be serialized to a reference?
     
  17. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi there!

    You could add some methods/properties of simple queries or data manipulation in the models. But all game logic should reside in the controllers.

    Those "normal" objects should have the [serializable] attribute assigned to their class, then they would be serialized properly. Only the Model classes referenced through the ModelRef(s)<T> will be (de)serialized as a separate reference though!
     
  18. Extrakun

    Extrakun

    Joined:
    Apr 2, 2009
    Posts:
    69
    Just curious -- Usually most MVC advocates would advise putting logic into the model as to avoid 'fat' controllers.
     
  19. themarkval

    themarkval

    Joined:
    Feb 5, 2013
    Posts:
    11
  20. LesmoCasanova

    LesmoCasanova

    Joined:
    Mar 22, 2015
    Posts:
    1
  21. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Unity Code Control will not support UWP anywhere in near future. Feel free to solve the issues of unsupported platforms in the source code which is included in the Unity Code Control asset package!
     
  22. hkha

    hkha

    Joined:
    Jul 21, 2012
    Posts:
    6
    Can I use ModelBlobs to save binary data like images ?
    and is there a limit ?
     
  23. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Model(Blobs) can only store serializable data, that means no images! If you want to store images, you should write that functionality yourself in the associated controllers.
     
  24. PyroStudios

    PyroStudios

    Joined:
    Sep 23, 2012
    Posts:
    207
    Hi @softlion

    First I want to say, thanks so much for this asset. It has really come in handy for my project so far.

    My question is related to reusing models for multiple controllers. I know it is possible.. but is it a bad practice to have a single model used on 2 different controllers?
     
  25. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi PyroStudios!

    This is up to you, as you need to manage the instantiation and initialization process of the Controllers yourself.

    I hope this answers your question.
     
    Last edited: Aug 4, 2017
  26. MaddoScientisto

    MaddoScientisto

    Joined:
    Jan 30, 2015
    Posts:
    62
    Hey, I've been using this for years because it was so useful but now the website appears to be offline so the tutorials are gone, any plan to bring them back up?
     
  27. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi MaddoScientisto, cool to hear you've been using Code Control!

    When I check the site it seems to be running fine! Might be that the host took it off for a few hours to perform an update. Let me know if you can reach it now.
     
  28. MaddoScientisto

    MaddoScientisto

    Joined:
    Jan 30, 2015
    Posts:
    62
    Yeah it works now, guess I was just unlucky
     
  29. Spyderworxs

    Spyderworxs

    Joined:
    Aug 21, 2012
    Posts:
    31
    Could you have a look at the product site please? One of the Tutorials: Making a Controller is not working well for me. It tells me

    Error establishing a database connection

    The other two tutorials work well.
     
  30. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi Spyderworxs! Thanks for the heads up.

    Apparently the web provider has been taken over by another company and something went wrong with the transfer. I've contacted them for support, and am now waiting their reply.

    For the mean time I've uploaded a .txt version of the site. Hope that helps.
    http://unitycodecontrol.com/other/Code Control Website.zip
     
  31. Spyderworxs

    Spyderworxs

    Joined:
    Aug 21, 2012
    Posts:
    31
    Thanks for the text website. That will help, much appreciated. Thanks for the great framework. I have used CodeControl often since you released it and it is great!
     
  32. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    That's nice to hear!
     
  33. FBones

    FBones

    Joined:
    Aug 28, 2016
    Posts:
    66
    Hi @softlion,

    I have a question regarding the sample game included in CodeControl. I think my question gets at the deeper subject of whether MVC is strictly a design model for the presentation layer of an app or a general architectural approach.

    My specific question is "Where do the Mode classes in the Behaviors folder fit into the MVC pattern?"

    Should I think of these as residing in a separate, business logic layer of the app, or as being part of the MVC paradigm?
     
  34. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hi FBones!

    Oof that has been quite a while writing the example project of Code Control. I've been using a bunch of different MVC based frameworks since then, and I've come to realise there are many interpetations of the architectural approach.

    I agree with you that the Mode classes of the Code Control example should be considered as the logic layer of the app, not MVC, and can thus be implemented in any way the coder sees fit for their game.

    I hope this answers your question!
     
  35. FBones

    FBones

    Joined:
    Aug 28, 2016
    Posts:
    66
    @softlion , Thanks for the note. I have run into problems using the messaging monitor system.

    I have a small project that uses messages, and it works fine when I run it normally. But when I open the Code Control Monitoring window I get a variety of unexpected behavior:

    1. Most immediately, when I run the game, none of my OnPointerEnter() events work if the Code Control Monitoring window is open. This is true even if the Code Monitoring Window is docked into the editor.

    2. If I maximize the game window mid-play, my OnPointerEnter() events do fire and the game works as expected (but of course I cannot see the window at that point).

    3. If (again mid-play) I then un-Maximize the game window, my OnPointerEnter() events continue to work!! ....but none of my messages show up in the Message monitor.

    I'm attaching a screenshot. I have Console readouts showing messages being sent and received, but nothing shows up in the monitor.

    upload_2018-12-26_16-4-27.png
     
  36. FBones

    FBones

    Joined:
    Aug 28, 2016
    Posts:
    66
    @softlion , just a note that I'm no longer getting the behavior mentioned above.

    Also, I need to buy another seat so that a collaborator can work on this project with me. This guidance appears out of date. Any ideas?
     
  37. softlion

    softlion

    Joined:
    Sep 6, 2013
    Posts:
    100
    Hey FBones,

    I'm afraid I don't know the answer to that question. I think its best to contact Unity Support.
     
unityunity