1
This commit is contained in:
@@ -36,6 +36,19 @@ namespace BITKit
|
||||
action.RegisterCallback(callback);
|
||||
return this;
|
||||
}
|
||||
|
||||
public InputActionGroup RegisterCallback(InputAction inputAction,Action<InputAction.CallbackContext> callback)
|
||||
{
|
||||
EnsureConfiguration();
|
||||
|
||||
var action = actions.GetOrAdd(inputAction.name, _=>inputAction.Clone());
|
||||
|
||||
allowInput.Invoke();
|
||||
|
||||
action.RegisterCallback(callback);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public InputAction EnsureCreated(InputActionReference reference)
|
||||
{
|
||||
@@ -57,6 +70,20 @@ namespace BITKit
|
||||
|
||||
return action;
|
||||
}
|
||||
public InputAction EnsureCreated(InputAction inputAction)
|
||||
{
|
||||
EnsureConfiguration();
|
||||
var action = actions.GetOrAdd(inputAction.name, _ =>
|
||||
{
|
||||
var newAction = inputAction.Clone();
|
||||
newAction.Rename(inputAction.name);
|
||||
return newAction;
|
||||
});
|
||||
|
||||
allowInput.Invoke();
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
public void Inherit(InputActionGroup other)
|
||||
{
|
||||
@@ -80,6 +107,12 @@ namespace BITKit
|
||||
action.UnRegisterCallback(callback);
|
||||
}
|
||||
|
||||
public void UnRegisterCallback(InputAction inputAction, Action<InputAction.CallbackContext> callback)
|
||||
{
|
||||
if(actions.TryGetValue(inputAction.name,out var action))
|
||||
action.UnRegisterCallback(callback);
|
||||
}
|
||||
|
||||
private void EnsureConfiguration()
|
||||
{
|
||||
if (state is not InitializationState.Initialized)
|
||||
|
50
Src/Unity/Scripts/InputSystem/UnityPlayerInput.cs
Normal file
50
Src/Unity/Scripts/InputSystem/UnityPlayerInput.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEngine.InputSystem
|
||||
{
|
||||
public class UnityPlayerInput : MonoBehaviour
|
||||
{
|
||||
private readonly InputActionGroup _inputActionGroup=new();
|
||||
|
||||
[SerializeField] private InputActionAsset inputActionAsset;
|
||||
|
||||
private bool _isInitialized;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
foreach (var inputActionMap in inputActionAsset.actionMaps)
|
||||
{
|
||||
foreach (var inputAction in inputActionMap.actions)
|
||||
{
|
||||
_inputActionGroup.RegisterCallback(inputAction, x =>
|
||||
{
|
||||
SendMessage($"On{inputAction.name}",x,SendMessageOptions.DontRequireReceiver);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (_isInitialized is false)
|
||||
{
|
||||
_inputActionGroup.allowInput.AddElement(this);
|
||||
}
|
||||
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_isInitialized)
|
||||
_inputActionGroup.allowInput.AddElement(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_inputActionGroup.allowInput.RemoveElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Src/Unity/Scripts/InputSystem/UnityPlayerInput.cs.meta
Normal file
11
Src/Unity/Scripts/InputSystem/UnityPlayerInput.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b2748010e8669a44b12cd163ea95fa2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user