Getting Started - ParkitectNexus/ParkitectNexusClient GitHub Wiki
Introduction
Creating your first mod is peanuts. You'll only need a few things.
- The ParkitectNexus Client
- Visual Studio or any other c# IDE
- Some Basic C# skills
- Some Git(Hub) skills
- Some Unity knowledge will go a long way
Setup
Make sure that your Parkitect Game has a subfolder named pnmods
. This folder will contain all your downloaded mods and the ones you are going to be developing.
Create a new subfolder in the pnmods
directory, download the ModTemplate repository and extract its contents into your newly created folder.
Next we'll be starting a new project in your C# IDE. To do this in Visual Studio, open Visual Studio, go to 'File' > 'New' > 'Project From Existing Code'. In the newly opened window set the project type to 'Visual C#' and click on Next. Click on the '...' button next to 'Where are the files?' and navigate to your newly created folder. Under 'Specify the details for your new project' set the name of your mod and make sure that the output type is set to 'Class Library'. Now click on Finish.
After the project has been created, add references to Assembly-CSharp.dll
, UnityEngine.dll
and UnityEngine.UI.dll
which are located in (Parkitect Folder)/Parkitect_Data/Managed
. You can add references by right clicking on 'References' under your project in the Solution Explorer > 'Add Reference...' > 'Browse...'
Programming
Now we can write some code, create a class by right clicking on your project in the Solution Explorer > 'Add' > 'Class...' and name it, for example Main
. Let the newly created class extend from IMod
and implement all missing members. Make sure the class is marked as public
.
Create a new class ExampleBehaviour
, let it extend MonoBehaviour
and paste the following methods into this class:
void Start()
{
StartCoroutine(SpawnGuests());
}
private IEnumerator SpawnGuests()
{
for (;;)
{
GameController.Instance.park.spawnGuest();
yield return new UnityEngine.WaitForSeconds(1);
}
}
Don't forget the imports at the top of your file:
using UnityEngine;
using System.Collections;
The above code will spawn a new guest every second.
Now go back to your Main
class and place the following code within it:
private GameObject _go;
public void onEnabled()
{
_go = new GameObject();
_go.AddComponent<ExampleBehaviour>();
}
public void onDisabled()
{
UnityEngine.Object.Destroy(_go);
}
public string Name
{
get { return "Mod name"; }
}
public string Description
{
get { return "Mod description"; }
}
public string Identifier{ get; set; }
Don't forget the imports at the top of your file:
using UnityEngine;
The method onEnabled
will be called when the game is loading a level, before the loading of the save starts. onDisabled
will be called when the player quits the game, just before saving. The Mod Loader will automatically register your mod to the game (provided that the user has enabled the mod).
You need to make sure onDisabled actually cleans up all the things you added or changed, otherwise the game might crash when the user loads a new game and hot reloading won't work and that will make mod development a lot harder.
Now the only thing that's left to do is to configuring the mod.json
configuration file so the Mod Loader knows how to register your mod in the game.
{
"BaseDir": "",
"IsDevelopment": true,
"Name": "Your First Mod",
"Project": "YourMod.csproj"
}
for more information on the options available in mod.json
, click here
Now save your project, in visual studio 'File' > 'Save all'.
Compiling
Compiling isn't needed, the mod launcher will handle that. But you can always use the compiler of your IDE to test if your code is valid.
Start your engines
Now start the ParkitectNexus Client and check if your mod is installed. If you now launch the game with mods and start a new game, you'll find a new guest spawning every second!