【发布时间】:2019-04-10 15:51:49
【问题描述】:
我目前正在研究我的研究生项目,它是一个自动驾驶仪,我正在统一制作飞机以及 python 中的所有机器学习内容,python 代码将只返回飞机将执行的“上、下、左、对,enginepower up,...) 并且 c# 代码会处理所有的物理等等,所以我想模拟如果(左)那么计算机会按下(A)。
我已经尝试过输入模拟器,但仅此而已。
string t = GUIUtility.systemCopyBuffer; // this will get the input from python
if (t=="left") // if what the neural network choose is left do this
{
//what I need to convert the "left" to an actual keyboard press to
//be used by the crossplatformmanager
}
float roll = CrossPlatformInputManager.GetAxis("Horizontal");
我希望:
if (t=="left")
{
keyboardbutton="A"
}
CrossPlatformInputManager.GetAxis 将把它当作我实际按下的键。
【问题讨论】:
-
有趣的项目!但对我来说并不完全清楚:您正试图让 python 控制飞机(使其上升或下降等......),然后在统一 3D 引擎中使用它来可视化它,对吗?那么为什么需要将 C# 中的输入导出到 python 呢?不是反过来吗?
-
afaik 您不能在 Unity 中引发系统范围的键盘事件,但您可以使用本地套接字连接将命令传递给 python 脚本(如果该脚本在套接字上侦听)。如果 Unity 本身发生了某些事情,为什么不简单地将其添加到
if中呢?换句话说:你到底想达到什么目的? -
或(仅在 Windows 上)您可以尝试 Windows Input Simulator
-
您是否偶然发现了Unity help forums? Reddit 也有话要说。特别是你可能会觉得这个suggestion 很有趣。