pyunity.script module¶
Module to manage loading scripts from files.
-
class
pyunity.script.Behaviour[source]¶ Bases:
pyunity.core.ComponentBase class for behaviours that can be scripted.
-
gameObject¶ GameObject that the component belongs to.
Type: GameObject
-
AddComponent(component)¶ Calls AddComponent on the component’s GameObject.
Parameters: component (Component) – Component to add. Must inherit from Component
-
-
pyunity.script.CheckScript(text)[source]¶ Check if
textis 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
importstatement - 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
-
pyunity.script.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.modulesthat 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 namedPyUnityScriptsis present and does not have the__pyunity__variable set, then a warning will be issued and it will be replaced.