-
Notifications
You must be signed in to change notification settings - Fork 3
Tutorial: Writing a simple module
To understand the main focus of the library, we first need to think about Class Inheritance.
Normally, a modded module's class definition would look like this...
public class Foo : MonoBehaviour
In this case, Foo
inherits from MonoBehaviour
. This means that everything inside MonoBehaviour
gets carried over to Foo
.
To get the main functionalities of the library, we will be inheriting from a different class from this library.
public class Foo : ModuleScript
Now, everything from ModuleScript
gets pulled into Foo
!
But wait, are we not inheriting from MonoBehaviour
anymore? How can we attach this into Unity?
In this case it's fine, because if we look at ModuleScript
's definition...
public abstract class ModuleScript : CacheableBehaviour, IDump, ILog
...then look at CacheableBehaviour
's definition...
public class CacheableBehaviour : MonoBehaviour
...it eventually inherits MonoBehaviour
!
There are 2 such classes you inherit from in this library...
-
ModuleScript
: The class for creating either a regular or needy modded module in Keep Talking and Nobody Explodes. This one is required. -
TPScript<TModule>
: The class for implementing Twitch Plays support into any existing module. This one is optional.
Both scripts are attached to the module prefab.