wiki.sine.space | sinespace

Difference between revisions of "Scripting/SUIText"

From wiki.sine.space
Jump to: navigation, search
m
m
Line 205: Line 205:
 
thisObjectText = thisObject.UIText
 
thisObjectText = thisObject.UIText
 
   
 
   
Space.Log(thisObjectText.PreferredWidth)
+
Space.Log(thisObjectText.PreferredWidth)</pre>
 
}}
 
}}
  

Revision as of 16:02, 27 December 2020

The SUIText class provides tools to work with the SUIText component, which is a component responsible for displaying text

Properties

AlignByGeometry

bool AlignByGeometry {get;set;}

Use the range of glyph geometry to perform horizontal alignment.

thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the SUIText component in our object 

Space.Log(thisObjectText.AlignByGeometry)
--This will return "true" or "false"  to your debugger console
--telling you if the Align By Geometry feature is on or not (false by default)

thisObjectText.AlignByGeometry = true
--This enables the Align By Geometry feature

thisObjectText.AlignByGeometry = false
--This disables the Align By Geometry feature


Color

SColor Color {get;set;}

Base color of the Graphic.

--This script dynamically changes the text's color of a GameObject with UIText component.
--For example in a text sign over your shop that you want to make more visually stand out
--or perhaps text decoration during a celebration or a text element in your User Interface or HUD.

thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the SUIText component in our object 
colors = {Color.Red, Color.Black, Color.White, Color.Blue, Color.Green, Color.Yellow}
 --here we are holding 6 predefined colors in a Lua Table which we will go through


function ColorChanger()

    while true do
    --infinite loop
    
        for i=1,#colors do
        --For Loop to cycle through all the table items
        thisObjectText.color = colors[i] 
        --this will set the color based on which item in the table we are now at
        coroutine.yield(0.1)
        --this will pause for a tenth of a second before we change to the next color
        end

    end
end

thisObjectText.color = Color.Red 
--this is how to set text color using one of the predefined colors in the SColor class.
thisObjectText.color = Color.New(0,0,0,1)
--this sets our text color to Black (RGB 000) but also Alpha to 1 (meaning fully opaque, not transparent)

colorOfThisObject = thisObjectText.color
thisObjectText.color = colorOfThisObject
--The color property also allows you to "get" it, not only "set" it, meaning you can get
--your text's current color and save it. In this case, the color of your text wouldn't change.

--The last 4 lines of code above are not important to this color changing script, it's just extra information for you.

Space.Host.StartCoroutine(ColorChanger) 
--this coroutine will now call our ColorChanger() function which is infinitely changing our text colors between a select range. 


Enabled

bool Enabled {get;set;}
Whether the UIText component is Enabled or not will decide if it is visually updating or not.
thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 

Space.Log(thisObjectText.Enabled)
--This will return "true" or "false" to your debugger console

thisObjectText.Enabled = false
--This is how we disable the UIText component

thisObjectText.Enabled = true
--This is how we enable the UIText component


FlexibleHeight

float FlexibleHeight {get;}
The extra relative height this UIText  should be allocated if there is additional available space. (Used by the Layout system.) 
 thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 

Space.Log(thisObjectText.FlexibleHeight)
--Prints the FlexibleHeight value of this UIText component to the console


FlexibleWidth

float FlexibleWidth {get;}

The extra relative width this UIText should be allocated if there is additional available space. (Used by the Layout system)

thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 

Space.Log(thisObjectText.FlexibleWidth)
--Prints the FlexibleWidth value of this UIText component to the console 


FontSize

int FontSize {get;set;}

The size that the Font should render at.

thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 

Space.Log(thisObjectText.FontSize)
--Prints the Font Size value of this UIText component to the console

thisObjectText.FontSize = 54
--Sets the Font Size of this UIText component to 54


LayoutPriority

int LayoutPriority {get;}

The layout priority of this UIText component.(Used by the Layout system.)

thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 

Space.Log(thisObjectText.LayoutPriority)
--Prints the LayoutPriority value of this UIText component to the console


LineSpacing

float LineSpacing {get;set;}

How much space will be in-between lines of text. This is a multiplier. The line spacing value set will be multiplied by the font's internal line spacing. A value of 1 will produce normal line spacing.

thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 
 
Space.Log(thisObjectText.LineSpacing)
  --Prints the LineSpacing value of this UIText component to the console
  
thisObjectText.LineSpacing = 2
  --This sets the LineSpacing value of this UIText component to 2.


MinHeight

float MinHeight {get;}

The minimum height this UIText may be allocated.(Used by the Layout system).

thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 
 
 Space.Log(thisObjectText.MinHeight)
--Prints the MinHeight value of this UIText component to the console


MinWidth

float MinWidth {get;}

The minimum width this UIText may be allocated. (Used by the Layout system).

thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 
 
Space.Log(thisObjectText.MinWidth)
--Prints the MinWidth value of this UIText component to the console


PixelsPerUnit

float PixelsPerUnit {get;}

Provides information about how fonts are scale to the screen.

For dynamic fonts, the value is equivalent to the scale factor of the canvas. For non-dynamic fonts, the value is calculated from the requested text size and the size from the font.

thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 

Space.Log(thisObjectText.PixelsPerUnit)
--Prints the PixelsPerUnit value of this UIText component to the console


PreferredHeight

float PreferredHeight {get;}

The preferred height this UIText should be allocated if there is sufficient space. (Used by the Layout system)

thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 
 
 Space.Log(thisObjectText.PreferredHeight)
  --Prints the PreferredHeight value of this UIText component to the console


PreferredWidth

float PreferredWidth {get;}

The preferred width this UIText should be allocated if there is sufficient space. (Used by the Layout system)

thisObject = Space.Host.ExecutingObject
thisObjectText = thisObject.UIText
 
Space.Log(thisObjectText.PreferredWidth)


ResizeTextForBestFit

bool ResizeTextForBestFit {get;set;}

Should the text be allowed to auto resized.

 Space.Host.ExecutingObject.UIText.ResizeTextForBestFit = false 


ResizeTextMaxSize

int ResizeTextMaxSize {get;set;}

The maximum size the text is allowed to be. 1 is infinitely large.

 Space.Host.ExecutingObject.UIText.ResizeTextMaxSize = 150


ResizeTextMinSize

int ResizeTextMinSize {get;set;}

The minimum size the text is allowed to be.


Space.Host.ExecutingObject.UIText.ResizeTextMinSize = 20


SupportRichText

bool SupportRichText {get;set;}
Whether this Text will support rich text. 
 Space.Host.ExecutingObject.UIText.SupportRichText = true 


Text

string Text {get;set;}

The string value this Text displays.

 Space.Host.ExecutingObject.UIText.Text = "Hello World!"