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:

object

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
transform

Transform that the component belongs to.

Type:Transform
Start()[source]

Called every time a scene is loaded up.

Update(dt)[source]

Called every frame.

Parameters:dt (float) – Time since last frame, sent by the scene that the Behaviour is in.
FixedUpdate(dt)[source]

Called every frame, in each physics step.

Parameters:dt (float) – Length of this physics step
LateUpdate(dt)[source]

Called every frame, after physics processing.

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:

  1. The line is an import statement
  2. The line is just whitespace or blank
  3. The line is just a comment preceded by whitespace or nothing
  4. The line is a class definition
  5. The line has an indentation at the beginning

These checks are essential to ensure no malicious code is run to break the PyUnity engine.

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 called PyUnityScripts, 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 named PyUnityScripts is present and does not have the __pyunity__ variable set, then a warning will be issued and it will be replaced.

class pyunity.files.Texture2D(path_or_im)[source]

Bases: object

Class to represent a texture.

load()[source]

Loads the texture and sets up an OpenGL texture name.

setImg(im)[source]
use()[source]

Binds the texture for usage. The texture is reloaded if it hasn’t already been.

class pyunity.files.Skybox(path)[source]

Bases: object

Skybox model consisting of 6 images

compile()[source]
use()[source]
class pyunity.files.Prefab(gameObject, components)[source]

Bases: object

Prefab model

class pyunity.files.File(path, type, uuid=None)[source]

Bases: object

class pyunity.files.Project(path, name)[source]

Bases: object

import_file(localPath, type, uuid=None)[source]
reimport_file(localPath)[source]
get_file_obj(uuid)[source]
write_project()[source]
static from_folder(filePath)[source]
save_mat(mat, name)[source]
load_mat(file)[source]