WebRcon-Unity is the official Unity plugin to work with WebRcon. This plugin works as an extension of the official WebRcon-CSharp plugin, and uses it as its core. Hence, this is just an adaptation to be used together with Unity. For a more in-depth guide, please, refer to this readme.
In order to use this plugin, you first need:
- Unity 5.6 or higher
To use this plugin, you can either download the Unity package or copy the contents of Plugins folder into your Unity project.
The folder WebRcon/Resources/ contains the prefab WebRconManager.
When the "Auto Initialize" property is checked, it will be automatically instantiated in your scene when hitting play. The only thing you have to worry about is setting your ckey in the inspector.
If You want to have full control of its initialization, then the following code will suffice:
using SickDev.WebRcon.Unity;
...
WebRconManager.singleton.cKey = "0M6EQVX8PI"; //Only if you haven't set it in the inspector
WebRconManager.singleton.Initialize();
WebRconManager.singleton.onLinked += () => {
//Your code
};
WebRconManager.singleton.console.defaultTab.Log("Hello World!");
The property "WebRconManager.console" references the same WebConsole used by the core WebRcon-CSharp plugin.
To show messages on the web console, call the "Log" method on any "Tab" object. If no other tabs have been created explicitely, you can use the "defaultTab".
To create and send message to another tab, simply call the method "CreateTab".
Tab newTab = WebRconManager.singleton.console.CreateTab("Tab name");
newTab.Log("This message is sent to the new tab");
public static bool IsNumberEven(int number) {
return (number % 2) == 0
}
...
Command command = new FuncCommand<int, bool>(IsNumberEven);
console.commandsManager.Add(command);
Once a command is registered, it can be called from the WebConsole.
Commands management is implemented by the CommandSystem, which allows to parse strings into ready-to-use commands. The CommandSystem already contains a full in-depth guide of how it works, so feel free to read it and familiarize yourself with it.
The connection is automatically closed whenever the WebRconManager object is destroyed, that is, when the game quits. However, the connection can also be closed manually:
WebRconManager.singleton.console.Close();
It is recommended to manually close the connection at the end of the execution of your application.
- "onLinked" : Called when the connection status becomes linked.
- "onUnlinked" : Called when the connection status becomes unlinked.
- "onDisconnected" : Called when the connection status becomes disconnected. Returns the reason as an ErrorCode.
- "onError" : Called from the server when something is wrong. Returns the specific ErrorCode.
- "onExceptionThrown" : Called when an asynchronous operation throws an exception. The exception can come from either plugin source code or from the execution of a custom command.
- "onCommand" : Raised when a command is called from the WebConsole. Use it to manually manage the execution of commands. If no delegate is assigned to this event, the CommandSystem will execute the command automatically.
You can check and uncheck the built-in commands that you want to be bundled with your game through the WebRconManager inspector. Note: When targeting Android, enabling Microhone and Location will also add those same permissions to the final .apk.
Visit WebRcon Website to obtain all needed info.
The cKey is the generated code that will link your application to a WebConsole.
By default, WebRconManager will log any message that would go into the editor’s Console, such as Debug.Log calls, internal messages or exceptions. You can filter what kind of messages gets logged changing the setting "Attached Log Level" on the prefab.
You can find the base C# plugin for WebRcon on Github.
This project is licensed under the MIT License - see the LICENSE file for details
Created by SickDev.