Search Unity

Making a Moddable Game?

Discussion in 'Editor & General Support' started by Tyler-Jaacks, Mar 20, 2015.

  1. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    @Tomnnn: Sorry to hear about that =(. No worries though! I'll test it sometime in the future out of curiosity but there is no immediate need of mine to check it.
     
    Tomnnn likes this.
  2. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Assemblies will work on Mac because of Mono. They work on Linux which has completely different format for dynamic libraries. Without recompilation. So they would work on Mac too, because Mono is same everywhere.

    The thing is assemblies contain .NET/Mono bytecode so Mono doesn't have any issues with that.

    Anyway, making modding tools for my game is going fairly well. Now I need to add moving things around, i.e. widgets. Cool.
     
    CWolf likes this.
  3. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    It's like java and flash :eek:
     
  4. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Not like Flash. Flash isn't available for Linux and Android (not sure about iOS since I'll never touch Crapple). Mono is.
     
  5. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I was including AIR in "write once, compile everywhere" :p I'm pretty sure android has AIR (but the java7 update breaks the flash->AIR compiler) and I'm not sure about linux.
     
  6. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    340
    Hey, a great discussion here. I finally managed to put the thoughts in my mind about modding in an appropiate way.

    I have a question for you guys, more like requesting a suggestion:
    I am building an RTS game right now, and I decided to load everything externally as you guys suggested.
    But I hesitate to leave the Main Menu built-in, in a way that it can't be modded. Should I also load Main Menu externally too, or should it stay built-in?
     
  7. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    I think you can left it built in. What would be use of modding main menu anyway?
     
  8. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    LUA is great, but i suggest to have a look to Jurassic... you'll be pleasantly surprised.

     
    Last edited: Apr 12, 2016
  9. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    340
    Yea, I guess you are right.

    @ZJP
    Actually this also seems pretty neat to me: CS-Script for Unity
     
  10. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Yes. A good one. ;)
     
  11. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    @s.ta.c. In our situation we use Chromium (think: Chrome web browser) to render HTML, Javascript and CSS as our user interface. Due to this we expose all the html, css and js files to the player / modders. We developed a framework that links that to our Lua modding core. We use CoherentUI as our middleware but there are similar HTML UI frameworks on the asset store, or you could even integrate CEF if you're good at coding =).

    This way the main menu UI (and every other UI in the game) is moddable.
     
  12. McMayhem

    McMayhem

    Joined:
    Aug 24, 2011
    Posts:
    443
    Wish I could like this about 100 more times. You really do have to build the core gameplay elements with modding in mind if you want your game to support the kind of mods seen in Bethesda games.

    Currently, I've recreated the Aurora engine (NWN/Knights of the Old Republic) for my game mechanics and modding structure. I think someone mentioned it before, having directories where you can place assets to override in-game data. That's perfectly possible using the StreamingAssets directory. From there you can load a good amount of data. Though the real restriction comes when trying to have user-created scripts. For that, you'd have to implement something like @CWolf explained in his first post.

    I've been looking into the assembly method myself, and asset bundles as a whole, but I'm hoping that among the "Asset Bundle Improvements" that have been announced by UT is a more streamlined method for allowing C# scripts to be loaded at runtime.

    Also, XML files are lovely for storing custom tabular data. If you don't like the look of .xml at the end of all your files, you can always save it as a custom file type :).
     
    CWolf likes this.
  13. tiggus

    tiggus

    Joined:
    Sep 2, 2010
    Posts:
    1,240
  14. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  15. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    340
    I also wonder, is that a good idea to represent Unity Editor as the level editor tool to players? Or should one make their own level editor?
     
  16. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    @s.ta.c. Making any kind of editor is a large investment in time (which means 'money') and energy. All depends on how determined you are and what your goals are. For a small team, I'd usually advise to keep things simple and rarely develop your own tech or tools.

    That being said, if you want to present a unified front and keep everything 'in-house' so the player/modder never needs to know anything about Unity - then make your tools.
     
    s-ta-c and McMayhem like this.
  17. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Kerball simply wrote a small editor extension for Unity. Seems like the smart way to go to me.
     
    s-ta-c and McMayhem like this.
  18. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Well, for my game I've decided to create my own editor so people won't have to install/download separate app just to mod my game (literally, level editor is accessible from the main menu of the game which also serves as "playground" so the players can get acclimated to the controls).

    I'd probably save some time by writing Unity extension, but at the same time it wouldn't be so easy for the players to get into and having to download Unity (and the very same version game was build with on top of that) may deter some people from modding, just like I was deterred for that reason from modding Kerbals and SimplePlanes. And since editor is basically written, I can take care of content building now.
     
  19. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Both looks cool, though I'd prefer if someone would make Common Lisp interpreter for Unity. I mean, some guys have done it (as quick google can prove it), but that implementation isn't out in the wild so to speak.

    And obviously with ability to create callbacks and making it so if Lisp interpreter would encounter specific S-expression it would call C# side of things.
     
  20. kawaishiru360

    kawaishiru360

    Joined:
    Dec 17, 2017
    Posts:
    6
    here is some of the code i use to do it, feel free to use (sorry for necro positing but here is an answer)
    Code (CSharp):
    1. using Microsoft.CSharp;
    2. using System;
    3. using System.CodeDom.Compiler;
    4. using System.Reflection;
    5. using System.Text;
    6. using UnityEngine;
    7.  
    8. public class CustomCode : MonoBehaviour
    9. {
    10.     public string Name = "CUSTOM.CODE";
    11.     public string Code = @"using System.Collections; using System.Collections.Generic; using UnityEngine; namespace CUSTOM { public class CODE : MonoBehaviour{ public string Hi = ""hello""; public static CUSTOM.CODE AddYourselfTo(GameObject host) { return host.AddComponent<CUSTOM.CODE>(); } public void Start() { Debug.Log(""I started!""); } public void Update() { Debug.Log(""I Updated!""); } } }";
    12.  
    13.     void Start()
    14.     {
    15.         var assembly = Compile(Code);  
    16.  
    17.         var runtimeType = assembly.GetType(Name);
    18.         var method = runtimeType.GetMethod("AddYourselfTo");
    19.         var del = (Func<GameObject, MonoBehaviour>)
    20.                       Delegate.CreateDelegate(
    21.                           typeof(Func<GameObject, MonoBehaviour>),
    22.                           method
    23.                   );
    24.         var addedComponent = del.Invoke(gameObject);
    25.     }
    26.  
    27.     public static Assembly Compile(string source)
    28.     {
    29.         var provider = new CSharpCodeProvider();
    30.         var param = new CompilerParameters();
    31.  
    32.         foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
    33.         {
    34.             if (assembly.IsDynamic == false){
    35.                 param.ReferencedAssemblies.Add(assembly.Location);
    36.             }
    37.         }
    38.  
    39.         param.GenerateExecutable = false;
    40.         param.GenerateInMemory = true;
    41.  
    42.         var result = provider.CompileAssemblyFromSource(param, source);
    43.  
    44.         if (result.Errors.Count > 0) {
    45.             var msg = new StringBuilder();
    46.             foreach (CompilerError error in result.Errors) {
    47.                 msg.AppendFormat("Error ({0}): {1}\n",
    48.                     error.ErrorNumber, error.ErrorText);
    49.             }
    50.             Debug.Log(msg.ToString());
    51.         }
    52.  
    53.         return result.CompiledAssembly;
    54.     }
    55. }
    there you go! it adds in the string as a C# script onto the object and runs like any other script.

    You can probably figure out how to use this for your own use.
     
    bb8_1 and GibTreaty like this.