在Unity中调用Python

新手上路,请多包涵

如题:我想知道在Unity里面怎么调用Python,怎么和Python的数据互通,我在C#的控制台程序中可以进行数据互通,
但是在Unity里面互通失败,,,,,求解 求方法。。谢谢

阅读 17.3k
1 个回答
新手上路,请多包涵

或许你可以考虑用ProcessStartInfo来实现。

private static void RunPythonCmd( string args)
{
   ProcessStartInfo start = new ProcessStartInfo ();
    start.FileName = "python";
    start.Arguments = args;
    start.UseShellExecute = false;
    start.RedirectStandardOutput = true;
   using ( Process process = Process.Start(start))
    {
        using ( StreamReader reader = process.StandardOutput)
        {
            string result = "";
            while (result != null)
            {

                result = reader.ReadLine();
             

                UnityEngine. Debug.Log(result);
            }

        }
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题