TextComponent

Displays the text on the screen. We recommend you use it in conjunction with UITransformComponent.

# Properties

[{"index":"TextAlignmentType Alignment","0":"How to align text."}]

[{"index":"boolean AllowAutomaticTranslation (MakerOnly)","0":"Sets whether to automatically translate the value of the Text property."}]

[{"index":"boolean BestFit","0":"Adjust the font size to fit the area size."}]

[{"index":"boolean Bold","0":"Sets whether to use bold text."}]

[{"index":"float ConstraintX","0":"Sets the maximum width to limit. Operates when sizefit is true."}]

[{"index":"float ConstraintY","0":"Sets the maximum height to limit. Operates when sizefit is true."}]

[{"index":"boolean DropShadow","0":"Sets whether to output the shadow of text."}]

[{"index":"float DropShadowAngle","0":"Sets the angle of the shadow."}]

[{"index":"Color DropShadowColor","0":"The shadow color."}]

[{"index":"float DropShadowDistance","0":"Distance between the text and the shadow."}]

[{"index":"boolean EnableProfanityFilter (MakerOnly)","0":"Sets whether a banned words filter will be applied to the Text property."}]

[{"index":"FontType Font","0":"Font types."}]

[{"index":"Color FontColor","0":"The color to use to render the text."}]

[{"index":"int32 FontSize","0":"Font size."}]

[{"index":"boolean IgnoreMapLayerCheck (Sync)","0":"Does not perform automatic substitution when the Map Layer's name is specified in SortingLayer."}]

[{"index":"boolean IsLocalizationKey (MakerOnly)","0":"If true, finds and displays the text matching the current language settings in LocaleDataSet. Text's property value is used as a key. The actual value of the text property does not change."}]

[{"index":"boolean IsRichText","0":"Sets whether to use rich text."}]

[{"index":"float LineSpacing","0":"Adjusts line spacing."}]

[{"index":"int32 MaxSize","0":"Determines the maximum font size."}]

[{"index":"int32 MinSize","0":"Determines the minimum font size."}]

[{"index":"int32 OrderInLayer (Sync)","0":"Determines the priority within the same layer. A higher number indicates higher priority."}]

[{"index":"Color OutlineColor","0":"The color of the text's outline."}]

[{"index":"Vector2 OutlineDistance (Deprecated) (HideFromInspector)","0":"This is a deprecated property. Use OutlineWidth."}]

[{"index":"float OutlineWidth","0":"Sets the width of the text outline."}]

[{"index":"OverflowType Overflow","0":"Sets the handling method for when the text exceeds the horizontal area."}]

[{"index":"boolean OverrideSorting (Sync) (ReadOnly)","0":"Determines whether to set the SortingLayer and OrderInLayer values manually."}]

[{"index":"RectOffset Padding","0":"Sets the margin of the text area."}]

[{"index":"boolean SizeFit","0":"Resizes the text area to fit the text."}]

[{"index":"string SortingLayer (Sync)","0":"When two or more Entities overlap, the priority is determined according to the Sorting Layer."}]

[{"index":"string Text","0":"The content to be displayed."}]

[{"index":"boolean UseConstraintX","0":"Sets the width to be limited using the ConstraintX value."}]

[{"index":"boolean UseConstraintY","0":"Sets the height to be limited using the ConstraintY value."}]

[{"index":"boolean UseNBSP","0":"Specifies whether to enable line breaking at the character level. Line breaking is determined by characters, so the line breaks immediately when a character reaches the end of the line if the value is set to true. The line breaks by words to avoid incorrect line breaking if the value is set to false."}]

[{"index":"boolean UseOutLine","0":"Use the outline effect."}]

##### inherited from Component:

[{"index":"boolean Enable (Sync)","0":"Checks whether Component is activated or not."}]

[{"index":"boolean EnableInHierarchy (ReadOnly) (HideFromInspector)","0":"Displays whether this Component is Enable in the hierarchy. If Entity Enable is false regardless of Component Enable, returns false."}]

[{"index":"Entity Entity (ReadOnly)","0":"The Entity that owns this component."}]

# Methods

[{"index":"string GetLocalizedText() (ClientOnly)","0":"Returns the text matching the current language settings in LocaleDataSet when IsLocalizationKey's value is true. A Key will be used as Text's property value. Returns Text's property value when IsLocalizationKey's value is false."}]

[{"index":"float GetPreferredHeight(string preferredText, float width) (ClientOnly) (Yield)","0":"Gets the height of the text area that is outputted to a fixed-width space."}]

[{"index":"float GetPreferredWidth(string preferredText) (ClientOnly) (Yield)","0":"Gets the width of the input text area."}]

##### inherited from Component:

[{"index":"boolean IsClient()","0":"Returns whether the current execution environment is a client or not."}]

[{"index":"boolean IsServer()","0":"Returns whether the current execution environment is a server or not."}]

# Events

[{"index":"OrderInLayerChangedEvent","0":"This event occurs when changing the Component's OrderInLayer."}]

[{"index":"SortingLayerChangedEvent","0":"This event occurs when changing the component's SortingLayer."}]

# Examples

This is an example of printing text one character at a time.
    
    
    @Component
    script TypewriterDialogue extends Component
        property number TimerID = 0
        property number MessageLength = 0
        property number MessageIdx = 0
        property string RawMessage = ""
    
        @ExecSpace("ClientOnly")
        method void OnBeginPlay()
        self.Entity.Parent.Enable = true
    
        self.InputMessage = "안녕하세요. MSW에 오신 것을 환영합니다."
    
        local textComponent = self.Entity.TextComponent
        if not textComponent then
        	return
        end
    
        textComponent.Bold = true
        textComponent.Alignment = TextAlignmentType.UpperLeft
        textComponent.FontColor = Color.white
        textComponent.UseOutLine = true
        textComponent.OutlineColor = Color.black
        textComponent.FontSize = 50
    
        self:ShowDialogueOverTime(self.InputMessage, 0.1)
        -- min val is 0.1
        end
    
        method void ShowDialogueOverTime(string rawMessage, number interval)
        if interval <= 0 then
        	interval = 0.1
        end
    
        self.MessageIdx = 0
        self.RawMessage = rawMessage
        self.MessageLength = (utf8.len(rawMessage))
    
        local UpdateMessage = function()
        	if self.MessageIdx < self.MessageLength then
        		self.MessageIdx = self.MessageIdx + 1
        		local currentString = _UtilLogic:SubString(self.RawMessage, 1, self.MessageIdx)
    
        		if _UtilLogic:IsNilorEmptyString(currentString) == false then
        			self.Entity.TextComponent.Text =  currentString
        		end
        	else
        		self.Entity.TextComponent.Text =  ""
        		self:RestartDialogue()
        	end
        end
    
        self.TimerID = _TimerService:SetTimerRepeat(UpdateMessage, interval)
        end
    
        method void CancelDialogue()
        _TimerService:ClearTimer(self.TimerID)
        end
    
        method void RestartDialogue()
        self.MessageIdx = 0
        end
    end
    

# SeeAlso

  * UtilLogic
  * Entity
  * TimerService
  * [Automatic Translation](/docs?postId=1072)
  * [Basic UI Components](/docs?postId=744)
  * [Understanding Localization](/docs?postId=951)