要使用 Unity 将 Amazon Fire Tv 控制器与新输入系统完全映射,您需要一个自定义设备。
使用此脚本,您可以使所有按钮正常工作。
也可以提高音量、降低音量和静音。但我认为覆盖此按钮不是一个好主意。
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Scripting;
#if UNITY_EDITOR
using UnityEditor;
#endif
[Preserve]
public struct AftvRemoteDeviceState : IInputStateTypeInfo
{
public FourCC format => new FourCC('A', 'G', 'C');
//Mapped Here
[InputControl(name = "dPadUpButton", layout = "Button", bit = 19, displayName = "Dpad Up")]
[InputControl(name = "dPadRightButton", layout = "Button", bit = 22, displayName = "Dpad Right")]
[InputControl(name = "dPadDownButton", layout = "Button", bit = 20, displayName = "Dpad Down")]
[InputControl(name = "dPadLeftButton", layout = "Button", bit = 21, displayName = "Dpad Left")]
//[InputControl(name = "backButton", layout = "Button", bit = 4, displayName = "Back Button")]
[InputControl(name = "menuButton", layout = "Button", bit = 82, displayName = "Menu Button")]
//Non Maped
[InputControl(name = "selectButton", layout = "Button", bit = 23, displayName = "Select Button")]
[InputControl(name = "rewindButton", layout = "Button", bit = 89, displayName = "Rewind Button")]
[InputControl(name = "playPauseButton", layout = "Button", bit = 85, displayName = "Play Pause Button")]
[InputControl(name = "fastForwardButton", layout = "Button", bit = 90, displayName = "Fast Forward Button")]
public uint buttons;
}
#if UNITY_EDITOR
[InitializeOnLoad] // Call static class constructor in editor.
#endif
[Preserve]
[InputControlLayout(displayName = "Aftv Remote", stateType = typeof(AftvRemoteDeviceState))]
public class AftvRemoteDevice : InputDevice
{
#if UNITY_EDITOR
static AftvRemoteDevice()
{
Initialize();
}
#endif
[RuntimeInitializeOnLoadMethod]
private static void Initialize()
{
InputSystem.RegisterLayout<AftvRemoteDevice>
(
matches: new InputDeviceMatcher()
.WithInterface("Android")
.WithDeviceClass("AndroidGameController")
.WithProduct("Amazon Fire TV Remote")
);
}
public ButtonControl dPadUpButton { get; private set; }
public ButtonControl dPadRightButton { get; private set; }
public ButtonControl dPadDownButton { get; private set; }
public ButtonControl dPadLeftButton { get; private set; }
public ButtonControl selectButton { get; private set; }
public ButtonControl rewindButton { get; private set; }
public ButtonControl playPauseButton { get; private set; }
public ButtonControl fastForwardButton { get; private set; }
//public ButtonControl backButton { get; private set; }
public ButtonControl menuButton { get; private set; }
public bool SelectButtonDown { get; set; }
public bool RewindButtonDown { get; set; }
public bool PlayPauseButtonDown { get; set; }
public bool FastForwardButtonDown { get; set; }
protected override void FinishSetup()
{
base.FinishSetup();
dPadUpButton = GetChildControl<ButtonControl>("dPadUpButton");
dPadRightButton = GetChildControl<ButtonControl>("dPadRightButton");
dPadDownButton = GetChildControl<ButtonControl>("dPadDownButton");
dPadLeftButton = GetChildControl<ButtonControl>("dPadLeftButton");
rewindButton = GetChildControl<ButtonControl>("rewindButton");
playPauseButton = GetChildControl<ButtonControl>("playPauseButton");
fastForwardButton = GetChildControl<ButtonControl>("fastForwardButton");
//backButton = GetChildControl<ButtonControl>("backButton");
menuButton = GetChildControl<ButtonControl>("menuButton");
selectButton = GetChildControl<ButtonControl>("selectButton");
}
public static AftvRemoteDevice current { get; private set; }
public override void MakeCurrent()
{
base.MakeCurrent();
current = this;
}
protected override void OnRemoved()
{
base.OnRemoved();
if (current == this)
current = null;
}
#region Editor
#if UNITY_EDITOR
[MenuItem("Tools/AftvRemote/Create Device")]
private static void CreateDevice()
{
InputSystem.AddDevice<AftvRemoteDevice>();
}
[MenuItem("Tools/AftvRemote/Remove Device")]
private static void RemoveDevice()
{
var customDevice = InputSystem.devices.FirstOrDefault(x => x is AftvRemoteDevice);
if (customDevice != null)
InputSystem.RemoveDevice(customDevice);
}
#endif
#endregion
}
位值是相同的来自 Android API 的常量值。
您可以查看列表Here
您只需在项目设置中包含此脚本即可设置您的输入操作和输入操作映射。
由于某些原因,播放器输入组件存在问题。
但是对于 UI 导航,这很好用,它也适用于 Input Debugger。