Unity 罗技G29接入

Unity 罗技G29接入

Unity 罗技G29接入

一、 使用Unity Standard Assets中的CrossPlatformInputManager

InputManger设置

 

InputManager1
InputManager1

 

 

InputMnanger2
InputMnanger2

 

Code

float wheel = CrossPlatformInputManager.GetAxis("G29 Horizontal Steer");
float throttle = CrossPlatformInputManager.GetAxis("G29 Vertical Throttle");
float footbrake = CrossPlatformInputManager.GetAxis("G29 Vertical Brake");
float cluch = CrossPlatformInputManager.GetAxis("G29 Vertical Clutch

二、使用Rewired插件

Rewired是一套非常便捷的输入控制插件,支持数百种设备,包括:键盘,手柄、模拟器等。
下载地址:Rewired

Actions

 

Actions
Actions

 

Joystick Maps

 

Joystick Maps
Joystick Maps

 

三、其他键位

键位测试:

using UnityEngine;
using System.Collections;
using System;


/// <summary>
/// 测试游戏手柄键值
/// </summary>
public class JoytickTest : MonoBehaviour
{
    private string currentButton;//当前按下的按键
 
    // Update is called once per frame 
    void Update()
    {
        var values = Enum.GetValues(typeof(KeyCode));//存储所有的按键
        for (int x = 0; x < values.Length; x++)
        {
            if (Input.GetKeyDown((KeyCode)values.GetValue(x)))
            {
                currentButton = values.GetValue(x).ToString();//遍历并获取当前按下的按键
            }
        }
    }
    // Show some data 
    void OnGUI()
    {
        GUI.TextArea(new Rect(0, 50, 250, 40), "Current Button : " + currentButton);//使用GUI在屏幕上面实时打印当前按下的按键
    }
}

 

可参考xbox手柄配置:
https://blog.csdn.net/u014635337/article/details/76273323

 

XBOX
XBOX

 

 

配置说明
Gravity 设备静止时输出值下降的速度(/秒)。仅在 Type 为 key/mouse button 时使用
Dead 任何小于此数字的正值或负值都将注册为零。对摇杆很有用。
Sensitivity 对于键盘输入,较大的值将导致更快的响应时间。较低的值会更平滑。对于鼠标增量,该值将缩放实际鼠标增量。
Snap 如果启用,轴值将在接收到相反输入后立即重置为零。仅在 Type 为 key/mouse button 时使用
Invert 如果启用,正按钮将向轴发送负值,反之亦然。
Type 输入类型 按键/鼠标/摇杆 

 

posted @ 2021-12-20 17:17  世纪末の魔术师  阅读(700)  评论(0编辑  收藏  举报