1
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user