Setting up Restrictions
With Restrictions you can control the use of namespaces, Types, a Type's members, or inheritance in a Mod.
Restrictions can be applied to all Types, or only Types that derive from a specific Type. Restrictions can either require or prohibit something.
Code will be validated before exporting a Mod and before a Mod is loaded into the game, to make sure mods will be compatible with the game and don't cause issues.
ModTool has a number of default restrictions that are included. These restrictions enforce the use of ModBehaviour and restrict some namespaces like System.IO and System.Reflection.
These restrictions serve both as an example and to support ModTool.Interface They can be removed if they are not needed.
To add a restriction, open ModTool's setting window by going to the ModTool menu.
Here you can see various settings, including restrictions. Adding a Restriction works similarly to how you'd add a new axis in Unity's input manager. You can add a new Restriction by increasing the size of the collection.
A Restriction's message is what will be displayed or logged when the loading or exporting of a Mod fails due to this Restriction.
The applicable base type of a restriction is the base type to which the Restriction will be applied. For example, if you want a restriction to only affect Types that derive from MonoBehaviour, you can configure it here.
When left empty, the Restriction will be applied to all Types.
This restriction will be applied to all Types that derive from MonoBehaviour.
Use the Restriction's RestrictionMode to determine whether the Restriction prohibits or requires the use of something.
For each Restriction you need to provide which member, Type, namespace or base class you want to prohibit or require.
When you want to restrict the use of a property, you need to provide the name of the generated getter and/or setter methods. Usually these are "get_" or "set_" followed by the property name.
Constructors can be restricted by using ".ctor".
The following restriction will require that all Types that derive from MonoBehaviour also derive from GameCode.GameBehaviour. This is a way to make sure the modder will use GameBehaviour instead of MonoBehaviour.