跳至正文
版本:bleeding-edge 🩸

🆒 TextRender

文本渲染类在 3D 世界中生成文本非常有用。

Client & Server🔁Not Distributable🧑‍💻API Source
👪Inheritance
This class shares methods and events from Base Entity, Base Actor.

🎒 示例​

local my_text_render = TextRender(
Vector(-100, 200, 300),
Rotator(),
"My Awesome Text",
40, -- 文本大小
Color.RED
)
名称标签getting-started/tutorials-and-examples/name-tags

🛠 构造函数​

Default Constructor​

No description provided

local my_textrender = TextRender(location, rotation, text, word_size?, color?, rendering_type?, horizontal_alignment?, vertical_alignment?, font_asset?, cast_shadow?)

Parameters

TypeNameDefaultDescription
Vectorlocation Required parameter 生成的世界坐标位置
Rotatorrotation Required parameter 生成的世界坐标旋转
stringtext Required parameter 要显示的文本
floatword_size26文本大小
ColorcolorColor.WHITE文本颜色
TextRenderRenderingTyperendering_typeTextRenderRenderingType.Lit使其不受光照影响、总是面向相机或总是透过墙壁可见
TextRenderHorizontalAlignmenthorizontal_alignmentTextRenderHorizontalAlignment.Center文本的水平对齐方式
TextRenderVerticalAlignmentvertical_alignmentTextRenderVerticalAlignment.Center文本的垂直对齐方式
stringfont_asset用于文本的字体资产。注意字体必须是离线缓存的距离场字体
booleancast_shadowfalse控制是否应当投射阴影

🗿 静态函数​

Inherited Entity Static Functions
TextRender inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
ReturnsNameDescription
table of Base EntityGetAll返回一个包含调用此方法的类中所有实体的表
Base EntityGetByIndex返回该类中指定索引处的特定实体
integerGetCount返回该类当前存在的实体数量
table of tableGetInheritedClasses获取使用 继承系统 创建的、直接继承自该类的所有子类列表
iteratorGetPairs返回一个包含该类所有实体的迭代器,供 pairs() 使用
table or nilGetParentClass如果该类是使用 继承系统 创建的,则获取其父类
tableInherit通过 继承系统 继承此类
booleanIsChildOf如果该类是使用 继承系统 创建的,检查此类是否为另一个类的子类
functionSubscribe为此类的所有实体订阅一个 事件
functionSubscribeRemote订阅从服务器调用的自定义事件
Unsubscribe退订此包内该类中此 事件 的所有回调,或者仅取消传入的特定回调

This class doesn't have own static functions.

🦠 函数​

