配置默認文字聊天輸入欄的屬性。它與 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 實例,該實例代表使用者發送訊息。您可以使用它來自由操控外觀、位置和布局,將自訂聊天輸入欄介面整合到您的體驗中,進一步提升體驗品質。當選擇將此屬性設為自訂 TextBox 時,您不需要寫任何代碼來實現以下行為:
- 當使用者輸入訊息並按下 Enum.KeyCode.Return 時,訊息將傳送到 ChatInputBarConfiguration.TargetTextChannel 。
- 當傳送訊息時,TextBox.Text將自動清除。
為了安全,當提升到 ChatInputBarConfiguration.TextBox 時,對 TextBox 會有一些限制。 Luau 代碼將無法:
- 變更 TextBox.Text 屬性。