51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
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);
|
|
}
|
|
}
|
|
|
|
}
|