Inherited Entity Functions
TextRender inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
ReturnsNameDescription
BroadcastRemoteEvent直接在此实体上向所有玩家调用自定义远程事件
BroadcastRemoteInRadiusEvent直接针对此实体调用自定义远程事件,并将该事件传递给半径范围内的所有玩家
CallRemoteEvent直接在此实体上向特定玩家调用自定义远程事件
CallRemoteEvent直接在此实体上调用自定义远程事件
CallRemotePlayersEvent直接在此实体上调用自定义远程事件,并将事件传递给玩家列表
Destroy销毁此实体
FinishSpawn如果此实体是以延迟 spawn_mode 生成的,则完成生成过程并将该实体发送至客户端
table of stringGetAllValuesKeys获取所有存储值的键名列表
tableGetClass获取此实体的类
integerGetID获取此实体的通用网络 ID(客户端和服务器一致)
anyGetValue获取存储在此实体上指定键处的 值
booleanHasAuthority获取本地上下文是否对此实体拥有主控(如果由客户端生成则为 true,由服务器生成则为 false)
booleanIsA递归检查此实体是否继承自某个类
booleanIsBeingDestroyed如果此实体正在被销毁,则返回 true
booleanIsSpawned获取此实体是否已完成生成
booleanIsValid如果此实体有效(即未被销毁且指向有效的实体),则返回 true
SetSpawnMode从继承类的构造函数中覆盖此实体完成生成的时间点
SetValue在此实体中设置一个 值
functionSubscribe在这个特定实体上订阅一个事件
functionSubscribeRemote在这个特定实体上订阅一个从服务器调用的自定义远程事件
Unsubscribe退订此包内该实体中此 事件 的所有回调,或者仅取消传入的特定回调
Inherited Actor Functions
TextRender inherits from Base Actor Class, sharing it's methods and functions:
Base Actorscripting-reference/classes/base-classes/actor
ReturnsNameDescription
AddActorTag向该 Actor 添加一个虚幻 Actor 标签
AddAngularImpulse向该 Actor 添加角冲量。适用于单次瞬间爆发
AddImpulse向该 Actor 添加冲量。适用于单次瞬间爆发
booleanAttachTo将该 Actor 附加到任何其他 Actor 上,可选择附加在特定骨骼处
Detach将该 Actor 从其附加的 Actor 上分离
table of stringGetActorTags获取该 Actor 上的所有虚幻 Actor 标签
VectorGetAngularForce获取该 Actor 的角外力(由 SetAngularForce() 设置)
floatGetAngularVelocity返回此 Actor 的角速度
table of Base ActorGetAttachedEntities获取附加到该 Actor 的所有 Actor
Base Actor or nilGetAttachedTo获取该 Actor 所附加到的父级 Actor
stringGetAttachedToSocket获取此 Actor 所附加到的骨骼或插槽名称
tableGetBounds获取此 Actor 的包围盒,便于计算其在世界中的尺寸
CollisionTypeGetCollision获取该 Actor 的碰撞类型
integerGetDimension获取该 Actor 的维度
floatGetDistanceFromCamera获取该 Actor 距离相机的距离
VectorGetForce获取该 Actor 的持续外力(由 SetForce() 设置)
floatGetLifeSpan获取此 Actor 被销毁前剩余的时间(秒)
VectorGetLocation获取该 Actor 在游戏世界中的位置
floatGetMass返回此 Actor 的质量
Player or nilGetNetworkAuthority获取该 Actor 的网络主控玩家
VectorGetRelativeLocation如果该 Actor 已附加,获取其相对位置
RotatorGetRelativeRotation如果该 Actor 已附加,获取其相对旋转
RotatorGetRotation获取该 Actor 在游戏世界中的角度值
VectorGetScale获取该 Actor 的缩放比例
floatGetScreenPercentage获取该 Actor 在屏幕中所占尺寸的百分比
tableGetSocketTransform在给定骨骼或插槽名称的情况下,获取世界空间中的插槽变换
VectorGetVelocity获取该 Actor 当前的速度
booleanHasNetworkAuthority如果本地玩家当前是该 Actor 的网络主控(Network Authority),则返回 true
booleanIsGravityEnabled如果该 Actor 启用了重力,则返回 true
booleanIsImpulseOnDamageReturns true if taking damage pushes this Actor's physics body
booleanIsInWater如果该 Actor 处于水中,则返回 true
booleanIsNetworkDistributed如果该 Actor 当前处于网络分配状态,则返回 true
booleanIsVisible如果该 Actor 可见,则返回 true
RemoveActorTag从该 Actor 中移除一个虚幻 Actor 标签
RotateRelativeToSmoothly rotates this attached actor to an angle relative to its parent over a certain time
RotateTo在一定时间内平滑旋转该 Actor 到指定角度
SetAngularForce向该 Actor 添加一个永久的角外力,设为 Vector(0, 0, 0) 可以取消
SetCastShadow设置该 Actor 是否投射阴影
SetCollision设置该 Actor 的碰撞类型
SetDimension设置此 Actor 的维度。Actor 仅能看见并与处于同一维度中的实体进行交互
SetDistanceOptimizationMultiplier设置此 Actor 的距离优化系数
SetForce向该 Actor 添加一个永久的外力,设为 Vector(0, 0, 0) 可以取消
SetGravityEnabled设置该 Actor 是否启用重力
SetHighlightEnabled设置该 Actor 是否启用高亮显示,以及使用哪个高亮索引值
SetImpulseOnDamageSets whether taking damage (shots, melee, explosions) pushes this Actor's physics body
SetLifeSpan设置该 Actor 被销毁前的生存时间(秒)。经过这段时间后,Actor 将被自动销毁。
SetLocation设置该 Actor 在游戏世界中的位置
SetNetworkAuthority设置某个玩家拥有此 Actor 的网络主控
SetNetworkAuthorityAutoDistributed设置该 Actor 是否在玩家之间自动分配网络主控
SetOutlineEnabled设置该 Actor 是否启用描边,以及使用哪个描边索引值
SetRelativeLocation在局部空间中设置该 Actor 的相对位置(仅在此 Actor 已附加时生效)
SetRelativeRotation在局部空间中设置该 Actor 的相对旋转(仅在此 Actor 已附加时生效)
SetRenderCullDistance设置该 Actor 的渲染剔除距离
SetRotation设置该 Actor 在游戏世界中的旋转
SetScale设置该 Actor 的缩放比例
SetVisibility设置该 Actor 是否可见
TranslateRelativeToSmoothly moves this attached actor to a location relative to its parent over a certain time
TranslateTo在一定时间内平滑地将该 Actor 移动到某个位置
booleanWasRecentlyRendered获取该 Actor 最近是否在屏幕上被渲染过
ReturnsNameDescription
ColorGetColor获取当前文本颜色
stringGetText获取当前文本
floatGetWordSize获取当前字号大小
SetAlignment设置文本对齐方式
SetColor设置文本颜色
SetFont设置字体。字体必须预先烘焙为离线缓存的距离场字体。
SetSpacingAdjust设置水平和垂直间距调整值
SetText设置文本
SetWordSize设置字号大小

