# LethalCompany InputUtils
Utilities for creating InputActions and having them be accessible in-game.
InputActions created through this mod are accessible in-game via the keybinds menu added in update v45.
#### For feature requests or issues head over to my [repo](https://github.com/Rune580/LethalCompanyInputUtils)
## General Users
This mod is just a dependency for other mods, it doesn't add content, but it allows mods to add keybinds.
### Where are my bind overrides stored?
Depends on the version of InputUtils:
- **>= 0.4.1** `BepInEx/config/controls`
- **<= 0.4.0** `BepInEx/controls`
### Recommended Install
Use a Mod manager. I won't provide support if a mod manager wasn't used, a mod manager makes it far easier to debug issues since users can just share a modpack code.
## Developer Quick-Start
*This Api/Mod is still in beta, please keep in mind that stuff may change.*
Feedback is appreciated.
Download the latest release from either the [Thunderstore](https://thunderstore.io/c/lethal-company/p/Rune580/LethalCompany_InputUtils) or the [Releases](https://github.com/Rune580/LethalCompanyInputUtils/releases).
Extract the zip and add a reference to the dll file of the mod in Visual Studio or Rider.
### Initializing Your Binds
- Create a **subclass of `LcInputActions`**
- An instance of this class will contain all `InputAction`s your mod wishes to bind inputs for
- Name the class appropriately
- Create InputActions [using Attributes](#using-attributes) and/or [at Runtime](#at-runtime)
```csharp
public class MyExampleInputClass : LcInputActions
{
[InputAction("<Keyboard>/g", Name = "Explode")]
public InputAction ExplodeKey { get; set; }
[InputAction("<Keyboard>/h", Name = "Another")]
public InputAction AnotherKey { get; set; }
}
```
### Using Attributes
- **Create instance properties** for all desired `InputActions`
- **Annotate** the instance properties with the `[InputAction(...)]` annotation
> [!IMPORTANT]
> For actions to be registered to the API, **Properties MUST be annotated with `[InputAction(...)]`**
>```csharp
>[InputAction("YourkbmPath", Name = "", GamepadPath = "", KbmInteractions = "", GamepadInteractions = "", ActionID = "", ActionType = InputActionType...)]
>```
#### Required Parameters
* `kbmPath`: The default bind for Keyboard and Mouse devices
#### Optional Parameters
* `Name`: The Displayed text in the game keybinds menu
* `GamepadPath`: The default bind for Gamepad devices
* `KbmInteractions`: Sets the interactions of the kbm binding. See [Interactions Docs](https://docs.unity3d.com/Packages/com.unity.inputsystem@1.7/api/UnityEngine.InputSystem.Interactions.html)
* `GamepadInteractions`: Sets the interactions of the gamepad binding. See [Interactions Docs](https://docs.unity3d.com/Packages/com.unity.inputsystem@1.7/api/UnityEngine.InputSystem.Interactions.html)
* `ActionID`: Overrides the generated actionId (Generally you don't want to change this)
* `ActionType`: Determines the behavior with which the action triggers. See [ActionType Docs](https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.InputActionType.html)
So your Attribute could be written like this:
```csharp
[InputAction("<Keyboard>/minus", Name = "Explode")]
public InputAction ExplodeKey { get; set; }
```
Or with any combination of optional parameters:
```csharp
[InputAction("<Keyboard>/minus", Name = "Explode", GamepadPath = "<Gamepad>/Button North", KbmInteractions = "hold(duration = 5)")]
public InputAction ExplodeKey { get; set; }
```
> [!NOTE]
> In this case above the Hold Interaction is being used. This keybind triggers after being held for *5* seconds. See [Interactions Docs](https://docs.unity3d.com/Packages/com.unity.inputsystem@1.7/api/UnityEngine.InputSystem.Interactions.html)
### At Runtime
- **Override Method** `void CreateInputActions(in InputActionMapBuilder builder)`
- Use the builder to create InputActions
- **Reference InputAction** by calling `Asset["actionId"]` in your class
> [!IMPORTANT]
> Make sure you call `Finish()` after you're done creating each InputAction.
Here's an example usage of the runtime api
```csharp
public class MyExampleInputClass : LcInputActions
{
public static readonly MyExampleInputClass Instance = new();
public InputAction ExplodeKey => Asset["explodekey"];
public override void CreateInputActions(in InputActionMapBuilder builder)
{
builder.NewActionBinding()
.WithActionId("explodekey")
.WithActionType(InputActionType.Button)
.WithKbmPath("<Keyboard>/j")
.WithBindingName("Explode")
.Finish();
}
}
```
### Referencing Your Binds
To use your InputActions class, you need to instantiate it.
> [!IMPORTANT]
> Do **not** create more than one instance of your InputActions class.
> If your class is instantiated more than once, your InputActions are unlikely to work as intended.
The easiest (opinionated) way to do so would be to have a static instance in your plugin class.
```csharp
[BepInPlugin(...)]
[BepInDependency("com.rune580.LethalCompanyInputUtils", BepInDependency.DependencyFlags.HardDependency)]
public class MyExamplePlugin : BaseUnityPlugin
{
internal static MyExampleInputClass InputActionsInstance = new MyExampleInputClass();
}
```
You could also opt for instantiating the instance in the InputActions class (Singleton-style).
```csharp
public class MyExampleInputClass : LcInputActions
{
public static MyExampleInputClass Instance = new();
[InputAction("explodekey", "<Keyboard>/j", "<Gamepad>/Button North", Name = "Explode")]
public InputAction ExplodeKey { get; set; }
}
```
> [!IMPORTANT]
> #### But How Do I Get My Binds String?
> You may have noticed that `<keyboard>/yourKey` can be a little confusing for the special buttons. So try this:
> 1. First, arbitrarily set the value to some regular value or just an empty string
> 2. Then, load up your mod and change the keybind to the desired key
> 3. After, look in your `.../BepInEx/controls/YOURMODID.json` file
> 4. Find the `{"action":"myaction","origPath":"","path":"<Keyboard>/f8"}]}`
> 5. Last, copy that `path:""` from the far right i.e. `"<Keyboard>/f8"`
### Using Your Binds
You could then simply reference the instance anywhere you need to have your actions at.
```csharp
public class MyOtherClassOrMonoBehavior
{
public void DoSomething()
{
MyExamplePlugin.InputActionsInstance.ExplodeKey ...
}
}
```
or
```csharp
public class MyOtherClassOrMonoBehavior
{
public void DoSomething()
{
MyExampleInputClass.Instance.ExplodeKey ...
}
}
```
#### Best Practices
It is common to see tutorials call `InputAction.ReadValue<>()` or `InputAction.triggered` from mono-behaviour `Update()` functions.
```csharp
public class MyOtherClassOrMonoBehavior
{
public void Update()
{
DoSomething();
}
public void DoSomething()
{
if (!MyExamplePlugin.InputActionsInstance.ExplodeKey.triggered) return;
//Your executing code here
}
}
```
This approach is sufficient for 'continuous' actions, e.g. movement.
For 'discrete' actions, it's more appropriate to create event listeners that accept an `InputAction.CallbackContext`
and subscribe to `InputAction.performed`.
```csharp
public class MyOtherClassOrMonoBehavior
{
public void Awake()
{
SetupKeybindCallbacks();
}
// Name this whatever you like. It needs to be called exactly once, so
public void SetupKeybindCallbacks()
{
MyExamplePlugin.InputActionsInstance.ExplodeKey.performed += OnExplodeKeyPressed;
}
public void OnExplodeKeyPressed(InputAction.CallbackContext explodeConext)
{
if (!explodeConext.performed) return;
// Add more context checks if desired
// Your executing code here
}
}
```
### Using InputUtils as an Optional or Soft Dependency
First make sure to add the `[BepInDepe
V49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.ra
需积分: 0 135 浏览量
更新于2024-01-18
收藏 298.33MB RAR 举报
V49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.0.2.rarV49 9.
酸奶公园
- 粉丝: 843
- 资源: 51
最新资源
- proxy arp自动配置-关闭-适用于openwr
- 在线书店AB测试数据集.zip
- 多目标优化算法 有基于粒子群的 遗传的多目标粒子群优化算法,代码都可以运行,通用性良好
- 产品实践-怎么去进行竞品分析
- APQP开发审核资料 1.经过大众、上汽、小鹏、雷诺的体系审核 2.结合AIAG APQP手册、VDA6.3、VDA4.3、PMP进行整合编制(优化) 3.标准化模板,层次清晰,五大阶段依次展开,共
- 移动边缘计算中无人机轨迹优化与任务卸载策略研究-含详细算法及解答
- windows组策略分享
- ov7670摄像头循迹原理分析与stm32源码
- 基于51单片机的太阳能追光系统设计,太阳跟踪系统设计,光敏控制系统protues仿真设计 有仿真,程序,AD图,原文,相关资料 本系统可以通过光敏电阻调节电机转速,有手动模式和我自动模式 适用于
- 足球、足球场地设施球员检测35-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- Arduino使用W5500作为CLIENT连接超时时间设置
- 【Python期末/课程设计】大学生乡镇餐饮营收统计系统(pycharm项目/flask框架/MySQL数据库/网页设计)
- springboot+vue智慧养老手表管理系统 本系统共分为两个角色:家长,养老院管理员 功能有:个人管理,公告管理,家庭管理,加好友管理,老人健康管理,基础管理,加好友板等框架:springboo
- 汽车后视镜组装上料机 pro5.0全套技术资料100%好用.zip
- 汽车后视镜电机组装机pro5.0全套技术资料100%好用.zip
- (N27)基于STM32指纹密码锁proteus仿真设计