Making your first plugin¶
In this guide we will cover:
- Setting up development environment.
- Creating a plugin project.
- Writing a basic plugin.
Installing the IDE for coding¶
Visual Studio Code¶
You can install install Visual Studio Code with the Omnisharp extension for developing plugins. Visual Studio Code is much lightweighter and faster then a full Visual Studio installation. It is optimal for small-mid size projects.
Visual Studio¶
If you want a full IDE experience, download and install Visual Studio Community Edition. When the installer starts, select "Visual Studio 2022 Community Edition" (or newer). After that select the .NET Desktop Development option and press install/modify.
Making a plugin from scratch¶
First create new "Class Library (.NET Framework)" in Visual Studio. Remember to select Framework to .NET Framework 4.6.1
The next step is to add Unturned and Rocket's binaries to your project.
You should make a new directory inside your project folder called Libraries
or libs
, and copy the following files over from the Unturned\Unturned_Data\Managed\
directory:
- Assembly-Csharp.dll
- SDG.NetTransport.dll
- com.rlabrecque.steamworks.net.dll
- UnityEngine.dll
- UnityEngine.CoreModule.dll
aswell as the Rocket binaries from Unturned\Extras\Rocket.Unturned\
:
- Rocket.Core.dll
- Rocket.API.dll
- Rocket.Unturned.dll
Now in Visual Studio's solution explorer right click on References and press Add Reference. Then browse for RocketMod and Unturned libraries that you saved in your projects directory, select and add them.
After that rename the pre-existing Class1.cs file to ExamplePlugin.cs from the solution explorer. On the top of the file add using Rocket.Core.Plugins
.
We're now gonna start by making ExamplePlugin inherit from RocketPlugin
, so your ExamplePlugin.cs
should look like this now.
using Rocket.Core.Plugins;
namespace ExamplePlugin
{
public class ExamplePlugin : RocketPlugin
{
}
}
Now for the beginning we're gonna send a basic logger message when the plugin loads and unloads. For that you have to override void Load()
and void Unload()
methods like below and add your message.
Note
I've added 2 more usings to the top of ExamplePlugins.cs
(System
and Rocket.Core.Logging
)
using System;
using Rocket.Core.Logging;
using Rocket.Core.Plugins;
namespace ExamplePlugin
{
public class ExamplePlugin : RocketPlugin
{
protected override void Load()
{
Logger.Log($"{Name} {Assembly.GetName().Version} has been loaded!", ConsoleColor.Yellow);
}
protected override void Unload()
{
Logger.Log($"{Name} has been unloaded!", ConsoleColor.Yellow);
}
}
}
Note
Assembly.GetName().Version
returns your Assembly Version. You can change it in AssemblyInfo.cs
. You can find under Properties
in Visual Studio's solution explorer.