unity3d python communication

Unity3D-Python-Communication

GitHub - offchan42/Unity3D-Python-Communication: :zap: A very fast, simple, and general inter-process communication example between Unity3D C# and Python, using ZeroMQ

⚡️ A very fast, simple, and general inter-process communication example between Unity3D C# and Python, using ZeroMQ.

 PS. It looks slow in the GIF above because I put a delay of one second between each message so that you can see it working.

Core Pillars

  • very fast — ZeroMQ is a networking library that allows you to send huge amount of data from server to client in a short period of time. I'm talking about casually sending/receiving 10,000 requests per second.
  • simple — You don't have to explicitly open and bind a socket or know anything about low-level networking.
  • general — You can use this to send/receive any kind of data request. You can send image, video, text, JSON, file, or whatever you want. In this example, we are sending text.
  • inter-process — The communication is done inside the same machine. Which means very low-latency.

Introduction

  • Have you ever tried to communicate C# code in Unity3D with Python before but could not find a satisfying solution?
  • Have you ever tried implementing communication protocol using file read/write and found out that it's a stupid approach?
  • Have you ever tried communicating using Web HTTP request and found out that it's stupidly slow and high latency?
  • Have you ever tried communicating using socket/TCP/UDP stuff, but it feels like you are reinventing the wheel and you are becoming a network engineer?
  • Have you ever tried to communicate by emulating a serial port, and found out that it's not how cool guys do work?
  • Have you ever tried to send Unity input to python and do some scientific work (maybe even machine learning task) and return the output to Unity?
  • Have you ever tried to build a .dll from python or even rewrite everything in C# because you don't know how to communicate between python and C# processes?
  • Have you ever tried to embed IronPython or Python.NET inside Unity but it doesn't allow you to install your amazing external python libraries? (And its minimal power is pretty ridiculous compared to your external python)
  • Have you ever tried to export a TensorFlow Protobuf Graph (Deep learning model) and use TensorFlowSharp or OpenCVForUnity to import the graph inside Unity because you want to use the model to predict stuff in Unity, but it doesn't allow you to use/utilize your new NVIDIA GeForce RTX 2080Ti, and it's also hard to code?
  • Tried MLAgents, anyone?

Getting Started

  1. Clone this repository using git clone https://github.com/offchan42/Unity3D-Python-Communication.git command.
  2. Open UnityProject (its dll files are targeting .NET 4.x version) and run Assets/NetMQExample/Scenes/SampleScene.
  3. Run python file PythonFiles/server.py using command python server.py on a command prompt.
  4. You should start seeing messages being logged inside Unity and the command prompt.

Specifically, Unity will send request with a message Hello 10 times, and Python will simply reply World 10 times. There is a one second sleep between each reply on the server (to simulate long processing time of the request).

Please read the comments inside PythonFiles/server.py and UnityProject/Assets/NetMQExample/Scripts/ and you will understand everything more deeply.

The most important thing is that you should follow the 4 getting started steps first. Don't skip it! ❣️

After you've understood most of the stuff but it's not advanced enough, you should consult the official ØMQ - The Guide.

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值