Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadME Changes Proposal for Developers #1

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 54 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,97 @@ Create a new class, name it whatever you prefer, this class will contain all the
Make sure it extends `LcInputActions`.

```csharp
public class [CLASSNAME] : LcInputActions
public class MyExampleInputClass : LcInputActions
{

}
```

Next make properties for all of the InputActions you want/need
```csharp
public InputAction Explode { get; set; }
public InputAction ExplodeKey { get; set; }
```

In order for the action to be registered to the API, you must use the attribute `[InputAction(...)]`.
This attribute has 3 required parameters: actionId, keyboard/mouse binding path, and gamepad binding path.
There are also 2 optional parameters: ActionType (default: InputActionType.Button), and Name. The Name parameter is what will be displayed in game.
There are also 2 optional parameters: Name and ActionType (default: InputActionType.Button). The Name parameter is what will be displayed in game.


```csharp
[InputAction("explode", "<Keyboard>/j", "<Gamepad>/Button North", Name = "Explode")]
public InputAction Explode { get; set; }
// [InputAction(string actionId, string keyBinding, string gamepadBinding, Name = "Shown Name", ActionType = InputActionType...)]

[InputAction("explode", "<Keyboard>/minus", "<Gamepad>/Button North", Name = "Explode")]
public InputAction ExplodeKey { get; set; }
```

Finally to use the InputAction you need an instance of this class. Due to how registration works, only 1 instance of this class can exist.
The easiest (opinionated) way to do so would be to have a static instance in your plugin class.
```csharp
[BepInPlugin(...)]
public class [MODPLUGIN] : BaseUnityPlugin
public class MyExamplePlugin : BaseUnityPlugin
{
internal static [CLASSNAME] InputActionsInstance = new [CLASSNAME]();
internal static MyExampleInputClass InputActionsInstance = new MyExampleInputClass();
}
```
You could also opt for having the instance in the InputActions class.
```csharp
public class [CLASSNAME] : LcInputActions
public class MyExamplePlugin : LcInputActions
{
public static [CLASSNAME] Instance = new();
public static MyExampleInputClass Instance = new();

[InputAction("explode", "<Keyboard>/j", "<Gamepad>/Button North", Name = "Explode")]
public InputAction Explode { get; set; }
[InputAction("explodekey", "<Keyboard>/j", "<Gamepad>/Button North", Name = "Explode")]
public InputAction ExplodeKey { get; set; }
}
```

You could then simply reference the instance anywhere you need to have your actions at
```csharp
public class [SomeOtherClassOrMonoBehavior]
public class MyOtherClassOrMonoBehavior
{
public void DoSomething()
{
[MODPLUGIN].InputActionsInstance.Explode ...
MyExamplePlugin.InputActionsInstance.ExplodeKey ...
}
}
```
or
```csharp
public class [SomeOtherClassOrMonoBehavior]
public class MyOtherClassOrMonoBehavior
{
public void DoSomething()
{
MyExampleInputClass.Instance.ExplodeKey ...
}
}
```

You can then use callbacks on the InputAction, make sure to read Unity's [docs](https://docs.unity3d.com/Packages/[email protected]/manual/Interactions.html#default-interaction) on how these callbacks work.
```csharp
public class MyOtherClassOrMonoBehavior
{
// Name this whatever you like.
public void SetupKeybindCallbacks()
{
MyExamplePlugin.InputActionsInstance.ExplodeKey.performed += OnExplodeKeyPressed
}

public void OnExplodeKeyPressed(InputAction.CallbackContext ctx)
{
// Your executing code here
}
}
```

Another good implementation of this is getting the boolean value from when it is triggered
```csharp
public class MyOtherClassOrMonoBehavior
{
public void DoSomething()
{
[CLASSNAME].Instance.Explode ...
if (MyExamplePlugin.InputActionsInstance.ExplodeKey.triggered)
{
//Your executing code here
}
}
}
```
Expand All @@ -89,6 +124,9 @@ Discord: @rune

Github: Rune580

# Contributers
Thanks to @Boxofbiscuits97 for helping make the ReadME easier for Devs

# Changelog
0.1.0:
Initial Beta Release.
Initial Beta Release.
Loading