Attention
You are viewing PyUnity docs under the develop
branch.
As such, they are only applicable if you installed from source.
Go to https://docs.pyunity.x10.bz/en/latest/ for the most recent
release.
pyunity.gui module¶
Source code: pyunity/gui.py
- class pyunity.gui.Canvas[source]¶
Bases:
Component
A Component that manages GUI interactions and 2D rendering. Only GameObjects which are a descendant of a Canvas will be rendered.
- class pyunity.gui.RectAnchors[source]¶
Bases:
RectData
A type of RectData which represents the anchor points of a RectTransform.
- class pyunity.gui.RectOffset[source]¶
Bases:
RectData
Rect to represent the offset from the anchor points of a RectTransform.
- class pyunity.gui.RectTransform[source]¶
Bases:
SingleComponent
A Component that represents the size, position and orientation of a 2D object.
- anchors = None¶
Anchor points of the RectTransform. Measured between Vector2(0, 0) and Vector2(1, 1)
- Type:
- offset = None¶
Offset vectors representing the offset of opposite corners from the anchors. Measured in pixels
- Type:
- pivot = None¶
Point in which the object rotates around. Measured between Vector2(0, 0) and Vector2(1, 1)
- Type:
- property parent¶
- class pyunity.gui.GuiComponent[source]¶
Bases:
Component
A Component that represents a clickable area.
- class pyunity.gui.NoResponseGuiComponent[source]¶
Bases:
GuiComponent
A Component that blocks all clicks that are behind it.
- class pyunity.gui.GuiRenderComponent[source]¶
Bases:
NoResponseGuiComponent
A Component that renders something in its RectTransform.
- class pyunity.gui.Image2D[source]¶
Bases:
GuiRenderComponent
A 2D image component, which is uninteractive.
- class pyunity.gui.RenderTarget[source]¶
Bases:
GuiRenderComponent
- class pyunity.gui.Button[source]¶
Bases:
GuiComponent
A Component that calls a function when clicked.
- class pyunity.gui.WinFontLoader[source]¶
Bases:
_FontLoader
- classmethod LoadFile(name)[source]¶
Use the Windows registry to find a font file name.
- Parameters:
name (str) – Font name. This is not the same as the file name.
- Returns:
Font file name
- Return type:
- Raises:
PyUnityException – If the font is not found
- class pyunity.gui.UnixFontLoader[source]¶
Bases:
_FontLoader
- classmethod LoadFile(name)[source]¶
Use
fc-match
to find the font file name.- Parameters:
name (str) – Font name. This is not the same as the file name.
- Returns:
Font file name
- Return type:
- Raises:
PyUnityException – If the font is not found
- class pyunity.gui.FontLoader[source]¶
Bases:
UnixFontLoader
- class pyunity.gui.Font[source]¶
Bases:
object
Font object to represent font data.
- _font¶
Image font object. Do not use unless you know what you are doing.
- Type:
ImageFont.FreeTypeFont
- class pyunity.gui.Text[source]¶
Bases:
GuiRenderComponent
Component to render text.
- rect¶
RectTransform of the GameObject. Can be None
- Type:
Notes
Modifying
font
,text
, orcolor
will callGenTexture()
.
- class pyunity.gui.CheckBox[source]¶
Bases:
GuiComponent
A component that updates the Image2D of its GameObject when clicked.
- class pyunity.gui.Gui[source]¶
Bases:
object
Helper class to create GUI GameObjects. Do not instantiate.
- classmethod MakeButton(name, scene, text='Button', font=None, color=None, texture=None)[source]¶
Create a Button GameObject and add all relevant GameObjects to the scene.
- Parameters:
name (str) – Name of the GameObject
scene (Scene) – Scene to add all generated GameObjects to
text (str, optional) – Text content of the button, by default “Button”
font (Font, optional) – Default font to use, if None then “Arial” is used
color (Color, optional) – Fill color of the button text, by default black
texture (Texture2D, optional) – Texture for the button background.
- Returns:
A tuple containing the
RectTransform
of button, theButton
component and theText
component.- Return type:
Notes
This will create 3 GameObjects in this hierarchy:
<specified button name> |- Button |- Text
The generated GameObject can be accessed from the
gameObject
property of the returned components. TheButton
GameObject will have two components,Button
andRectTransform
. TheButton
GameObject will have two components,Image2D
andRectTransform
.
- classmethod MakeCheckBox(name, scene)[source]¶
Create a CheckBox GameObject and add the appropriate components needed.
- Parameters:
- Returns:
A tuple of the
RectTransform
as well as theCheckBox
component.- Return type:
Notes
The generated GameObject can be accessed from the
gameObject
property of the returned components. The GameObject will have 3 properties added: aRectTransform
, aCheckBox
and anImage2D
.