TextService

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음
서비스
복제되지 않음

텍스트 서비스는 게임에서 텍스트 표시를 처리하는 내부 서비스입니다.

이 클래스에는 두 개의 멤버 함수가 있습니다:

TextService:GetTextSize() 함수는 특정 서식으로 지정된 텍스트 문자열에 필요한 공간을 계산하는 능력을 개발자에게 제공하며, 픽셀 크기 Vector2를 반환합니다.

TextService:FilterStringAsync() 함수는 사용자 지정 텍스트(채팅 메시지 또는 다른 입력 등)를 사용자 안전의 이익을 위해 적절하게 필터링하는 데 필요합니다.Roblox 기본값 을 사용하지 않거나 사용자가 다른 방법으로 텍스트를 입력할 수 있도록 허용하지 않는 개발자는 이 함수를 사용해야 합니다.

요약

메서드

속성

메서드

GetTextSize

매개 변수

string: string
기본값: ""
fontSize: number
기본값: ""
font: Enum.Font
기본값: ""
frameSize: Vector2
기본값: ""

반환

코드 샘플

TextService: Getting the Text Size

local TextService = game:GetService("TextService")
local function getTextBounds()
local message = "Hello World"
local size = Vector2.new(1, 1)
local bounds = TextService:GetTextSize(message, 12, "SourceSans", size)
return bounds + Vector2.new(1, 1)
end
print(getTextBounds())

FilterAndTranslateStringAsync

생성

매개 변수

stringToFilter: string
기본값: ""
fromUserId: number
기본값: ""
targetLocales: Array
기본값: ""
기본값: "PrivateChat"

반환

FilterStringAsync

생성

매개 변수

stringToFilter: string
기본값: ""
fromUserId: number
기본값: ""
기본값: "PrivateChat"

반환

코드 샘플

Pet Name Filter Example

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")
local Players = game:GetService("Players")
local Remotes = Instance.new("Folder")
Remotes.Name = "PetNamingRemotes"
Remotes.Parent = ReplicatedStorage
local UserNamedPet = Instance.new("RemoteEvent")
UserNamedPet.Name = "UserNamedPet"
UserNamedPet.Parent = Remotes
local SendPetName = Instance.new("RemoteEvent")
SendPetName.Name = "SendPetName"
SendPetName.Parent = Remotes
local RequestAllPetNames = Instance.new("RemoteFunction")
RequestAllPetNames.Name = "RequestAllPetNames"
RequestAllPetNames.Parent = Remotes
local filterResults = {}
local function broadcastPetName(userId)
local filterResult = filterResults[userId]
if filterResult then
for _, player in pairs(Players:GetPlayers()) do
if player then
-- spawn a new thread so as to not yield the update
task.spawn(function()
-- grab the filtered string for this user
local toUserId = player.UserId
local filteredString = filterResult:GetNonChatStringForUserAsync(toUserId)
filteredString = filteredString or ""
SendPetName:FireClient(player, userId, filteredString)
end)
end
end
end
end
UserNamedPet.OnServerEvent:Connect(function(player, petName)
local fromUserId = player.UserId
-- pcall to catch errors
local success, result = pcall(function()
return TextService:FilterStringAsync(petName, fromUserId)
end)
if success then
filterResults[fromUserId] = result
broadcastPetName(fromUserId)
else
print("Could not filter pet name")
end
end)
RequestAllPetNames.OnServerInvoke = function(player)
local toUserId = player.UserId
local petNames = {}
-- go through filter results and filter the pet name to be sent
for fromUserId, filterResult in pairs(filterResults) do
local filteredString = filterResult:GetNonChatStringForUserAsync(toUserId)
filteredString = filteredString or ""
-- need to convert userId to string so it can't be sent via a remote function
petNames[tostring(fromUserId)] = filteredString
end
return petNames
end
Players.PlayerRemoving:Connect(function(oldPlayer)
local userId = oldPlayer.UserId
filterResults[userId] = nil
end)

GetFamilyInfoAsync

생성

매개 변수

assetId: ContentId
기본값: ""

반환

코드 샘플

TextService: Getting font family information

local TextService = game:GetService("TextService")
local familyToCheck = "rbxasset://fonts/families/Arial.json"
-- This is a yield function which may take up to a few seconds to download the font.
local info = TextService:GetFamilyInfoAsync(familyToCheck)
print("Name of the font:", info.Name)
print("Faces:")
for _, face in info.Faces do
print("--------")
print("Name:", face.Name)
print("Weight:", face.Weight.Name)
print("Style:", face.Style.Name)
end

GetTextBoundsAsync

생성

매개 변수

기본값: ""

반환

코드 샘플

TextService: Measuring text size

local TextService = game:GetService("TextService")
local params = Instance.new("GetTextBoundsParams")
params.Text = "hello world!"
params.Font = Font.new("rbxasset://fonts/families/GrenzeGotisch.json", Enum.FontWeight.Thin)
params.Size = 20
params.Width = 200
local size = TextService:GetTextBoundsAsync(params)
print("The size of the text is:", size)

GetTextSizeOffsetAsync

생성

매개 변수

fontSize: number
기본값: ""
font: Enum.Font
기본값: ""

반환

이벤트