Unity接入罗技G29方向盘,通过SDK获取按键信息
Unity接入罗技G29方向盘,通过SDK获取按键信息
说明:
最近需要做一个外设汽车驾驶相关的软件,采用的外设 罗技G29方向盘,项目中遇到的问题这里记录一下。
项目准备:
1.下载罗技的SDK
2.下载罗技游戏软件
3.Unity商店中导入Logitech Gaming SDK
遇到的问题:
1.Unity商店中导入的SDK运行会报错,将项目准备中步骤一下载的SDK 路径:Lib\x64\LogitechSteeringWheelLib.lib
复制到Logitech SDK文件夹下
2.插件没有问题,运行并不能获取方向盘的按键信息,这个情况我的电脑重启了好多次,也补充了一些基础的运行环境,一直就是获取不到方向盘的按键信息,最后我重装了一下罗技游戏软件,重启运行发现可以用了。
最后:
将插件中的LogitechSteeringWheel.cs脚本挂载到场景中运行:
相关方向盘和脚踏板的监听代码(我这没有挡位外设)
using UnityEngine;
using System.Collections;
using System.Text;public class LogitechSteeringWheel : MonoBehaviour
{LogitechGSDK.LogiControllerPropertiesData properties;private string actualState;private string activeForces;private string propertiesEdit;private string buttonStatus;private string forcesLabel;string[] activeForceAndEffect;// Use this for initializationvoid Start(){activeForces = "";propertiesEdit = "";actualState = "";buttonStatus = "";forcesLabel = "Press the following keys to activate forces and effects on the steering wheel / gaming controller \n";forcesLabel += "Spring force : S\n"; //弹簧弹力forcesLabel += "Constant force : C\n"; //恒力forcesLabel += "Damper force : D\n"; //阻尼力forcesLabel += "Side collision : Left or Right Arrow\n"; //侧向碰撞forcesLabel += "Front collision : Up arrow\n"; //正面碰撞forcesLabel += "Dirt road effect : I\n"; //土路效应forcesLabel += "Bumpy road effect : B\n"; //崎岖不平的道路forcesLabel += "Slippery road effect : L\n"; //滑路效应forcesLabel += "Surface effect : U\n"; //表面效应forcesLabel += "Car Airborne effect : A\n"; //汽车空气的影响forcesLabel += "Soft Stop Force : O\n"; //forcesLabel += "Set example controller properties : PageUp\n";forcesLabel += "Play Leds : P\n"; //发光activeForceAndEffect = new string[9];Debug.Log("SteeringInit:" + LogitechGSDK.LogiSteeringInitialize(false));}void OnApplicationQuit(){Debug.Log("SteeringShutdown:" + LogitechGSDK.LogiSteeringShutdown());}void OnGUI(){activeForces = GUI.TextArea(new Rect(10, 10, 180, 200), activeForces, 400);propertiesEdit = GUI.TextArea(new Rect(200, 10, 200, 200), propertiesEdit, 400);actualState = GUI.TextArea(new Rect(410, 10, 300, 200), actualState, 1000);buttonStatus = GUI.TextArea(new Rect(720, 10, 300, 200), buttonStatus, 1000);GUI.Label(new Rect(10, 400, 800, 400), forcesLabel);}// Update is called once per framevoid Update(){//All the test functions are called on the first device plugged in(index = 0)if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)){//CONTROLLER PROPERTIESStringBuilder deviceName = new StringBuilder(256);LogitechGSDK.LogiGetFriendlyProductName(0, deviceName, 256);propertiesEdit = "Current Controller : " + deviceName + "\n";propertiesEdit += "Current controller properties : \n\n";LogitechGSDK.LogiControllerPropertiesData actualProperties = new LogitechGSDK.LogiControllerPropertiesData();LogitechGSDK.LogiGetCurrentControllerProperties(0, ref actualProperties);propertiesEdit += "forceEnable = " + actualProperties.forceEnable + "\n";propertiesEdit += "overallGain = " + actualProperties.overallGain + "\n";propertiesEdit += "springGain = " + actualProperties.springGain + "\n";propertiesEdit += "damperGain = " + actualProperties.damperGain + "\n";propertiesEdit += "defaultSpringEnabled = " + actualProperties.defaultSpringEnabled + "\n";propertiesEdit += "combinePedals = " + actualProperties.combinePedals + "\n";propertiesEdit += "wheelRange = " + actualProperties.wheelRange + "\n";propertiesEdit += "gameSettingsEnabled = " + actualProperties.gameSettingsEnabled + "\n";propertiesEdit += "allowGameSettings = " + actualProperties.allowGameSettings + "\n";//CONTROLLER STATEactualState = "Steering wheel current state : \n\n";LogitechGSDK.DIJOYSTATE2ENGINES rec;rec = LogitechGSDK.LogiGetStateUnity(0);actualState += "x-axis position :" + rec.lX + "\n"; //方向盘actualState += "y-axis position :" + rec.lY + "\n"; //油门actualState += "z-axis position :" + rec.lZ + "\n";actualState += "x-axis rotation :" + rec.lRx + "\n";actualState += "y-axis rotation :" + rec.lRy + "\n";actualState += "z-axis rotation :" + rec.lRz + "\n"; //刹车actualState += "extra axes positions 1 :" + rec.rglSlider[0] + "\n"; //离合actualState += "extra axes positions 2 :" + rec.rglSlider[1] + "\n";switch (rec.rgdwPOV[0]){case (0): actualState += "POV : UP\n"; break;case (4500): actualState += "POV : UP-RIGHT\n"; break;case (9000): actualState += "POV : RIGHT\n"; break;case (13500): actualState += "POV : DOWN-RIGHT\n"; break;case (18000): actualState += "POV : DOWN\n"; break;case (22500): actualState += "POV : DOWN-LEFT\n"; break;case (27000): actualState += "POV : LEFT\n"; break;case (31500): actualState += "POV : UP-LEFT\n"; break;default: actualState += "POV : CENTER\n"; break;}//Button status :buttonStatus = "Button pressed : \n\n";for (int i = 0; i < 128; i++){if (rec.rgbButtons[i] == 128){buttonStatus += "Button " + i + " pressed\n";}}/* THIS AXIS ARE NEVER REPORTED BY LOGITECH CONTROLLERS * * actualState += "x-axis velocity :" + rec.lVX + "\n";* actualState += "y-axis velocity :" + rec.lVY + "\n";* actualState += "z-axis velocity :" + rec.lVZ + "\n";* actualState += "x-axis angular velocity :" + rec.lVRx + "\n";* actualState += "y-axis angular velocity :" + rec.lVRy + "\n";* actualState += "z-axis angular velocity :" + rec.lVRz + "\n";* actualState += "extra axes velocities 1 :" + rec.rglVSlider[0] + "\n";* actualState += "extra axes velocities 2 :" + rec.rglVSlider[1] + "\n";* actualState += "x-axis acceleration :" + rec.lAX + "\n";* actualState += "y-axis acceleration :" + rec.lAY + "\n";* actualState += "z-axis acceleration :" + rec.lAZ + "\n";* actualState += "x-axis angular acceleration :" + rec.lARx + "\n";* actualState += "y-axis angular acceleration :" + rec.lARy + "\n";* actualState += "z-axis angular acceleration :" + rec.lARz + "\n";* actualState += "extra axes accelerations 1 :" + rec.rglASlider[0] + "\n";* actualState += "extra axes accelerations 2 :" + rec.rglASlider[1] + "\n";* actualState += "x-axis force :" + rec.lFX + "\n";* actualState += "y-axis force :" + rec.lFY + "\n";* actualState += "z-axis force :" + rec.lFZ + "\n";* actualState += "x-axis torque :" + rec.lFRx + "\n";* actualState += "y-axis torque :" + rec.lFRy + "\n";* actualState += "z-axis torque :" + rec.lFRz + "\n";* actualState += "extra axes forces 1 :" + rec.rglFSlider[0] + "\n";* actualState += "extra axes forces 2 :" + rec.rglFSlider[1] + "\n";*/int shifterTipe = LogitechGSDK.LogiGetShifterMode(0);string shifterString = "";if (shifterTipe == 1) shifterString = "Gated";else if (shifterTipe == 0) shifterString = "Sequential";else shifterString = "Unknown";actualState += "\nSHIFTER MODE:" + shifterString;}else if (!LogitechGSDK.LogiIsConnected(0)){actualState = "PLEASE PLUG IN A STEERING WHEEL OR A FORCE FEEDBACK CONTROLLER";}else{actualState = "THIS WINDOW NEEDS TO BE IN FOREGROUND IN ORDER FOR THE SDK TO WORK PROPERLY";}}
}
参考:
链接1
Unity接入罗技G29方向盘,通过SDK获取按键信息相关推荐
- ubuntu20.04安装Carla并配置罗技G29方向盘使用
环境:ubuntu20.04+anaconda+python3.7+ros2 foxy+Logitech g29 一.安装Carla github地址: https://github.com/carl ...
- Wear OS手表应用开发教程之-监听手表按键以及获取按键信息-WearableButtons
本文目录 点击直达 Wear OS手表应用开发系列教程 点击直达 本文标签 `路过的年轻人啊,你是要用左手点个赞呢,还是要右手点个关注呢` 前言: 获取按键信息: 获取按键数量 获取按键信息 获取按键 ...
- android使用高德地图SDK获取定位信息
注册账号.创建应用.获取API KEY等这些就不说了,按照官网来就行,我们来讲讲项目的配置及示例代码. 高德地图获取定位信息配置要比百度地图简单多了,这是我比较喜欢的一点,而且之前用百度地图嵌入一个应 ...
- Unity接入TopOn聚合广告平台SDK【聚合了穿山甲,优量汇(腾讯广告),快手,Mintegral,sigmob等各大广告平台SDK】
TopOn聚合穿山甲,优量汇,快手,Mintegral各大广告SDK教程 接了好几家SDK,都有亿点点蛋疼,直到遇到了TopOn. TopOn的文档和SDK相当齐全,包括Android,IOS,Uni ...
- unity接入讯飞AIUI(Windows SDK)
一.什么是AIUI AIUI 是一套人机交互解决方案,整合了语音唤醒.语音识别.语义理解.内容平台.语音合成(比普通的语音合成多一个发音人)等能力. 新用户有20个免费的装机量,每天有500交互次数 ...
- unity 接入友盟数据统计SDK
1.下载UnitySDK 友盟SDK官网链接:SDK_开发者中心 - 友盟+ (umeng.com) 如下图. 解压后长这样 然后进入Unity3D文件夹,分别导入两个unitypackge包 ①.导 ...
- Unity3D 罗技G29开发笔记
这些博客可能对你有帮助: https://blog.csdn.net/m0_38143858/article/details/79855923 https://blog.csdn.net/baozao ...
- Ubuntu18.04通过ros通信联调Carla0.9.13+罗技G29 ros_g29控制实车vehicle_status话题的转发与消息类型的转换twist——cmd并写入同一个launch
前提:安装完carla,参考链接:https://editor.csdn.net/md/?articleId=131200896 可以安装二进制发布版本,这样启动方便很多 一.carla+罗技G29联 ...
- 对接支付宝人脸识别和获取用户信息接口
h5通过服务端调用支付宝接口获取用户信息 前提介绍 功能快捷键 总结 前提介绍 通过对接支付宝的接口,实现在移动端(安卓和ios)通过唤醒手机上的支付宝应用,调用支付宝的人脸识别实现实人认证;通过移动 ...
最新文章
- centos7 选定默认启动内核,及删除无用内核
- IntelliJ IDEA2016 + tomcat 即改即生效 实现热部署
- Mysql性能调优工具Explain结合语句讲解
- pt939g联通_尝试修改友华PT939G的省份设置,成功!
- jquery概念、引入、选择器
- iOS之socket编程
- 【足迹C++primer】51、面向对象编程概述
- javaWeb 学习笔记14 会话跟踪技术CoolieSession
- 微软苏州校招笔试题目(1月10日)Colorful Lecture Note的解法
- 手把手教你搭建Windows环境微信小程序的本地测试服务器
- 王厚祥谈《古诗四帖》基本笔画的书写方法
- 人工神经网络 人工智能,人工智能神经网络技术
- 【优化】近端梯度下降(Proximal Gradient Descent)求解Lasso线性回归问题
- Redis源码分析 —— 发布与订阅
- 2016弱校联盟十一专场10.2部分题解
- MySql安装成功后没有my.ini文件怎么办?
- 某校教务管理系统post分析,Python实现自动查询成绩并发送短信
- 数字雨C++代码(转)
- Lua(一)——Lua介绍
- heidiSQL怎么连接JAVA_Heidisql连接sql server后如何使用-Heidisql使用教程 - 河东软件园...
热门文章
- WPF自定义TabControl的样式
- 实战28:数字图像可视化水印系统的设计与实现(LSB算法、DCT算法、随机间隔算法、区域校验位算法、图像降级算法、图像降级算法改进等6种数字水印算法的实现)
- 一步一步教你自定义博客园(cnblog)界面
- TEM一维正演matlab,瞬变电磁法矩形线框一维正演及电磁信号去噪的研究
- 每日实用技巧分享:怎么修复老照片?
- SecondLife 架构剖析
- 艾默生流量计校验功能
- VHDL语言入门帮助
- arcgis二次开发动态追踪以及提高
- c语言logical转文本,c语言逻辑运算符(C language logical operator).doc