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:
ComponentA 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:
RectDataA type of RectData which represents the anchor points of a RectTransform.
- class pyunity.gui.RectOffset[source]¶
Bases:
RectDataRect to represent the offset from the anchor points of a RectTransform.
- class pyunity.gui.RectTransform[source]¶
Bases:
SingleComponentA 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:
ComponentA Component that represents a clickable area.
- class pyunity.gui.NoResponseGuiComponent[source]¶
Bases:
GuiComponentA Component that blocks all clicks that are behind it.
- class pyunity.gui.GuiRenderComponent[source]¶
Bases:
NoResponseGuiComponentA Component that renders something in its RectTransform.
- class pyunity.gui.Image2D[source]¶
Bases:
GuiRenderComponentA 2D image component, which is uninteractive.
- class pyunity.gui.RenderTarget[source]¶
Bases:
GuiRenderComponent
- class pyunity.gui.Button[source]¶
Bases:
GuiComponentA 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-matchto 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:
objectFont 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:
GuiRenderComponentComponent to render text.
- rect¶
RectTransform of the GameObject. Can be None
- Type:
Notes
Modifying
font,text, orcolorwill callGenTexture().
- class pyunity.gui.CheckBox[source]¶
Bases:
GuiComponentA component that updates the Image2D of its GameObject when clicked.
- class pyunity.gui.Gui[source]¶
Bases:
objectHelper 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
RectTransformof button, theButtoncomponent and theTextcomponent.- Return type:
Notes
This will create 3 GameObjects in this hierarchy:
<specified button name> |- Button |- Text
The generated GameObject can be accessed from the
gameObjectproperty of the returned components. TheButtonGameObject will have two components,ButtonandRectTransform. TheButtonGameObject will have two components,Image2DandRectTransform.
- classmethod MakeCheckBox(name, scene)[source]¶
Create a CheckBox GameObject and add the appropriate components needed.
- Parameters:
- Returns:
A tuple of the
RectTransformas well as theCheckBoxcomponent.- Return type:
Notes
The generated GameObject can be accessed from the
gameObjectproperty of the returned components. The GameObject will have 3 properties added: aRectTransform, aCheckBoxand anImage2D.