添加对象池并更新KeySettingManager的README

This commit is contained in:
2024-07-10 16:39:46 +08:00
parent 68665845ab
commit 15c2849090
5 changed files with 187 additions and 10 deletions

View File

@@ -20,7 +20,7 @@ namespace AnnoyingUtils.KeyboardInput
if (_instance) return _instance;
_instance = FindObjectOfType<KeySettingManager>();
if (_instance) return _instance;
var go = new GameObject("KeySettingManager");
var go = new GameObject(nameof(KeySettingManager));
_instance = go.AddComponent<KeySettingManager>();
return _instance;

View File

@@ -2,17 +2,20 @@
```csharp
public class KeyMapping
{
public string actionName;
public KeyCode keyCode;
{
public string actionName;
public KeyCode keyCode;
public KeyMapping(string actionName, KeyCode keyCode)
{
this.actionName = actionName;
this.keyCode = keyCode;
}
public KeyMapping(string actionName, KeyCode keyCode)
{
this.actionName = actionName;
this.keyCode = keyCode;
}
}
```
<code>KeySettingManager</code>为单例类
//todo
在<code>LoadKeySettings()</code>中填写自己需要的键位对即可。
调用<code>GetKey(string actionName)</code>获取行为对应的KeyCode
调用<code>SetKey(string actionName, KeyCode newKeyCode)</code>设置行为对应KeyCode