Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erodozer/bepinex.unityinput
Basic Harmony Hooks to allow plugins to override Unity's Global Input responses
https://github.com/erodozer/bepinex.unityinput
bepinex bepinex-plugins unity
Last synced: about 2 months ago
JSON representation
Basic Harmony Hooks to allow plugins to override Unity's Global Input responses
- Host: GitHub
- URL: https://github.com/erodozer/bepinex.unityinput
- Owner: erodozer
- License: mit
- Created: 2021-07-23T20:24:04.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-09-19T14:40:26.000Z (over 3 years ago)
- Last Synced: 2024-04-29T00:17:08.039Z (8 months ago)
- Topics: bepinex, bepinex-plugins, unity
- Language: C#
- Homepage:
- Size: 19.5 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BepInEx.UnityInput
Adds Harmony hooks so that BepInEx plugins may intercept Unity's Global Input system.
Development for this largely stems from interest of extending functionality of Illusion games, such as Koikatsu, which extensively make use of `UnityEngine.Input` in places where by best practice it shouldn't.
In areas where you wish to use original game functionality through the simulation of button presses on the UI, you may need to occasionally fake an Input state.## Requirements
* Install BepInEx 5.4 or later.
## Using this in your own Plugins
Plugins that require BepInEx.UnityInput should specify the dependency like so
```
[BepInPlugin(GUID, "MyPlugin", Version)]
[BepInDependency("github.lunared.bepinex.unityinput", BepInDependency.DependencyFlags.HardDependency)]
internal class MyPlugin : BaseUnityPlugin
{
}
```Once your plugin is set up to depend on the UnityInput one, you can now reference the Global methods where you need to.
The functions are all exposed similar to Unity's own Input system.
In this example, we can demonstrate how to click an Action button in Koikatsu's HSprite UI```csharp
using UnityEngine;
using KKAPI.MainGame;
using BepInEx.Unity; // this has InputSimulator in it, which we use to override inputnamespace MyPlugin
{
internal class MyPluginController : GameCustomFunctionController
{protected override void OnStartH(HSceneProc proc, bool freeH)
{
StartCoroutine(PickAction(proc));
}IEnumerator PickAction(HSceneProc proc)
{
while (true)
{
// get the list of visible actions from one of the interfaces
var choices = proc.sprite.sonyu.categoryActionButton.lstButton.Where(
button => button.isActiveAndEnabled && button.interactable
).ToList();// leverage simulating clicking in the menu
var index = Random.RandomRangeInt(0, choices.Count);
var nextAction = choices[index];// many koikatsu actions check for left click mouse up
// within their onClick handler
InputSimulator.MouseButtonUp(0);
// perform our action
nextAction?.onClick?.Invoke();
// reset the input state after performing the action
InputSimulator.UnsetMouseButton(0);
yield return new WaitForSeconds(1f);
}
}
}
```