這些博客可能對你有幫助:
https://blog.csdn.net/m0_38143858/article/details/79855923
https://blog.csdn.net/baozaodedianxiaoer/article/details/80134658
https://blog.csdn.net/wuyf88/article/details/68942196
目錄
一、準備工作
1、在羅技官網下載最新的羅技遊戲軟件。https://www.logitechg.com/en-us/partnerdeveloperlab/sdk-resource-list/steering-wheel-sdk.html
2、在assetstore中下載Logitech Gaming SDK,導入 Logitech SDK 。把官網下載的LogitechSteeringWheelEnginesWrapper.dll替換Unity3D中的。
二、使用官方Demo,熟悉各種輸入
直接把Script Sample中的LogitechSteeringWheel.cs掛載空物體中,運行。
三、 注意項
(1)初始化連接問題
- 使用LogitechGSDK.cs腳本需要先初始化,LogiSteeringInitialize();
- 要在代碼中調用來自羅技SDK的任何函數,請導入LogitechGSDK.cs腳本並靜態調用函數。
- 函數LogiSteeringInitialize()會試圖獲得你的應用程序/遊戲主窗口句柄。它可能會失敗,因爲當你調用該函數時的主窗口可能不會在最前面的界面。
- 如果LogiSteeringInitialize()返回false,初始化將會接受任何嘗試下一個LogiUpdate()函數的調用。當窗口在最前界面時和SDK可以初始化,LogiUpdate()將返回true。
- 【但我曾經出現過一個狀況是:在Start()裏LogiSteeringInitialize()返回是false,然後就算當前窗口已經是最前界面了,Update()裏LogiUpdate()還是一直返回false,後來試着在Start()里加一個循環,一直循環LogiSteeringInitialize()直到返回true就完美解決問題了。】
(2)獲取不到方向盤旋轉的數據(結構體DIJOYSTATE2ENGINES中的lX)
- 如果連接成功(函數LogiSteeringInitialize和LogiUpdate,返回true),但只能獲取方向盤的按鈕,獲取不了方向盤旋轉的數據可能是線沒插緊的原因。
(3)方向盤、腳踏板、檔位器:當沒有觸碰到的時候,好像是不會收到數據?我判定不到連接狀態。
我用了下LogiIsDeviceConnected()去獲取方向盤、腳踏板、檔位器的狀態,但只有LOGI_DEVICE_TYPE_WHEEL返回true,其他(LOGI_DEVICE_TYPE_JOYSTICK、LOGI_DEVICE_TYPE_GAMEPAD、LOGI_DEVICE_TYPE_OTHER)都是返回false,不知道爲什麼獲取不到連接狀態,如果知道的,望告知 QAQ
四、使用流程圖
五、模板
public class LogitechControllerController : MonoBehaviour {
private static LogitechControllerController instance = null;
public static LogitechControllerController GetInstance()
{
if (instance == null)
{
instance = new GameObject("LogitechControllerCtrl").AddComponent<LogitechControllerController>();
//1、初始化,看需求初始化。
bool flag = false;
while (flag == false)
{
//Debug.Log("SteeringInit:" + LogitechGSDK.LogiLedInit());
//Debug.Log("SteeringInit2:" + LogitechGSDK.LogiSteeringInitialize(false));
flag = LogitechGSDK.LogiSteeringInitialize(false);
Debug.Log("SteeringInit:" + flag);
}
}
return instance;
}
//2、更新
private void Update()
{
if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
{
//。。。。。。
}
}
//3、退出前
void OnApplicationQuit()
{
Debug.Log("SteeringShutdown:" + LogitechGSDK.LogiSteeringShutdown());
}
}
六、記錄
- 方向盤:lX
不觸碰(初始):0,觸碰後左扭到盡:-32768,右扭到盡:32767 - 油門: lY
不觸碰(初始):0,不踩:32767,踩盡:-32768 - 剎車: lRz
不觸碰(初始):0,不踩:32767,踩盡:-32768
七、官方文檔中較常用的一些函數
【因爲我不肯定機翻的誤差多大,但大部分都是能看懂的,不過最好還是一邊官方文檔一邊我這文哈哈哈】
1、LogiSteeringInitialize 主窗口初始化
-
bool LogiSteeringInitialize(bool ignoreXInputControllers);
ignoreXInputControllers:忽略X輸入控制器 -
【只允許一個用戶在任何給定時間來控制,如果兩個應用程序同時初始化SDK設備,只有第一個獲取成功,第二個應用程序獲取失敗。】
-
函數LogiSteeringInitialize()會試圖獲得你的應用程序/遊戲主窗口句柄。它可能會失敗,因爲當你調用該函數時的主窗口可能不會在最前面的界面。
-
如果LogiSteeringInitialize()返回false,初始化將會接受任何嘗試下一個LogiUpdate()函數的調用。當窗口在最前界面時和SDK可以初始化,LogiUpdate()將返回true。
2、獲取設備數據前,要判斷設備是否連接和更新【LogiUpdate()和LogiIsConnected(0)】
-
(1)LogiUpdate 主窗口設備更新
Bool LogiUpdate()
該LogiUpdate()查找主窗口處理程序,如果已經發現力和控制器 保持連接最新的。它被稱爲應用程序的每一幀。
返回false,可能是LogiSteeringInitialize()沒有被調用/已無法找到主窗口句柄。 -
(2)LogiIsConnected 設備是否已連接
Bool LogiIsConnected(const int index)
該LogiIsConnected()函數檢查遊戲控制器是否連接在指定索引處
Index:遊戲控制器的索引。0對應連接的第一個遊戲控制器。1對應第二個遊戲控制器。 -
(3)LogiGetStateUnity 獲取設備狀態
DIJOYSTATE2ENGINES LogiGetStateUnity(int index)
LogiGetStateUnity()返回結構體DIJOYSTATE2控制器的狀態。
Index:遊戲控制器的索引。0對應連接的第一個遊戲控制器。1對應第二個遊戲控制器。 -
(4)LogiGetFriendlyProductName 獲取設備名
Bool LogiGetFriendlyProductName(int index, StringBuilder buffer, int bufferSize);
Index:遊戲控制器的索引。0對應連接的第一個遊戲控制器。1對應第二個遊戲控制器。
Buffer:設備名
bufferSize:buffer長度 -
(5)DIJOYSTATE2結構體 包含設備的在座標系中的位置信息,和POVs和按鈕設備信息。
【大部分方向盤、腳踏、排擋杆數據可在這裏獲取】
public struct DIJOYSTATE2ENGINES
{
public int lX; /* x-axis position 【方向盤】 */
public int lY; /* y-axis position 【油門】 */
public int lZ; /* z-axis position */
public int lRx; /* x-axis rotation */
public int lRy; /* y-axis rotation */
public int lRz; /* z-axis rotation 【剎車】 */
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public int[] rglSlider; /* extra axes positions 【rglSlider[0]離合】 */
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public uint[] rgdwPOV; /* POV directions */
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public byte[] rgbButtons; /* 128 buttons */
public int lVX; /* x-axis velocity */
public int lVY; /* y-axis velocity */
public int lVZ; /* z-axis velocity */
public int lVRx; /* x-axis angular velocity */
public int lVRy; /* y-axis angular velocity */
public int lVRz; /* z-axis angular velocity */
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public int[] rglVSlider; /* extra axes velocities */
public int lAX; /* x-axis acceleration */
public int lAY; /* y-axis acceleration */
public int lAZ; /* z-axis acceleration */
public int lARx; /* x-axis angular acceleration */
public int lARy; /* y-axis angular acceleration */
public int lARz; /* z-axis angular acceleration */
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public int[] rglASlider; /* extra axes accelerations */
public int lFX; /* x-axis force */
public int lFY; /* y-axis force */
public int lFZ; /* z-axis force */
public int lFRx; /* x-axis torque */
public int lFRy; /* y-axis torque */
public int lFRz; /* z-axis torque */
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public int[] rglFSlider; /* extra axes forces */
};
//例子: 可在void Update()中寫,獲取方向盤數據。
if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
{
LogitechGSDK.DIJOYSTATE2ENGINES wheel;
wheel = LogitechGSDK.LogiGetStateUnity(0);
Debug.Log(wheel.lX);
}
3、LogiButton 方向盤按鍵
- (1)bool LogiButtonTriggered(int index, int buttonNbr); 按鍵檢測
- (2)bool LogiButtonIsPressed(int index, int buttonNbr); 按鍵釋放
- (3)bool LogiButtonReleased(int index, int buttonNbr); 按鍵按下
buttonNbr:想要檢測的按鈕號碼
【Triggered按鍵按下第一幀返回true,Pressed按鍵按下期間返回true,Released按鍵鬆開第一幀返回true】
//例子:
//可在void Update()中寫,獲取按鍵信息
if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
{
if (LogitechGSDK.LogiButtonTriggered(0, 0))
Debug.Log("KeyCode.Joystick1Button0 方向盤 X 鍵");
if (LogitechGSDK.LogiButtonTriggered(0, 1))
Debug.Log("KeyCode.Joystick1Button1 方向盤 □ 鍵");
}
//或:
//(這種方法是根據參考官方的演示腳本中寫的。
//如果只需要監聽幾個按鈕,推薦上面的方法,且作用類似LogiButtonIsPressed,只要按下,wheel.rgbButtons[i]就返回true)
//但最推薦就是寫一個腳本,把所有輸入信息包裝一下,用事件的形式觸發。
if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
{
LogitechGSDK.DIJOYSTATE2ENGINES wheel;
wheel = LogitechGSDK.LogiGetStateUnity(0);
for (int i = 0; i < 128; i++)
{
if (wheel.rgbButtons[i] == 128)
{
switch (i)
{
case 0:
Debug.Log("KeyCode.Joystick1Button0 方向盤 X 鍵");
break;
case 1:
Debug.Log("KeyCode.Joystick1Button1 方向盤 □ 鍵");
break;
//。。。。。。。。。。
}
}
}
}
4、LogiControllerPropertiesData 控制器屬性
public struct LogiControllerPropertiesData
{
public bool forceEnable; 使能力
public int overallGain; 整體
public int springGain; 彈簧力
public int damperGain; 阻尼力
public bool defaultSpringEnabled;默認彈簧力狀態
public int defaultSpringGain; 默認彈簧力的大小
public bool combinePedals;
public int wheelRange; 輪範圍
public bool gameSettingsEnabled;
public bool allowGameSettings;
}
5、LogiIsPlaying 力反饋是否發揮作用
bool LogiIsPlaying(const int index, const int forceType)檢查是否有某個力正在發揮作用。
Force types:
public const int LOGI_FORCE_NONE = -1;
public const int LOGI_FORCE_SPRING = 0;
public const int LOGI_FORCE_CONSTANT = 1;
public const int LOGI_FORCE_DAMPER = 2;
public const int LOGI_FORCE_SIDE_COLLISION = 3;
public const int LOGI_FORCE_FRONTAL_COLLISION = 4;
public const int LOGI_FORCE_DIRT_ROAD = 5;
public const int LOGI_FORCE_BUMPY_ROAD = 6;
public const int LOGI_FORCE_SLIPPERY_ROAD = 7;
public const int LOGI_FORCE_SURFACE_EFFECT = 8;
public const int LOGI_NUMBER_FORCE_EFFECTS = 9;
public const int LOGI_FORCE_SOFTSTOP = 10;
public const int LOGI_FORCE_CAR_AIRBORNE = 11;
6、SpringForce 彈簧力
- (1)bool LogiPlaySpringForce(int index, int offsetPercentage, int saturationPercentage, int coefficientPercentage); 產生彈簧力
offsetPercentage:指定彈簧力作用的中心,[-100,100],指定0爲彈簧的中心位置。超出範圍的任何值彈簧都會靜止不動。
saturationPercentage:指定彈力效果飽和的水平。經過中心位置一定偏差後,飽和水平保持不變。[0,100],超出範圍的任何值彈簧都會靜止不動。
coefficientPercentage:表示指定相對於從條件中心偏轉的量的效果強度增加的斜率。值越高,到達飽和水平越快。[-100,100]。有效範圍之外的任何值都將被靜默地夾緊。 - (2)bool LogiStopSpringForce(int index); 終止彈簧力
- (3)例子:
LogitechGSDK.LogiPlaySpringForce(0, 50, 50, 50);
LogitechGSDK.LogiStopSpringForce(0);
7、ConstantForce 恆力
- (1)bool LogiPlayConstantForce(int index, int magnitudePercentage); 產生恆力
magnitudePercentage:指定恆力作用的大小。負值與力的方向相反。[-100,100],超出範圍的任何值彈簧都會靜止不動。 - (2)bool LogiStopConstantForce(int index); 終止恆力
8、DamperForce 阻尼力
- (1)bool LogiPlayDamperForce(int index, int coefficientPercentage); 產生阻尼力
coefficientPercentage:效果強度增加的斜率和中心位置處的條件有關。值越高,到達飽和水平越快。[-100,100],有效範圍之外的任何值都將被靜默地夾緊。-100模擬了一個非常光滑的效果。+100使車輪/操縱桿很難移動,模擬車在停車或在泥濘中行駛。 - (2)bool LogiStopDamperForce(int index); 終止阻尼力
9、LogiPlaySideCollisionForce 側向碰撞力
- bool LogiPlaySideCollisionForce(int index, int magnitudePercentage);
magnitudePercentage:側面碰撞力的大小。[-100,100],超出範圍的任何值將不起作用。
10、LogiPlayFrontalCollisionForce 正向碰撞力
- bool LogiPlayFrontalCollisionForce(int index, int magnitudePercentage);
magnitudePercentage:正向碰撞力的大小。[0,100],超出範圍的任何值將不起作用。
11、DirtRoadEffect土路效果
- (1)bool LogiPlayDirtRoadEffect(int index, int magnitudePercentage);開啓土路效果
magnitudePercentage:指土路影響的程度。[0,100],超出範圍的任何值將不起作用。 - (2)bool LogiStopDirtRoadEffect(int index); 終止土路效果
12、BumpyRoadEffect 顛簸路面效果
- (1)bool LogiPlayBumpyRoadEffect(int index, int magnitudePercentage); 開啓顛簸路面效果
magnitudePercentage:指顛簸路面影響的程度。[0,100],超出範圍的任何值將不起作用。 - (2)bool LogiStopBumpyRoadEffect(int index);關閉顛簸路面效果
13、SlipperyRoadEffect 平滑路面效果
- (1)bool LogiPlaySlipperyRoadEffect(int index, int magnitudePercentage); 開啓平滑路面效果
magnitudePercentage:指平滑路面影響的程度。[0,100],超出範圍的任何值將不起作用。 - (2)bool LogiStopSlipperyRoadEffect(int index);終止平滑路面效果
14、SurfaceEffect 路面響應效果
- (1)bool LogiPlaySurfaceEffect(int index, int type, int magnitudePercentage, int period); 開啓路面響應效果
//Periodic types for surface effect
public const int LOGI_PERIODICTYPE_NONE = -1;
public const int LOGI_PERIODICTYPE_SINE = 0;
public const int LOGI_PERIODICTYPE_SQUARE = 1;
public const int LOGI_PERIODICTYPE_TRIANGLE = 2;
magnitudePercentage:指路面影響的程度。[0,100],超出範圍的任何值將不起作用。
period:表示週期力作用的期限,值是毫秒爲測量單位。
- (2)bool LogiStopSurfaceEffect(int index); 關閉路面響應效果
- (3) 例子:LogitechGSDK.LogiPlaySurfaceEffect(0, LogitechGSDK.LOGI_PERIODICTYPE_SQUARE, 50, 1000);
15、CarAirborne 模擬汽車在路面上騰空的效果
- (1)bool LogiPlayCarAirborne(int index); 模擬汽車在路面上騰空的效果
- (2)bool LogiStopCarAirborne(int index);終止汽車在路面上騰空的效果
16、SoftstopForce 軟停力
- (1)bool LogiPlaySoftstopForce(int index, int usableRangePercentage); 開啓軟停力
usableRangePercentage:表示軟停力效果影響deadband的百分比。 - (2)bool LogiStopSoftstopForce(int index); 終止軟停力
17、LogiPlayLeds 開啓方向盤的LED燈
- bool LogiPlayLeds(int index, float currentRPM, float rpmFirstLedTurnsOn, float rpmRedLine);
最後我做了一個辣雞插件,如何使用在test裏,供大家參考吧。
功能如下:
監控了方向盤 + 腳踏板 + 檔位器中的如下數據
- 方向盤:
15 個按鈕的觸發事件(包括:剛點擊觸發一次,維持點擊一直觸發,鬆開時觸發一次)
7 個按鈕(pov)的觸發事件(點擊按鈕時一直觸發)
旋轉紅色旋鈕的觸發事件(每旋轉一檔旋鈕時觸發一次)
轉動方向盤的數據事件- 腳踏板:
離合、剎車、油門的數據事件- 檔位器:
7個檔位的觸發事件(包括:剛進入新檔位時觸發一次,維持檔位一直觸發,離開檔位觸發一次)
using System;
using System.Collections;
using UnityEngine;
namespace Sakura
{
/// <summary>
/// Logitech輸入設備
/// </summary>
public enum LogitechSteeringWheelButtonType
{
/// <summary>
/// 方向盤 X 鍵(按鈕1)
/// </summary>
x,
/// <summary>
/// 方向盤 □ 鍵(按鈕2)
/// </summary>
rect,
/// <summary>
/// 方向盤 ○ 鍵(按鈕3)
/// </summary>
circle,
/// <summary>
/// 方向盤 △ 鍵(按鈕4)
/// </summary>
triangle,
/// <summary>
/// 方向盤 右撥片 鍵(按鈕5)
/// </summary>
rightDialSlice,
/// <summary>
/// 方向盤 左撥片 鍵(按鈕6)
/// </summary>
leftDialSlice,
/// <summary>
/// 方向盤 R2 鍵(按鈕7)
/// </summary>
R2,
/// <summary>
/// 方向盤 L2 鍵(按鈕8)
/// </summary>
L2,
/// <summary>
/// 方向盤 SHARE 鍵(按鈕9)
/// </summary>
share,
/// <summary>
/// 方向盤 OPTION 鍵(按鈕10)
/// </summary>
option,
/// <summary>
/// 方向盤 R3 鍵(按鈕11)
/// </summary>
R3,
/// <summary>
/// 方向盤 L3 鍵(按鈕12)
/// </summary>
L3,
/// <summary>
/// 方向盤 + 鍵(按鈕20)
/// </summary>
plus,
/// <summary>
/// 方向盤 - 鍵(按鈕21)
/// </summary>
subtract,
/// <summary>
/// 方向盤 回車 鍵(按鈕24)
/// </summary>
enter,
/// <summary>
/// 方向盤 logo 鍵(按鈕25)
/// </summary>
logoBtn
}
public enum CursorType
{
/// <summary>
/// Up
/// rec.rgdwPOV[0] = 0
/// </summary>
up,
/// <summary>
/// UP-RIGHT
/// rec.rgdwPOV[0] = 4500
/// </summary>
up_right,
/// <summary>
/// right
/// rec.rgdwPOV[0] = 9000
/// </summary>
right,
/// <summary>
/// DOWN-RIGHT
/// rec.rgdwPOV[0] = 13500
/// </summary>
down_right,
/// <summary>
/// down
/// rec.rgdwPOV[0] = 18000
/// </summary>
down,
/// <summary>
/// DOWN-LEFT
/// rec.rgdwPOV[0] = 22500
/// </summary>
down_left,
/// <summary>
/// left
/// rec.rgdwPOV[0] = 27000
/// </summary>
left,
/// <summary>
/// UP-LEFT
/// rec.rgdwPOV[0] = 31500
/// </summary>
up_left
}
public class LogitechController : MonoBehaviour
{
public GearShifter gearShifter;
public Pedals pedals;
public SteeringWheel steeringWheel;
private LogitechGSDK.DIJOYSTATE2ENGINES rec;
/// <summary>
/// 方向盤
/// </summary>
public class SteeringWheel
{
/// <summary>
/// 剛點擊按鈕時觸發一次
/// LogitechWheelButtonType:按鈕類型
/// </summary>
public Action<LogitechSteeringWheelButtonType> OnTriggered;
/// <summary>
/// 維持點擊按鈕時一直觸發
/// LogitechWheelButtonType:按鈕類型
/// </summary>
public Action<LogitechSteeringWheelButtonType> OnPressed;
/// <summary>
/// 鬆開按鈕時觸發一次
/// LogitechWheelButtonType:按鈕類型
/// </summary>
public Action<LogitechSteeringWheelButtonType> OnReleased;
/// <summary>
/// 點擊按鈕時觸發一次,按住按鈕一直觸發
/// CursorType:方向類型
/// </summary>
public Action<CursorType> OnCursor;
/// <summary>
/// 每旋轉一檔旋鈕時觸發一次
/// bool:返回true,順時針旋轉;返回flase,逆時針旋轉
/// </summary>
public Action<bool> OnKnob;
/// <summary>
/// 轉動方向盤觸發
/// float:不觸碰方向盤,值一直爲0,觸碰後左扭到盡:-32768,右扭到盡爲32767
/// </summary>
public Action<float> OnSteeringWheel;
}
/// <summary>
/// 腳踏板
/// </summary>
public class Pedals
{
/// <summary>
/// 離合
/// float:不觸碰腳踏板,值一直爲0,觸碰後踩盡:-32768,鬆開爲32767
/// </summary>
public Action<float> Clutch;
/// <summary>
/// 剎車
/// float:不觸碰腳踏板,值一直爲0,觸碰後踩盡:-32768,鬆開爲32767
/// </summary>
public Action<float> Brake;
/// <summary>
/// 油門
/// float:不觸碰腳踏板,值一直爲0,觸碰後踩盡:-32768,鬆開爲32767
/// </summary>
public Action<float> Throttle;
}
/// <summary>
/// 檔位器
/// </summary>
public class GearShifter
{
/// <summary>
/// 剛進入新檔位時觸發一次
/// int:檔位數(0:R檔,1:1檔,2:2檔,以此類推)
/// </summary>
public Action<int> OnTriggered;
/// <summary>
/// 維持檔位時一直觸發
/// int:檔位數(0:R檔,1:1檔,2:2檔,以此類推)
/// </summary>
public Action<int> OnPressed;
/// <summary>
/// 離開檔位時觸發一次
/// int:檔位數(0:R檔,1:1檔,2:2檔,以此類推)
/// </summary>
public Action<int> OnReleased;
}
private void Awake()
{
gearShifter = new GearShifter();
pedals = new Pedals();
steeringWheel = new SteeringWheel();
#region test
//gearShifter.OnTriggered += (index) => { Debug.Log(index + " OnTriggered"); };
//gearShifter.OnPressed += (index) => { Debug.Log(index + " OnPressed"); };
//gearShifter.OnReleased += (index) => { Debug.Log(index + "OnReleased "); };
//pedals.Clutch += (xx) => { Debug.Log(xx + "Clutch"); };
//pedals.Brake += (xx) => { Debug.Log(xx + "Brake"); };
//pedals.Throttle += (xx) => { Debug.Log(xx + "Throttle"); };
//steeringWheel.OnTriggered += (index) => { Debug.Log(index + " OnTriggered"); };
//steeringWheel.OnPressed += (index) => { Debug.Log(index + " OnPressed"); };
//steeringWheel.OnReleased += (index) => { Debug.Log(index + "OnReleased "); };
//steeringWheel.OnCursor += (inx) => { Debug.Log(inx + "OnReleased "); };
//steeringWheel.OnKnob += (inx) => { Debug.Log(inx + "OnReleased "); };
//steeringWheel.OnSteeringWheel += (inx) => { Debug.Log(inx + " "); };
#endregion
bool x = false;
while (x == false)
{
x = LogitechGSDK.LogiSteeringInitialize(false);
Debug.Log("SteeringInit:" + x);
}
//
}
private void Update()
{
if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
{
#region 檔位器
//擋位 1 擋
if (LogitechGSDK.LogiButtonTriggered(0, 12))
{
if(gearShifter.OnTriggered != null) gearShifter.OnTriggered(1);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 12))
{
if (gearShifter.OnPressed != null) gearShifter.OnPressed(1);
}
else if (LogitechGSDK.LogiButtonReleased(0, 12))
{
if (gearShifter.OnReleased != null) gearShifter.OnReleased(1);
}
//擋位 2 擋
if (LogitechGSDK.LogiButtonTriggered(0, 13))
{
if (gearShifter.OnTriggered != null) gearShifter.OnTriggered(2);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 13))
{
if (gearShifter.OnPressed != null) gearShifter.OnPressed(2);
}
else if (LogitechGSDK.LogiButtonReleased(0, 13))
{
if (gearShifter.OnReleased != null) gearShifter.OnReleased(2);
}
//擋位 3 擋
if (LogitechGSDK.LogiButtonTriggered(0, 14))
{
if (gearShifter.OnTriggered != null) gearShifter.OnTriggered(3);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 14))
{
if (gearShifter.OnPressed != null) gearShifter.OnPressed(3);
}
else if (LogitechGSDK.LogiButtonReleased(0, 14))
{
if (gearShifter.OnReleased != null) gearShifter.OnReleased(3);
}
//擋位 4 擋
if (LogitechGSDK.LogiButtonTriggered(0, 15))
{
if (gearShifter.OnTriggered != null) gearShifter.OnTriggered(4);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 15))
{
if (gearShifter.OnPressed != null) gearShifter.OnPressed(4);
}
else if (LogitechGSDK.LogiButtonReleased(0, 15))
{
if (gearShifter.OnReleased != null) gearShifter.OnReleased(4);
}
//擋位 5 擋
if (LogitechGSDK.LogiButtonTriggered(0, 16))
{
if (gearShifter.OnTriggered != null) gearShifter.OnTriggered(5);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 16))
{
if (gearShifter.OnPressed != null) gearShifter.OnPressed(5);
}
else if (LogitechGSDK.LogiButtonReleased(0, 16))
{
if (gearShifter.OnReleased != null) gearShifter.OnReleased(5);
}
//擋位 6 擋
if (LogitechGSDK.LogiButtonTriggered(0, 17))
{
if (gearShifter.OnTriggered != null) gearShifter.OnTriggered(6);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 17))
{
if (gearShifter.OnPressed != null) gearShifter.OnPressed(6);
}
else if (LogitechGSDK.LogiButtonReleased(0, 17))
{
if (gearShifter.OnReleased != null) gearShifter.OnReleased(6);
}
//擋位 R 擋
if (LogitechGSDK.LogiButtonTriggered(0, 18))
{
if (gearShifter.OnTriggered != null) gearShifter.OnTriggered(0);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 18))
{
if (gearShifter.OnPressed != null) gearShifter.OnPressed(0);
}
else if (LogitechGSDK.LogiButtonReleased(0, 18))
{
if (gearShifter.OnReleased != null) gearShifter.OnReleased(0);
}
#endregion
#region 腳踏板
rec = LogitechGSDK.LogiGetStateUnity(0);
//離合
if (pedals.Clutch != null) pedals.Clutch(rec.rglSlider[0]);
//剎車
if (pedals.Brake != null) pedals.Brake(rec.lRz);
//油門
if (pedals.Throttle != null) pedals.Throttle(rec.lY);
#endregion
#region 方向盤
rec = LogitechGSDK.LogiGetStateUnity(0);
if (steeringWheel.OnSteeringWheel != null) steeringWheel.OnSteeringWheel(rec.lX);
//方向盤 X 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 0))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.x);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 0))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.x);
}
else if (LogitechGSDK.LogiButtonReleased(0, 0))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.x);
}
//方向盤 □ 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 1))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.rect);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 1))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.rect);
}
else if (LogitechGSDK.LogiButtonReleased(0, 1))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.rect);
}
//方向盤 ○ 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 2))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.circle);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 2))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.circle);
}
else if (LogitechGSDK.LogiButtonReleased(0, 2))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.circle);
}
//方向盤 △ 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 3))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.triangle);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 3))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.triangle);
}
else if (LogitechGSDK.LogiButtonReleased(0, 3))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.triangle);
}
//方向盤 右撥片 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 4))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.rightDialSlice);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 4))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.rightDialSlice);
}
else if (LogitechGSDK.LogiButtonReleased(0, 4))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.rightDialSlice);
}
//方向盤 左撥片 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 5))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.leftDialSlice);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 5))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.leftDialSlice);
}
else if (LogitechGSDK.LogiButtonReleased(0, 5))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.leftDialSlice);
}
//方向盤 R2 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 6))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.R2);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 6))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.R2);
}
else if (LogitechGSDK.LogiButtonReleased(0, 6))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.R2);
}
//方向盤 L2 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 7))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.L2);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 7))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.L2);
}
else if (LogitechGSDK.LogiButtonReleased(0, 7))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.L2);
}
//方向盤 SHARE 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 8))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.share);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 8))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.share);
}
else if (LogitechGSDK.LogiButtonReleased(0, 8))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.share);
}
//方向盤 OPTION 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 9))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.option);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 9))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.option);
}
else if (LogitechGSDK.LogiButtonReleased(0, 9))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.option);
}
//方向盤 R3 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 10))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.R3);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 10))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.R3);
}
else if (LogitechGSDK.LogiButtonReleased(0, 10))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.R3);
}
//方向盤 L3 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 11))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.L3);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 11))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.L3);
}
else if (LogitechGSDK.LogiButtonReleased(0, 11))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.L3);
}
//方向盤 + 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 19))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.plus);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 19))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.plus);
}
else if (LogitechGSDK.LogiButtonReleased(0, 19))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.plus);
}
//方向盤 - 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 20))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.subtract);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 20))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.subtract);
}
else if (LogitechGSDK.LogiButtonReleased(0, 20))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.subtract);
}
//方向盤 回車 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 23))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.enter);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 23))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.enter);
}
else if (LogitechGSDK.LogiButtonReleased(0, 23))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.enter);
}
//方向盤 logo 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 24))
{
if (steeringWheel.OnTriggered != null) steeringWheel.OnTriggered(LogitechSteeringWheelButtonType.logoBtn);
}
else if (LogitechGSDK.LogiButtonIsPressed(0, 24))
{
if (steeringWheel.OnPressed != null) steeringWheel.OnPressed(LogitechSteeringWheelButtonType.logoBtn);
}
else if (LogitechGSDK.LogiButtonReleased(0, 24))
{
if (steeringWheel.OnReleased != null) steeringWheel.OnReleased(LogitechSteeringWheelButtonType.logoBtn);
}
//方向盤 紅色滾輪右滾 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 21))
{
if (steeringWheel.OnKnob != null) steeringWheel.OnKnob(true);
}
//方向盤 紅色滾輪左滾 鍵
if (LogitechGSDK.LogiButtonTriggered(0, 22))
{
if (steeringWheel.OnKnob != null) steeringWheel.OnKnob(false);
}
switch (rec.rgdwPOV[0])
{
case (0): //Up
if (steeringWheel.OnCursor != null) steeringWheel.OnCursor(CursorType.up);
break;
case (4500): // UP-RIGHT
if (steeringWheel.OnCursor != null) steeringWheel.OnCursor(CursorType.up_left);
break;
case (9000): //right
if (steeringWheel.OnCursor != null) steeringWheel.OnCursor(CursorType.right);
break;
case (13500): //DOWN-RIGHT
if (steeringWheel.OnCursor != null) steeringWheel.OnCursor(CursorType.down_right);
break;
case (18000): //down
if (steeringWheel.OnCursor != null) steeringWheel.OnCursor(CursorType.down);
break;
case (22500): //DOWN-LEFT
if (steeringWheel.OnCursor != null) steeringWheel.OnCursor(CursorType.down_left);
break;
case (27000): //left
if (steeringWheel.OnCursor != null) steeringWheel.OnCursor(CursorType.left);
break;
case (31500): //UP-LEFT
if (steeringWheel.OnCursor != null) steeringWheel.OnCursor(CursorType.up_left);
break;
}
#endregion
}
}
void OnApplicationQuit()
{
Debug.Log("SteeringShutdown:" + LogitechGSDK.LogiSteeringShutdown());
}
}
}