pyunity.gui module¶
-
class
pyunity.gui.
Canvas
(transform, is_dummy=False)[source]¶ Bases:
pyunity.core.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.
RectData
(min_or_both=None, max=None)[source]¶ Bases:
object
Class to represent a 2D rect.
Parameters:
-
class
pyunity.gui.
RectAnchors
(min_or_both=None, max=None)[source]¶ Bases:
pyunity.gui.RectData
A type of RectData which represents the anchor points of a RectTransform.
-
class
pyunity.gui.
RectOffset
(min_or_both=None, max=None)[source]¶ Bases:
pyunity.gui.RectData
Rect to represent the offset from the anchor points of a RectTransform.
-
static
Rectangle
(size, center=Vector2(0, 0))[source]¶ Create a rectangular RectOffset.
Parameters: Returns: The generated RectOffset
Return type:
-
static
-
class
pyunity.gui.
RectTransform
(transform)[source]¶ Bases:
pyunity.core.SingleComponent
A Component that represents the size, position and orientation of a 2D object.
-
anchors
¶ Anchor points of the RectTransform. Measured between Vector2(0, 0) and Vector2(1, 1)
Type: RectAnchors
-
offset
¶ Offset vectors representing the offset of opposite corners from the anchors. Measured in pixels
Type: RectOffset
-
pivot
¶ Point in which the object rotates around. Measured between Vector2(0, 0) and Vector2(1, 1)
Type: Vector2
-
parent
¶
-
-
class
pyunity.gui.
GuiComponent
(transform, is_dummy=False)[source]¶ Bases:
pyunity.core.Component
A Component that represents a clickable area.
-
class
pyunity.gui.
NoResponseGuiComponent
(transform, is_dummy=False)[source]¶ Bases:
pyunity.gui.GuiComponent
A Component that blocks all clicks that are behind it.
-
class
pyunity.gui.
Image2D
(transform)[source]¶ Bases:
pyunity.gui.NoResponseGuiComponent
A 2D image component, which is uninteractive.
-
class
pyunity.gui.
Button
(transform)[source]¶ Bases:
pyunity.gui.GuiComponent
A Component that calls a function when clicked.
-
callback
¶ Callback function
Type: FunctionType
-
state
= 1
-
mouseButton
= 1
-
-
class
pyunity.gui.
FontLoader
[source]¶ Bases:
pyunity.gui.UnixFontLoader
-
class
pyunity.gui.
Font
(name, size, imagefont)[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.
TextAlign
[source]¶ Bases:
enum.IntEnum
An enumeration.
-
Left
= 1¶
-
Center
= 2¶
-
Right
= 3¶
-
-
class
pyunity.gui.
Text
(transform)[source]¶ Bases:
pyunity.gui.NoResponseGuiComponent
Component to render text.
-
rect
¶ RectTransform of the GameObject. Can be None
Type: RectTransform
Notes
Modifying
font
,text
, orcolor
will callGenTexture()
.-
centeredX
= 1
-
centeredY
= 2
-
-
class
pyunity.gui.
CheckBox
(transform, is_dummy=False)[source]¶ Bases:
pyunity.gui.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
.
-
classmethod