Banyan Unity is a package built upon the python-banyan framework, allowing two-way communication between Unity's game environment and python applications using lightweight asynchronous socket communication. You can view the installation guide here.
You can view the Unity Asset Store counterpart with its respective documentation here.
For this package you will need Python 3, Python Banyan, and Unity all installed. A general understanding of Alan Yorinks' Python Banyan is highly recommended.
Below is a brief explanation on the purpose of each component. Both the Python and C# components of Banyan Unity are located in this GitHub repository.
The framework used for the Unity C# programs were originally based on the TCP & UDP chat framework developed by HardlyDifficult. You can see a more in-depth guide on this implemented structure here.
This script acts as a demonostration of how one might use Python Banyan to send messages through the Backplane. Each topic starts in a python dictionary format, which is converted JSON before sent.
unitygateway.py uses the Python Banyan framework to constantly listen for messages in the receive_loop()
, then processing those messages in incoming_message_processing()
. While being processed, if the incoming topic is send_to_unity
, the message will be forwarded to BanyanMessageListener.cs in the Unity environment (through port 5000).
BanyanMessageListener.cs listens to unitygateway.py on port 5000. Once receiving a message, the script will decode it and forward the payload off to MessageProcessor.cs on a Unity object.
MessageProcessor.cs will perform an action (in the example, turn the cube a certain color) based on the method DoAction()
after being called by BanyanMessageListener.cs. The script will then use BanyanMessageSender.cs to send a message back to the Python Banyan environment.
BanyanMessageSender.cs sends a message to unitylistener.py on port 5001 after being called from MessageProcessor.cs.
unitylistener.py listens on port 5001 for messages being sent by BanyanMessageSender.cs in the Unity environment. Once receiving a message, unitylistener.py decodes the message and forwards it to the Python Banyan Backplane with the topic of receive_unity_message
.
For further help on installation or other inquiries, feel free to contact me at [email protected]