Skip to content

Instantly share code, notes, and snippets.

View rayzchen's full-sized avatar
🎉
Developing PyUnity

Ray Chen rayzchen

🎉
Developing PyUnity
  • The PyUnity Team
  • London
View GitHub Profile
@rayzchen
rayzchen / hook.py
Last active March 29, 2022 16:13
Versatile module wrapper for multiple callback functions
import sys
import types
class Hook:
def __init__(self, defaultfunc=None):
self._defaultfunc = defaultfunc
self._funcs = []
def __call__(self, *args):
if len(self._funcs) == 0 and callable(self._defaultfunc):
@rayzchen
rayzchen / syshook.py
Last active March 29, 2022 16:06
`sys.excepthook` wrapper
import sys
import types
class Hook:
_sys = sys
def __init__(self):
self._default = True
self._funcs = []
def __call__(self, exctype, value, tb):
@rayzchen
rayzchen / ball.py
Last active October 11, 2021 20:48
Roll A Ball example for PyUnity
from pyunity import *
class PlayerController(Behaviour):
speed = ShowInInspector(int, 15)
rigidbody = ShowInInspector(Rigidbody)
def Update(self, dt):
x = Input.GetRawAxis("Horizontal")
y = Input.GetRawAxis("Vertical")
@rayzchen
rayzchen / bootstrap.py
Last active January 10, 2024 11:51
Convert any Python package into a single Python extension file (.so or .pyd)
import sys
import importlib
class CythonPackageMetaPathFinder(importlib.abc.MetaPathFinder):
def __init__(self, name_filter):
super(CythonPackageMetaPathFinder, self).__init__()
self.name_filter = name_filter
def find_module(self, fullname, path):
if fullname.startswith(self.name_filter + "."):