### 【模组详细说明与实操指南】
# LethalCompany 输入实用程序
用于创建输入动作并使其可在游戏中访问的实用程序。
通过此 mod 创建的输入操作可以通过更新 v45 中添加的按键绑定菜单在游戏中访问。
#### 对于功能请求或问题,请前往我的repo
## 一般用户
这个mod只是其他mod的依赖,它不添加内容,但它允许mod添加按键绑定。
### 我的绑定覆盖存储在哪里?
取决于InputUtils的版本:
- **>= 0.7.0** 全局:`AppData/LocalLow/ZeekerssRBLX/Lethal Company/InputUtils/controls` 本地:`BepInEx/config/controls`
- **>= 0.4.1** `BepInEx/config/controls`
- **<= 0.4.0** `BepInEx/控件`
### 致命的公司版本支持
InputUtils 仅_官方_支持 Lethal Company 的最新版本,除非有公开测试版,在这种情况下,非测试版和测试版都包含在内。
InputUtils 仅保证在这些版本上工作,我不支持旧版本的 Lethal Company 和 InputUtils,并且不会为使用旧版本的 Lethal Company 时发现的问题提供支持。
如果您选择使用不受支持的 Lethal Company 版本,您需要自行承担风险。
### 推荐安装
使用 Mod 管理器。如果不使用 mod 管理器,我不会提供支持,mod 管理器使调试问题变得更加容易,因为用户只需共享 modpack 代码。
## 开发者快速入门
*此 Api/Mod 仍处于测试阶段,请记住,内容可能会发生变化。*
感谢您的反馈。
如果您想要复制和粘贴解决方案,请将 nuget 包添加到您的项目中:
将其添加到您的项目 `.csproj`
```xml
<项目组>
<!-- 确保 'Version="..."' 设置为最新版本 -->
<PackageReference Include="Rune580.Mods.LethalCompany.InputUtils" Version="0.7.10" />
</项目组>
````
这应该就是您开始所需的全部内容。
否则,如果您不想使用 nuget,则可以从 Thunderstore 或 Releases 下载最新版本。
解压 zip 并在 Visual Studio 或 Rider 中添加对 mod 的 dll 文件的引用。
### 初始化您的绑定
- 创建“LcInputActions”的**子类**
- 此类的实例将包含您的 mod 希望绑定输入的所有“InputAction”
- 适当地命名类
- 创建 InputActions 使用属性 和/或 在运行时
```csharp
public class MyExampleInputClass : LcInputActions
{
[InputAction(KeyboardControl.G, Name = "Explode")]
public InputAction ExplodeKey { get; set; }
[InputAction("<Keyboard>/h", Name = "Another")]
public InputAction AnotherKey { get; set; }
}
```
### 使用属性
- **为所有所需的“InputActions”创建实例属性**
- **使用“[InputAction(...)]”注释来注释实例属性
> [!重要]
> 对于要注册到 API 的操作,**属性必须使用 `[InputAction(...)]`** 进行注释
>```csharp
>[InputAction("YourkbmPath" /* 您还可以使用 KeyboardControl 或 MouseControl */, Name = "", GamepadPath = "", GamepadControl = GamepadControl.None, KbmInteractions = "", GamepadInteractions = "", ActionID = "", ActionType = InputActionType...)]
>```
#### 所需参数
您只需使用以下重载中的**一个**:
* `kbmPath`:键盘和鼠标设备的默认绑定
* `keyboardControl`:键盘设备的默认绑定,使用 KeyboardControl 枚举
* `mouseControl`:鼠标设备的默认绑定,使用 MouseControl 枚举
#### 可选参数
* `Name`:游戏按键绑定菜单中显示的文本
* `GamepadPath` **_or_** `GamepadControl`:游戏手柄设备的默认绑定。当两者都设置时,“GamepadPath”将优先。
* `KbmInteractions`:设置 kbm 绑定的交互。请参阅交互文档
* `GamepadInteractions`:设置游戏手柄绑定的交互。请参阅交互文档
* `ActionID`:覆盖生成的actionId(通常你不想更改它)
* `ActionType`:确定操作触发的行为。请参阅 ActionType 文档
所以你的属性可以这样写:
``csharp
[InputAction(KeyboardControl.Minus, Name = "爆炸")]
公共InputAction ExplodeKey { 获取;放; }
````
或者使用可选参数的任意组合:
``csharp
[InputAction(KeyboardControl.Minus, Name = "爆炸", GamepadControl = GamepadControl.ButtonNorth, KbmInteractions = "按住(持续时间 = 5)")]
公共InputAction ExplodeKey { 获取;放; }
````
> [!注意]
> 在上面的例子中,使用了保持交互。该按键绑定在按住 *5* 秒后触发。请参阅交互文档
### 在运行时
- **重写方法** `void CreateInputActions(在InputActionMapBuilder构建器中)`
- 使用构建器创建InputActions
- **通过在类中调用`Asset["actionId"]`来引用InputAction**
> [!重要]
> 确保在创建完每个 InputAction 后调用 `Finish()`。
这是运行时 api 的示例用法
``csharp
公共类 MyExampleInputClass :LcInputActions
{
公共静态只读 MyExampleInputClass 实例 = new();
public InputAction ExplodeKey => Asset["explodekey"];
公共覆盖无效CreateInputActions(在InputActionMapBuilder构建器中)
{
构建器.NewActionBinding()
.WithActionId("爆炸键")
.WithActionType(InputActionType.按钮)
.WithKeyboardControl(KeyboardControl.J) // 或 .WithKbmPath("<Keyboard>/j")
.WithGamepadControl(GamepadControl.ButtonNorth) // 或 .WithGamepadPath("<Gamepad>/buttonNorth")
.WithBindingName("爆炸")
。结束();
}
}
````
> [!重要]
> 省略 `WithGamepadControl`、`WithGamepadPath` 或 `WithGamepadUnbound` 将禁用将 `InputAction` 绑定到游戏手柄设备。
> 同样,省略 `WithKeyboardControl`、`WithMouseControl`、`WithKbmPath` 或 `WithKbmUnbound` 将禁用将 `InputAction` 绑定到键盘或鼠标设备。
### 引用您的绑定
要使用您的 InputActions 类,您需要实例化它。
> [!重要]
> **不要**创建多个 InputActions 类的实例。
> 如果您的类被实例化多次,您的 InputActions 不太可能按预期工作。
最简单(自以为是)的方法是在插件类中拥有一个静态实例。
``csharp
[BepInPlugin(...)]
[BepInDependency("com.rune580.LethalCompanyInputUtils", BepInDependency.DependencyFlags.HardDependency)]
公共类 MyExamplePlugin :BaseUnityPlugin
{
内部静态 MyExampleInputClass InputActionsInstance;
公共无效唤醒()
{
InputActionsInstance = new MyExampleInputClass();
}
}
````
### 使用你的绑定
然后,您可以在需要执行操作的任何地方简单地引用该实例。
``csharp
公共类 MyOtherClassOrMonoBehavior
{
公共无效DoSomething()
{
MyExamplePlugin.InputActionsInstance.ExplodeKey ...
}
}
````
或者
``csharp
公共类 MyOtherClassOrMonoBehavior
{
公共无效DoSomething()
{
MyExampleInputClass.Instance.ExplodeKey ...
}
}
````
#### 最佳实践
教程中经常会看到单行为“Update()”函数调用“InputAction.ReadValue<>()”或“InputAction.triggered”。
``csharp
公共类 MyOtherClassOrMonoBehavior
{
公共无效更新()
{
做某事();
}
公共无效DoSomething()
{
if (!MyExamplePlugin.InputActionsInstance.ExplodeKey.triggered) 返回;
//这里是你的执行代码
}
}
````
这种方法足以进行“连续”操作,例如移动。
对于“离散”操作,更适合创建接受“InputAction.CallbackContext”的事件侦听器
并订阅“InputAction.performed”。
``csharp
公共类 MyOtherClassOrMonoBehavior
{
公共无效唤醒()
{
设置KeybindCallbacks();
}
// 随意命名。它需要被调用一次,所以
公共无效SetupKeybindCallbacks()
{
MyExamplePlugin.InputActionsInstance.ExplodeKey.performed += OnExplodeKeyPressed;
}
公共无效OnExplodeKeyPressed(InputAction.CallbackContextexplodeConext)
{
if (!explodeConext.performed) 返回;
// 如果需要添加更多上下文检查
// Your executing code here
}
}
````
### 使用 InputUtils 作为可选或软依赖项
首先确保将 `[BepInDependency(...)]` 属性添加到您的 mods 插件类中,将其标记为 `SoftDependency`。
如果您已经将该属性设置为“HardDependency”,请确保将其替换。
``csharp
[BepInPlugin(...)]
[BepInDependency("com.rune580.LethalCompanyInputUtils", BepInDependency.DependencyFlags.SoftDependency)]
公共类 MyExamplePlugin :BaseUnityPlugin
````
按照上面的指南创建您的 InputActions 类。
专门为加载 mod 时创建一个类
``csharp
内部静态类InputUtilsCompat
{
公共静态布尔已启用=>
BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey("com.rune580.LethalCompanyInputUtils");
公共静态InputAction ExplodeKey =>
MyExampleInputClass.Instance.ExplodeKey;
}
````
最后,每当您引用“InputUtilsCompat”中的内容时,请务必先检查其“Enabled”属性。
``csharp
if (InputUtilsCompat.Enabled)
InputUtilsCompat.ExplodeKey...
````
有关如何最好地使用 InputAction 的详细信息,请参阅最佳实践
> [!重要]
> #### 如果您的 mod 使用 NetcodePatcher,您可能需要执行其他步骤。
> **这仅适用于使用 InputUtils 作为软依赖项的 mods**
>
> 请查看他们的自述文件以获取更多信息。
> 然而,为了可能的修复,请更换
> ```csharp
> var types = Assembly.GetExecutingAssembly().GetTypes();
> ```
> 与
> ```csharp
> IEnumerable<Type> 类型;
> 尝试
> {
> 类型 = Assembly.GetExecutingAssembly().GetTypes();
> }
> catch (ReflectionTypeLoadException e)
> {
> types = e.Types.Where(t => t != null);
> }
> ```
### 下一步
查看 Unity 的 [InputSystem] 文档(https://docs.unity3d.com/Packages/com.unity.inputsystem@1.7/manual/index.html)
## 构建说明
克隆并输入存储库。
````外壳
git克隆 https://github.com/Rune580/LethalCompanyInputUtils && cd LethalCompanyInputUtils
````
(可选)复制“LethalCompanyInputUtils.csproj.user.example”并将其重命名为“LethalCompanyInputUtils.csproj.user”。
编辑 `LethalCompanyInputUtils/LethalCompanyInputUtils.csproj.user` 以满足您的需求。
````外壳
cp LethalCompanyInputUtils/LethalCompanyInputUtils.csproj.user.example LethalCompanyInputUtils/LethalCompanyInputUtils.csproj.user
````
使用您选择的 IDE 或使用以下命令构建项目
````外壳
点网构建
````
## 接触
不和谐:@rune
GitHub:Rune580
## 贡献
进行 PR 时,请确保您的更改位于不同的分支上。不要在“master”分支上对您的更改进行 PR。
## 贡献者
感谢以下贡献者:
- @Boxofbiscuits97 用于修改大部分文档。
- @Lordfirespeed 用于内务管理和其他文档清理。
- @Singularia - 俄语翻译。
## 制作人员
- 重置为默认图标:@AinaVT
- PS5、Xbox Series X、Switch Glyph 源文件来自:https://thoseawesomeguys.com/prompts/
- 鼠标字形源文件来自:https://www.kenney.nl/assets/input-prompts
### 【联机规则与注意事项】
* **联机兼容性**:【客户端个人可用】(仅自己安装即可生效,不强制队友安装,不影响进纯净野队)
* **前置依赖需求**:BepInEx-BepInExPack-5.4.2305
* **当前模组版本**:`0.7.14`
* **适配版本**:针对《致命公司》2026 最新稳定版(v68+)整理适配