pyunity.files module¶
Module to load files and scripts. Also manages project structure.
-
pyunity.files.
convert
(type, list)[source]¶ Converts a Python array to a C type from
ctypes
.Parameters: - type (_ctypes.PyCSimpleType) – Type to cast to.
- list (list) – List to cast
Returns: A C array
Return type:
-
class
pyunity.files.
Behaviour
(transform, is_dummy=False)[source]¶ Bases:
pyunity.core.Component
Base class for behaviours that can be scripted.
-
gameObject
¶ GameObject that the component belongs to.
Type: GameObject
-
Update
(dt)[source]¶ Called every frame.
Parameters: dt (float) – Time since last frame, sent by the scene that the Behaviour is in.
-
-
class
pyunity.files.
Scripts
[source]¶ Bases:
object
Utility class for loading scripts in a folder.
-
static
CheckScript
(text)[source]¶ Check if
text
is a valid script for PyUnity.Parameters: text (list) – List of lines Returns: If script is valid or not. Return type: bool Notes
This function checks each line to see if it matches at least one of these criteria:
- The line is an
import
statement - The line is just whitespace or blank
- The line is just a comment preceded by whitespace or nothing
- The line is a class definition
- The line has an indentation at the beginning
These checks are essential to ensure no malicious code is run to break the PyUnity engine.
- The line is an
-
static
LoadScripts
(path)[source]¶ Loads all scripts found in
path
.Parameters: path (Pathlike) – A path to a folder containing all the scripts Returns: A module that contains all the imported scripts Return type: ModuleType Notes
This function will add a module to
sys.modules
that is calledPyUnityScripts
, and can be imported like any other module. The module will also have a variable called__pyunity__
which shows that it is from PyUnity and not a real module. If an existing module namedPyUnityScripts
is present and does not have the__pyunity__
variable set, then a warning will be issued and it will be replaced.
-
static