Unity and python server

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

POC for a Unity game client and dedicated server with websockets!

License

hsadler/unity-websocket-multiplayer

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Читайте также:  Цвета шрифтов html таблица

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Unity Websocket Multiplayer

POC for a Unity game client and game server with websockets!

There are 2 implementations of the game server. One in Python and one in Golang. The APIs for both servers are identical.

  • Unity Editor: version 2020.3.21f1
  • Docker
  • Docker Compose
  • ngrok (optional)
docker build -t python-gameserver:latest ./PythonGameServer docker-compose -f ./PythonGameServer/docker-compose.yaml up
docker build -t golang-gameserver:latest ./GolangGameServer docker-compose -f ./GolangGameServer/docker-compose.yaml up

The players is simply a circle you can move around with WASD. Other connected players are red and the main player is white.

Testing Multiple Client Connections

Now you can connect multiple players who can see each other’s movement!

This is a very simple proof-of-concept and could be used as a starting point for making a multiplayer game with the Unity engine.

It demonstrates game-client to game-server connection establishment, message transmission, and connection termination with the websocket protocol.

The entire game-server’s code resides in:
PythonGameServer/server.py (python server)
GolangGameServer/server.go (golang server)

The game-client’s websocket management resides in:
UnityWebSocketClient/Assets/Scripts/SceneManagerScript.cs

The Golang game server’s architecture is inspired by this chat example.

About

POC for a Unity game client and dedicated server with websockets!

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A simple Unity 3D server — Python asyncio client over TCP example

License

NumesSanguis/Basic-Unity3D-Python-server

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This project served as a way to connect Python with Unity 3D. However, in my current project (https://github.com/NumesSanguis/FACSvatar) I switched to ZeroMQ for this, which is more stable and more robust than the code found here. So I would recommend looking at that code.

A Python 3.6 client with asyncio for asynchronous execution, that can send to and receive JSON messages from a Unity3D server (Unity 2017.2.0f3).

Test usage Unity 3D — Python client

  1. Start Unity 3D from BasicUnityPython & press play (you should see in Unity: Server is listening)
  2. Open terminal in this folder and run: python client_asyncio.py , you should see in Unity: «Hello World x» / Python terminal: Send: Received: Close the socket

Test usage Python server — Python client

  1. Open terminal in this folder and run: python server_asyncio.py
  2. Open another terminal here and run: python client_asyncio.py

Test usage Unity 3D — Python with SocketIO

  1. Start Unity 3D from BasicUnityPython_aiohttp & press play
  2. Open terminal in this folder and run: python client_asyncio_aiohttp.py (you should see in Unity: «data_stuff»: x / Python terminal: message: )

To setup in your own project (asyncio, not SocketIO)

  • Get JSON object addon in your Unity project: https://assetstore.unity.com/packages/tools/input-management/json-object-710
  • Add TCPTestServer.cs to your project from this Github if you want JSON support, or: https://gist.github.com/danielbierwirth/0636650b005834204cb19ef5ae6ccedb

Communication over SocketIO is inspired by tawnkramer/sdsandbox (https://github.com/tawnkramer/sdsandbox/tree/master). However SocketIO (both the original with FLASK and modified with aiohttp) was found to be way slower.

Measured with a phone stopwatch for 10 seconds:

  • Just asyncio: 7738 messages received from Unity
  • asyncio with SocketIO and aiohttp: 97 messages received from Unity (seems to be faster than no asyncio with FLASK)

Therefore simple asyncio about 80 times as fast with this unprofessional measurement.

About

A simple Unity 3D server — Python asyncio client over TCP example

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Two-way communication between Unity (C#) and Python 3

License

Siliconifier/Python-Unity-Socket-Communication

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

Readme.md

Created by Youssef Elashry to solve the common problem for TWO-WAY communication Unity/C# applications with Python 3.

The files attached will allow you to both send and receive data between Unity (C#) and Python 3.

Feel free to use this in your individual or commercial projects BUT make sure to reference me as: Two-way communication between Python 3 and Unity (C#) — Y. T. Elashry It would be appreciated if you send me how you have used this in your projects (e.g. Machine Learning) at youssef.elashry@gmail.com

Use at your own risk Use under the Apache License 2.0

  • Ensure IP, send and receive ports are the same between server.py and UdpSocket.cs [edited via inspector] scripts. They are the same in the demo.
  • Run server.py on the python side to send and receive data from Unity
  • Add UdpSocket.cs to a game object in a scene
  • RECOMMENDED: Run server.py THEN Unity Scene
  • To be able to use the UdpSocket.cs script for your own script, REMOVE the lines and functions with a // DELETE THIS comment. These lines and functions are for the purposes of the demo and do not affect the main functionality.

alt text

About

Two-way communication between Unity (C#) and Python 3

Источник

Easily Start a Server to Run a Unity Web Build in your Browser

Easy ways to start a server to run your Unity build for web. Simple methods using Python, Javascript or directly from your browser.

Published Thu, Jan 28, 2021 by William

When building a Unity project for web, the process will output a HTML file as well as a Build folder, containing the WASM blob to be streamed to play the game.

The problem here is that if you try to open the HTML you will be greeted by this nice little error message:

error message unity no server

Right, so we need a server to run our game. So how do we do that? I’ll show you a few easy ways to do this, using your preferred tool between Python, Javascript or a browser extension.

Using Python

Now this is the most useful one in my opinion, as Python comes bundled with installs of Linux and Mac and odds are if you’re a dev you’re also using it as your preferred scripting language on Windows. It’s also used in Blender so, really, you’re likely to have a python install on your computer even if you don’t know it.

Python has a nice module called to create servers which is called http. It should be part of the standard library so you should already have it.

Now this package will allow us to run a very nice one-liner to create a server (assuming python is in your path). Navigate to the folder where your HTML file and the build folder are and open the command line. Then run the following command:

That’s all! This command should start a server and the first line should be “Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) …». Now open your browser and go to “localhost:8000”. You game should be running properly!

  • Users of Linux and Mac might have to use ‘python3’ instead of ‘python’ in the instruction.
  • After http.server, you can actually set the port on which you’d like to run the server, in case the default 8000 is busy.

Using Javascript

This can be extremely simple. Assuming you have npx installed (npm install -g npx), you can use these instructions:

npx http-server [path] [options]

npx will automatically install the needed dependencies and start the server. If you current working directory is where your files are located, ‘npx http-server’ is all you need. You can change the port with the ‘-p’ flag if needed.

Using a Chrome Extension

One last possibility is to use an extension. A simple one to use is “Web Server for Chrome”.

When starting it you should get the following menu:

menu web server for chrome

Once again this is pretty straightforward: you can choose the folder to serve, the port and whether to automatically return index.html when connecting.

With this, you should have all you need to run your web build in your browser. I haven’t tried any Firefox or Opera extensions, but an equivalent shouldn’t be hard to find. Have fun testing your builds!

Источник

Оцените статью