Logitech g27 Interface Input Message :
這邊程式沒有踏板程式,因為踏板程式發佈跟Unity 編輯 那邊 位址不同,要特別注意。
using UnityEngine;
using System.Collections;
public class LogitechG27InputMassage : MonoBehaviour {
LogitechGSDK.LogiControllerPropertiesData properties;
string actualState, steeringwheel;
float width, height;
public Sprite[] image;
SpriteRenderer sprtie;
public enum selectTool {button, steeringwheel }; // 方向盤跟按鈕(排檔)
public selectTool select;
// Use this for initialization
void Start () {
actualState = "";
steeringwheel = "";
sprtie = GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void Update () {
if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
{
LogitechGSDK.DIJOYSTATE2ENGINES rec;
rec = LogitechGSDK.LogiGetStateUnity(0);
switch (select) {
case selectTool.button:
actualState = "Steering wheel current state : \n\n";
sprtie.sprite = image[0];
// Button Input key Message
for (int i = 0; i < 128; i++)
{
if (rec.rgbButtons[i] == 128)
buttonFunction(i);
}
break;
case selectTool.steeringwheel:
//steeringwheel
sprtie.sprite = image[0];
steeringwheel = "steering Wheel Message: \n\n";
int steeringwheelPosistionAngle = (rec.lX / 36) - 10;
if (steeringwheelPosistionAngle < -900)
{
steeringwheelPosistionAngle = 900;
}
string steeringwheelPosistion = (steeringwheelPosistionAngle > 0) ? "右邊" : "左邊";
steeringwheel += "方向盤 :" + steeringwheelPosistion + ": 角度 : " + steeringwheelPosistionAngle + "\n";
transform.eulerAngles = new Vector3(0,0, -steeringwheelPosistionAngle) ;
break;
}
}
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";
}
void buttonFunction(int number) {
switch (number)
{
case 0:
sprtie.sprite = image[5];
actualState += "按鈕編號: " + number + "\n";
break;
case 1:
sprtie.sprite = image[6];
actualState += "按鈕編號: " + number + "\n";
break;
case 2:
sprtie.sprite = image[7];
actualState += "按鈕編號: " + number + "\n";
break;
case 3:
sprtie.sprite = image[8];
actualState += "按鈕編號: " + number + "\n";
break;
case 8: actualState += "1檔 \n"; break;
case 9: actualState += "2檔 \n"; break;
case 10: actualState += "3檔 \n"; break;
case 11: actualState += "4檔 \n"; break;
case 12: actualState += "5檔 \n"; break;
case 13: actualState += "6檔 \n"; break;
case 15:
sprtie.sprite = image[1];
actualState += "按鈕編號: " + number + "\n";
break;
case 16:
sprtie.sprite = image[3];
actualState += "按鈕編號: " + number + "\n";
break;
case 17:
sprtie.sprite = image[2];
actualState += "按鈕編號: " + number + "\n";
break;
case 18:
sprtie.sprite = image[4];
actualState += "按鈕編號: " + number + "\n";
break;
}
}
void OnGUI() {
actualState = GUI.TextArea(new Rect(Screen.width / Screen.width, Screen.height / Screen.height, 200, 100), actualState, 1000);
steeringwheel = GUI.TextArea(new Rect(Screen.width / Screen.width * 250f, Screen.height / Screen.height, 200, 100), steeringwheel, 1000);
}
}
--------------------------------------
結果圖:
要下載 Logitech g27 Interface Input Message Package之前 請下載 Logitech g27 SDK
這邊程式沒有踏板程式,因為踏板程式發佈跟Unity 編輯 那邊 位址不同,要特別注意。
using UnityEngine;
using System.Collections;
public class LogitechG27InputMassage : MonoBehaviour {
LogitechGSDK.LogiControllerPropertiesData properties;
string actualState, steeringwheel;
float width, height;
public Sprite[] image;
SpriteRenderer sprtie;
public enum selectTool {button, steeringwheel }; // 方向盤跟按鈕(排檔)
public selectTool select;
// Use this for initialization
void Start () {
actualState = "";
steeringwheel = "";
sprtie = GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void Update () {
if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
{
LogitechGSDK.DIJOYSTATE2ENGINES rec;
rec = LogitechGSDK.LogiGetStateUnity(0);
switch (select) {
case selectTool.button:
actualState = "Steering wheel current state : \n\n";
sprtie.sprite = image[0];
// Button Input key Message
for (int i = 0; i < 128; i++)
{
if (rec.rgbButtons[i] == 128)
buttonFunction(i);
}
break;
case selectTool.steeringwheel:
//steeringwheel
sprtie.sprite = image[0];
steeringwheel = "steering Wheel Message: \n\n";
int steeringwheelPosistionAngle = (rec.lX / 36) - 10;
if (steeringwheelPosistionAngle < -900)
{
steeringwheelPosistionAngle = 900;
}
string steeringwheelPosistion = (steeringwheelPosistionAngle > 0) ? "右邊" : "左邊";
steeringwheel += "方向盤 :" + steeringwheelPosistion + ": 角度 : " + steeringwheelPosistionAngle + "\n";
transform.eulerAngles = new Vector3(0,0, -steeringwheelPosistionAngle) ;
break;
}
}
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";
}
void buttonFunction(int number) {
switch (number)
{
case 0:
sprtie.sprite = image[5];
actualState += "按鈕編號: " + number + "\n";
break;
case 1:
sprtie.sprite = image[6];
actualState += "按鈕編號: " + number + "\n";
break;
case 2:
sprtie.sprite = image[7];
actualState += "按鈕編號: " + number + "\n";
break;
case 3:
sprtie.sprite = image[8];
actualState += "按鈕編號: " + number + "\n";
break;
case 8: actualState += "1檔 \n"; break;
case 9: actualState += "2檔 \n"; break;
case 10: actualState += "3檔 \n"; break;
case 11: actualState += "4檔 \n"; break;
case 12: actualState += "5檔 \n"; break;
case 13: actualState += "6檔 \n"; break;
case 15:
sprtie.sprite = image[1];
actualState += "按鈕編號: " + number + "\n";
break;
case 16:
sprtie.sprite = image[3];
actualState += "按鈕編號: " + number + "\n";
break;
case 17:
sprtie.sprite = image[2];
actualState += "按鈕編號: " + number + "\n";
break;
case 18:
sprtie.sprite = image[4];
actualState += "按鈕編號: " + number + "\n";
break;
}
}
void OnGUI() {
actualState = GUI.TextArea(new Rect(Screen.width / Screen.width, Screen.height / Screen.height, 200, 100), actualState, 1000);
steeringwheel = GUI.TextArea(new Rect(Screen.width / Screen.width * 250f, Screen.height / Screen.height, 200, 100), steeringwheel, 1000);
}
}
--------------------------------------
結果圖:
要下載 Logitech g27 Interface Input Message Package之前 請下載 Logitech g27 SDK
download package : http://pan.baidu.com/s/1qWU3Vre
沒有留言:
張貼留言