配置默认文本聊天输入栏的属性。它是父辈到 TextChatService 。
概要
属性
默认聊天输入栏的实际屏幕位置,以像素计算。
默认聊天输入栏的实际屏幕尺寸以像素计算。
是否启用聊天输入栏的自动完成。
默认聊天输入栏的背景颜色。
默认聊天输入栏的背景透明。
是否显示默认聊天输入栏。
用于默认聊天输入栏渲染文本的字体。
默认聊天输入栏是否焦点或不。
额外的关键用户可以按下以触发关注默认聊天输入栏的操作。
默认聊天输入栏中的占位符文本的颜色。
对目标的参考 TextChannel .
指向指定的 TextBox 实例,该实例代表用户发送消息。
默认聊天输入栏的文本颜色。
默认聊天输入栏的文本大小。
默认聊天输入栏中文本的字体颜色。
默认聊天输入栏中文本的字体透明度。
属性
BackgroundTransparency
默认聊天输入栏的背景透明度为 0 和 1 之间的数字。这个值与用户的 GuiService.PreferredTransparency 乘以以创建聊天输入栏使用的有效背景透明度,可能比这里设置的值更不透明。默认值为 0.2 。
IsFocused
指示默认聊天输入栏是否焦点或不。用于发射属性更改事件,以便您可以实现回调函数,回应输入栏的焦点状态发生的变化。
代码示例
The code below includes a simple way to create a typing indicator bubble above a user's avatar when the user is typing. Paste into a LocalScript.
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local ChatInputBarConfiguration = TextChatService:FindFirstChildOfClass("ChatInputBarConfiguration")
local BubbleChatConfiguration = TextChatService:FindFirstChildOfClass("BubbleChatConfiguration")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
-- Set up TextLabel
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.fromScale(1, 1)
textLabel.Text = ". . ."
textLabel.BackgroundColor3 = BubbleChatConfiguration.BackgroundColor3
textLabel.BorderColor3 = BubbleChatConfiguration.BackgroundColor3
textLabel.BackgroundTransparency = BubbleChatConfiguration.BackgroundTransparency
textLabel.TextColor3 = BubbleChatConfiguration.TextColor3
textLabel.FontFace = BubbleChatConfiguration.FontFace
textLabel.TextSize = BubbleChatConfiguration.TextSize
-- Parent a UICorner to the TextLabel to have rounded corners
local uiCorner = Instance.new("UICorner")
uiCorner.CornerRadius = UDim.new(0, 12)
uiCorner.Parent = textLabel
-- Set up Billboard
local typingIndicatorBillboard = Instance.new("BillboardGui")
typingIndicatorBillboard.Enabled = false
typingIndicatorBillboard.Size = UDim2.fromScale(1, 1)
typingIndicatorBillboard.StudsOffsetWorldSpace = Vector3.new(-0, 4, 0)
typingIndicatorBillboard.Adornee = Character
textLabel.Parent = typingIndicatorBillboard
typingIndicatorBillboard.Parent = LocalPlayer:FindFirstChildOfClass("PlayerGui")
ChatInputBarConfiguration:GetPropertyChangedSignal("IsFocused"):Connect(function()
-- Enable the typing indicator when the input bar is focused and disable otherwise
typingIndicatorBillboard.Enabled = ChatInputBarConfiguration.IsFocused
end)
TextBox
指向指定的 TextBox 实例,该实例代表用户发送消息。您可以使用它来自由操纵外观、位置和布局,进一步整合自定义聊天输入栏 UI 到您的体验中。当选择将此属性设置为自定义 TextBox 时,您不需要为以下行为写任何代码:
- 当用户输入消息并按Enum.KeyCode.Return时,消息将发送到ChatInputBarConfiguration.TargetTextChannel。
- 当消息发送时,TextBox.Text将自动清除。
为了安全,在晋升到 ChatInputBarConfiguration.TextBox 时,对 TextBox 会被施加一些限制。 Luau 代码将无法:
- 更改 TextBox.Text 属性。