文档

Unity Engine

Unity Engine

SetText

Sets the text content without allocating a managed string.
阅读时间1 分钟最后更新于 20 天前

Definition

SetText(ReadOnlySpan<char>)

Sets the text content without allocating a managed string.
public void SetText(ReadOnlySpan<char> text)

Parameters

The character span to set as the element's text content.

Remarks

Unlike assigning to TextElement.text, this method writes directly into an internal native buffer and defers string materialization until TextElement.text is read. A ChangeEvent<T> of type
string
is raised only when listeners for value-change events exist in the element's hierarchy; when no such listeners are present, the method is fully allocation-free.

SetText(char[], int, int)

Sets the text content from a character array slice without allocating a managed string.
public void SetText(char[] sourceText, int start, int length)

Parameters

sourceText

The source character array.

start

The starting index in the array.

length

The number of characters to copy.

SetText(StringBuilder)

Sets the text content from a StringBuilder without allocating a managed string.
public void SetText(StringBuilder sb)

Parameters

The StringBuilder whose contents to copy.

SetText(float, string)

Formats a float value directly into the text buffer without allocating a managed string.
public void SetText(float value, string format = null)

Parameters

value

The float value to display.

format

An optional standard or custom numeric format string.

SetText(int)

Formats an integer value directly into the text buffer without allocating a managed string.
public void SetText(int value)

Parameters

value

The integer value to display.