pyunity.gui module¶
-
class
pyunity.gui.Canvas(transform, is_dummy=False)[source]¶ Bases:
pyunity.core.ComponentA 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:
objectClass to represent a 2D rect.
Parameters:
-
class
pyunity.gui.RectAnchors(min_or_both=None, max=None)[source]¶ Bases:
pyunity.gui.RectDataA 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.RectDataRect 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.SingleComponentA 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.ComponentA Component that represents a clickable area.
-
class
pyunity.gui.NoResponseGuiComponent(transform, is_dummy=False)[source]¶ Bases:
pyunity.gui.GuiComponentA Component that blocks all clicks that are behind it.
-
class
pyunity.gui.Image2D(transform)[source]¶ Bases:
pyunity.gui.NoResponseGuiComponentA 2D image component, which is uninteractive.
-
class
pyunity.gui.Button(transform)[source]¶ Bases:
pyunity.gui.GuiComponentA 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:
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.TextAlign[source]¶ Bases:
enum.IntEnumAn enumeration.
-
Left= 1¶
-
Center= 2¶
-
Right= 3¶
-
-
class
pyunity.gui.Text(transform)[source]¶ Bases:
pyunity.gui.NoResponseGuiComponentComponent to render text.
-
rect¶ RectTransform of the GameObject. Can be None
Type: RectTransform
Notes
Modifying
font,text, orcolorwill callGenTexture().-
centeredX= 1
-
centeredY= 2
-
-
class
pyunity.gui.CheckBox(transform, is_dummy=False)[source]¶ Bases:
pyunity.gui.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.
-
classmethod