Changes

Jump to navigation Jump to search
586 bytes added ,  18:00, 6 June 2020
Added a ModMeta example
Line 21: Line 21:     
The ModMeta class will contain information about your mod and act as a manager for your mod.
 
The ModMeta class will contain information about your mod and act as a manager for your mod.
 +
<pre>
 +
namespace myMod
 +
{
 +
  internal class MyModMeta : ModMeta
 +
    {
 +
        public override void ConstructOptionsScreen(RectTransform parent, bool inGame)
 +
        {
 +
            Text text = WindowManager.SpawnLabel();
 +
            text.text = "This is the description of my mod\nIt shows in dropdown 'My Mod!' in the 'Mods' section of the options area.";
 +
            WindowManager.AddElementToElement(text.gameObject, parent.gameObject, new Rect(0f, 0f, 400f, 128f),
 +
                new Rect(0f, 0f, 0f, 0f));
 +
        }
 +
 +
        public override string Name => "My Mod!";
 +
    }
 +
}
 +
</pre>
    
ModBehaviours are just a subclass of Unity's [https://docs.unity3d.com/2017.4/Documentation/ScriptReference/MonoBehaviour.html MonoBehavior] and work the same way, i.e. they use the same life cycle of Awake, Start, Update, OnDestroy, ModBehaviours only differ in that they have the abstract OnActive and OnDeactive methods, to signal when the mod is toggled. You should stick to the Update method, rather than trying to write your own update loop, as you cannot interact with Unity's system from other threads. Each ModBehaviour implementation will be instantiated once the mod is loaded.
 
ModBehaviours are just a subclass of Unity's [https://docs.unity3d.com/2017.4/Documentation/ScriptReference/MonoBehaviour.html MonoBehavior] and work the same way, i.e. they use the same life cycle of Awake, Start, Update, OnDestroy, ModBehaviours only differ in that they have the abstract OnActive and OnDeactive methods, to signal when the mod is toggled. You should stick to the Update method, rather than trying to write your own update loop, as you cannot interact with Unity's system from other threads. Each ModBehaviour implementation will be instantiated once the mod is loaded.
    
== Compile ==
 
== Compile ==
When you're done, you can either compile your mod and place it in the game's folder, in a subfolder called "DLLMods", or create a new subfolder in the "DLLMods" folder and put your .cs files in that subfolder, and the game will compile them for you. Note that if you let the game compile the C# files for you, you are limited to C# version 3, but '''using the game's compiler is required, if you want to upload your mod to the Steam Workshop'''.
+
When you're done, you can either compile your mod and place it in the game's folder, in a subfolder called "DLLMods", or create a new subfolder in the "DLLMods" folder and put your .cs files in that subfolder, and the game will compile them for you. Note that if you let the game compile the C# files for you, you are limited to C# version 3, but '''using the game's compiler is required if you want to upload your mod to the Steam Workshop'''.
    
'''Please note that due to a bug in the compiler the game uses, you cannot use enums if you are using straight .cs files or the game will crash'''
 
'''Please note that due to a bug in the compiler the game uses, you cannot use enums if you are using straight .cs files or the game will crash'''
    
== Example mod ==
 
== Example mod ==
Here's an example of a mod that let's you change how many floors you can build on, complete with comments:
+
Here's a working mod example that lets you change how many floors you can build on, complete with comments:
 
[http://swinc.net/FloorMod.zip Floor Mod] (Updated to work with Alpha 10.7+)
 
[http://swinc.net/FloorMod.zip Floor Mod] (Updated to work with Alpha 10.7+)
    
== Full access ==
 
== Full access ==
By default certain namespaces and types are off limits to mods for security reasons. If you want to make a mod that writes to files or accesses the internet, you need to put a public static bool called GiveMeFreedom in your ModMeta implementation. Note that this only works for dll-based mods, which can't be uploaded to the Steam Workshop, and the user will be warned.
+
By default, certain namespaces and types are off-limits to mods for security reasons. If you want to make a mod that writes to files or accesses the internet, you need to put a public static bool called GiveMeFreedom in your ModMeta implementation. Note that this only works for dll-based mods, which can't be uploaded to the Steam Workshop, and the user will be warned.
    
= Entry points =
 
= Entry points =
52

edits

Navigation menu