在Gear VR上模仿游戏手柄?

时间:2016-07-19 21:55:35

标签: android input adb gamepad gear-vr

我上周收到了我的Gear VR,发现Oculus Home中大多数更好的应用需要一个游戏手柄。所以我有一个疯狂的想法,试图使用我的四个xbox 360控制器之一,连接到我的PC,通过WiFi发送命令到Gear Vr作为假游戏手柄。

现在我远离一个真正的程序员,我的大部分编码经验来自于教我自己如何使用统一,但我有一些进步(尽管是一个hacky) - 我写了一个团结的脚本来阅读从我的游戏手柄输入并通过无线ABD终端发送到应用程序。

using UnityEngine;
using System;
using System.Collections;
using System.Diagnostics;
using XInputDotNetPure;
using System.IO;

public class Datagetter : MonoBehaviour {
public Process process;
public StreamWriter mySW;
public StreamReader mySR;
public bool left = false;
public bool right = false;
public bool up = false;
public bool down = false;
public bool start = false;
public bool xbtn = false;

// Use this for initialization
void Start () {
process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.WorkingDirectory = "C:\\Windows\\System32";
process.StartInfo.FileName = "cmd.exe";

// Redirects the standard input so that commands can be sent to the shell.
process.StartInfo.RedirectStandardInput = true;
// Runs the specified command and exits the shell immediately.
//process.StartInfo.Arguments = @"/c ""dir""";



process.Start();
mySW = process.StandardInput;
mySW.WriteLine ("cd /d C:\\Users\\user");
mySW.WriteLine ("adb tcpip 5555");/////////////
mySW.WriteLine ("adb connect 10.0.0.11");/////////////////
}

IEnumerator timer(){
yield return new WaitForSeconds (3f);
connect ();
}
public void connect(){
mySW.WriteLine ("adb connect 10.0.0.3");
}

// Update is called once per frame
void Update () {
if (GamePad.GetState (PlayerIndex.One).DPad.Left == ButtonState.Pressed) {
if(!left){
left = true;    
mySW.WriteLine ("adb shell input keyevent 21");
mySW.Flush ();
}
}

if (GamePad.GetState (PlayerIndex.One).Buttons.X == ButtonState.Pressed) {
if (!right) {
xbtn = true;
mySW.WriteLine ("adb shell input keyevent 188");
mySW.Flush ();
}
}

if (GamePad.GetState (PlayerIndex.One).DPad.Right == ButtonState.Pressed) {
if (!right) {
right = true;
mySW.WriteLine ("adb shell input keyevent 22");
mySW.Flush ();
}
}
if (GamePad.GetState (PlayerIndex.One).DPad.Up == ButtonState.Pressed) {
if (!up) {
up = true;
mySW.WriteLine ("adb shell input keyevent 19");
mySW.Flush ();
}
//          UnityEngine.Debug.Log (mySR.ReadLine());
}
if (GamePad.GetState (PlayerIndex.One).DPad.Down == ButtonState.Pressed) {
if (!down) {
down = true;
mySW.WriteLine ("adb shell input keyevent 20");
mySW.Flush ();
}
}
if (GamePad.GetState (PlayerIndex.One).Buttons.Start == ButtonState.Pressed) {
if (!start) {
start = true;
mySW.WriteLine ("control");
mySW.Flush ();
}
}
if (GamePad.GetState (PlayerIndex.One).DPad.Down == ButtonState.Released) {
if (down) {
down = false;
}
}
if (GamePad.GetState (PlayerIndex.One).DPad.Up == ButtonState.Released) {
if (up) {
up = false;
}
}
if (GamePad.GetState (PlayerIndex.One).DPad.Right == ButtonState.Released) {
if (right) {
right = false;
}
}
if (GamePad.GetState (PlayerIndex.One).DPad.Left == ButtonState.Released) {
if (left) {
left = false;
}
}

if (GamePad.GetState (PlayerIndex.One).Buttons.Start == ButtonState.Released) {
if (start) {
start = false;
}
}
}
}

使用此代码,我可以使用游戏手柄在非VR应用程序和系统菜单中移动,但由于某些原因,没有任何keyEvents在gearVr中工作,唯一的例外是我发现到目前为止是关键事件3它模拟了后退按钮。

我知道这段代码非常可怕,一旦我掌握了基本功能,我会尝试正确地重写它,但是现在我已经很困难了。任何人都知道如何解决这个问题?对于那些不希望用价格过高,不太舒服的游戏手柄替换当前游戏手柄的人来说,这可能是一个非常有用的解决方案。

0 个答案:

没有答案