Optimal

GetColor​

获取当前文本颜色
local color = my_textrender:GetColor()

Returns

TypeDescription
Color当前文本颜色

See also SetColor.


Optimal

GetText​

获取当前文本
local text = my_textrender:GetText()

Returns

TypeDescription
string当前文本

See also SetText.


Optimal

GetWordSize​

获取当前字号大小
local word_size = my_textrender:GetWordSize()

Returns

TypeDescription
float当前字号大小

See also SetWordSize.


Moderate

SetAlignment​

设置文本对齐方式
my_textrender:SetAlignment(horizontal_alignment, vertical_alignment)

Parameters

TypeParameterDefaultDescription
TextRenderHorizontalAlignmenthorizontal_alignment Required parameter 文本的水平对齐方式
TextRenderVerticalAlignmentvertical_alignment Required parameter 文本的垂直对齐方式

Moderate

SetColor​

设置文本颜色
my_textrender:SetColor(color)

Parameters

TypeParameterDefaultDescription
Colorcolor Required parameter 新的文本颜色

See also GetColor.


Moderate

SetFont​

设置字体。字体必须预先烘焙为离线缓存的距离场字体。

可用字体示例:
- nanos-world::Font_LondrinaSolid_DistanceField
- nanos-world::Font_BoldPixels_DistanceField
- nanos-world::Font_Roboto_DistanceField
my_textrender:SetFont(font_asset)

Parameters

TypeParameterDefaultDescription
stringfont_asset Required parameter 新的字体。字体必须预先烘焙为离线缓存的距离场字体

Moderate

SetSpacingAdjust​

设置水平和垂直间距调整值
my_textrender:SetSpacingAdjust(horizontal_spacing, vertical_spacing)

Parameters

TypeParameterDefaultDescription
floathorizontal_spacing Required parameter 字符之间的额外水平间距
floatvertical_spacing Required parameter 行之间的额外垂直间距

Moderate

SetText​

设置文本
my_textrender:SetText(text)

Parameters

TypeParameterDefaultDescription
stringtext Required parameter 新的文本

See also GetText.


Moderate

SetWordSize​

设置字号大小
my_textrender:SetWordSize(word_size)

Parameters

TypeParameterDefaultDescription
floatword_size Required parameter 新的词尺寸

See also GetWordSize.

🚀 事件​

Inherited Entity Events
TextRender inherits from Base Entity Class, sharing it's events:
Base Entityscripting-reference/classes/base-classes/entity
NameDescription
ClassRegister当使用 继承系统 注册一个新类时触发
Destroy当实体被销毁时触发
Spawn当实体被生成/创建时触发
ValueChange当实体通过 :SetValue() 改变了值时触发
Inherited Actor Events
TextRender inherits from Base Actor Class, sharing it's events:
Base Actorscripting-reference/classes/base-classes/actor
NameDescription
DimensionChange当 Actor 改变其维度时触发
EnterWater当 Actor 进入水体时触发
LeaveWater当 Actor 离开水体时触发
NetworkAuthorityChange当 Actor 更改其网络主控玩家时触发
NetworkAuthorityChange当本地玩家获得或失去对此 Actor 的网络主控时触发

This class doesn't have own events.