阅读前须知
- 面向群体:基于游戏提供 API 进行开发三方游戏插件的玩家群体
- 知识要求:熟悉 CSharp
- 平台限制:Windows
前置准备 | Visual Studio 开发环境
插件开发的有效环境是在 .NET Framwork 4.8 下进行。任何高于该版本的环境下产出的 .dll
类库文件会在服务器实际运行使用中出现不可处理的程序报错问题。常见如 System.Collection
提示 6.0 不可用等。
前置准备 | 常用引用类库
SL-Lab 是基于 Unity 平台开发的游戏内容。对该平台下的类库有一定程度上的依赖使用。这部分类库获取方式可直接从 游戏安装目录/Managed/Plugin 中获取。
NWPlugin.dll
:插件环境库Assembly-CSharp.dll
:游戏源码库
其他类库:
UnityEngine.dll
Mirror.dll
UnityEngin.CoreMoulde.dll
模版|加载插件
public class AssmeblyLoad
{
[PluginConfig] public AssemblyConfig Config;
public static AssemblyLoad Instance { get; protected set; }
[PluginEvent.Load]
public void Load()
{
if(!Config.IsEnabled) return;
Instance = this;
this.Register(this);
this.Register<AssemblyEvent>(this);
}
}
PluginConfig
:配置特性。 该特性标识 (限制)字段 将在.dll
同目录下生成 .yml 配置文件。PluginEvent.Load
:加载特性。加载插件内容this.Register(this)
:注册执行。 首先注册执行 AssemblyLoad.cs 类,并注册 AssemblyEvent.cs 类。流程如此。- 与之相反为
PluginEvent.UnLoad
卸载特性。
模版|事件内容
public class AssmeblyEvent
{
[PluginServerType.OnPlayerJohned]
public void OnPlayerJohned(PlayerJohnEvent @event)
{
Log.Info($"Player John Round");
}
}
SL-Lab 的数据通讯方式为消息通知处理。如上所示,这是一个限定 [PluginServerType.OnPlayerJohned]
| 玩家加入事件 的发生处理逻辑。关联事件参数 PlayerJohnEvent
。并在事件发生时,日志输出 Player John Round。
- 注意:允许多个同指向
PluginServerType
的方法存在。但应当注意可能造成的逻辑冲突或覆盖问题。
生成|类库
- 右键 项目 - 生成 导出为
.dll
文件 - 前往 解决方案目录下/bin/Debug 目录下获取
.dll
文件
部署|运行目录
前往 Steam 下载 Server Tool 工具,访问本地安装目录下 appdata.bat。在安装目录下选择 PluginAPI/Plugin/Global 或 特定端口服务器。