2022-08-14 00:05:25 +03:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class RebindButton : BaseButton
|
|
|
|
|
{
|
2022-10-07 17:31:42 +03:00
|
|
|
[SerializeField] private InputActionReference _actionReference = default;
|
|
|
|
|
[SerializeField] private DeviceConfigurator _deviceConfigurator = default;
|
|
|
|
|
[SerializeField] private Image _image = default;
|
|
|
|
|
[SerializeField] private PlayerInput _playerInput = default;
|
|
|
|
|
[Range(-1, 4)]
|
|
|
|
|
[SerializeField] private int _compositeIndex = -1;
|
2022-08-16 23:07:21 +03:00
|
|
|
|
2022-10-07 17:31:42 +03:00
|
|
|
public InputActionReference ActionReference { get { return _actionReference; } private set { } }
|
|
|
|
|
public int ControlBindingIndex { get; private set; }
|
|
|
|
|
public int CompositeIndex { get { return _compositeIndex; } private set { } }
|
2022-08-14 00:05:25 +03:00
|
|
|
|
|
|
|
|
|
2022-10-07 17:31:42 +03:00
|
|
|
void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
if (_playerInput.devices[0].displayName.Contains("Keyboard"))
|
|
|
|
|
{
|
|
|
|
|
if (CompositeIndex == 0)
|
|
|
|
|
{
|
|
|
|
|
ControlBindingIndex = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ControlBindingIndex = CompositeIndex + 5;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CompositeIndex == 0)
|
|
|
|
|
{
|
|
|
|
|
ControlBindingIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ControlBindingIndex = CompositeIndex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UpdatePromptImage();
|
|
|
|
|
}
|
2022-08-14 00:05:25 +03:00
|
|
|
|
2022-10-07 17:31:42 +03:00
|
|
|
public void UpdatePromptImage()
|
|
|
|
|
{
|
|
|
|
|
InputAction inputAction = _actionReference.action;
|
|
|
|
|
string currentBindingInput = InputControlPath.ToHumanReadableString(inputAction.bindings[ControlBindingIndex].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
|
|
|
|
|
_image.sprite = _deviceConfigurator.GetDeviceBindingIcon(_playerInput, currentBindingInput);
|
|
|
|
|
}
|
2022-08-14 00:05:25 +03:00
|
|
|
}
|