TextService

사용되지 않는 항목 표시

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

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

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

이 클래스는 다음과 같은 두 가지 멤버 함수를 가집니다.

Class.TextService:GetTextSize() 함수는 지정된 서식을 사용하여 특정 텍스트 문자열에 필요한 공간을 계산하는 개발자 친화적인 함수입니다. 반환하는 픽셀 크기는 Vector2입니다.

사용자 안전에 대한 사용자 지정 텍스트(예: 채팅 메시지 또는 다른 입력)을 올바르게 필터링하려면 TextService:FilterStringAsync() 함수가 필요합니다. Roblox 기본 Chat를 사용하지 않는 개발자 또는 사용자가 다른 텍스트를 입력하도록 허용하지 않는 경우 이 함수

요약

메서드

속성

메서드

GetTextSize

지정된 서식 매개 변수 및 크기 제한을 사용하는 경우 텍스트와 함께 사용할 수 있는 Vector2 차원을 계산합니다.

참고, 글꼴 크기 매개 변수는 Enum.FontSize 열거 대신 글꼴 크기에 해당하는 정수 크기를 사용해야 합니다. 이는 글꼴 크기에 해당하는 Enu

이 함수는 TextLabel.TextBounds 속성의 TextLabelTextButton 개체와 함께 사용하면 편리한 대안이 될 수 있습니다. 크기 텍스트를 계산하려면 2>Class.TextLabel.TextBounds2> 속성을 사

GetTextSize를 사용하면 특정 TextLabel 또는 특정 TextButton 에 필요한 크기를 계산하여 개체를 생성하거나 텍스트 속성을 설정하기 전에 개체를 생성할 수 있습니다.

개발자는 텍스트가 잘리지 않도록 결과에 패딩 픽셀을 끄기것이 좋습니다.

이 메서드는 Enum.Font 에 나열된 글꼴에만 적용됩니다. 글꼴 목록에 액세스하려면 TextService:GetTextBoundsAsync() 대신 사용할 수 있습니다.

매개 변수

string: string

텍스트 크기를 계산할 문자열입니다.

fontSize: number

사용된 글꼴 크기를 나타내는 정수입니다.

font: Enum.Font

사용된 글꼴.

frameSize: Vector2

사용할 텍스트 개체의 TextLabel.AbsoluteSize입니다. 텍스트 묶음을 계산하는 데 필요합니다.


반환

지정된 서식의 문자열에 필요한 공간의 크기, 인 피치.

코드 샘플

This example showcases a possible usage of the GetTextSize function.

It computes the possible Vector2 dimensions (in pixels) of the string "Hello World" when the font size is 12, the font size SourceSans and the frame size is (1,1).

The expected return of this function is the Vector2 value 9, 13.

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

생성

이 메서드는 더 이상 지원되지 않습니다. 이 메서드는 더 이상 지원되지 않으며 사용하지 마십시오. 모든 호출은 빈 개체를 반환합니다. 채팅 메시지 번역은 TextChatService를 통해만 사용할 수 있습니다.

매개 변수

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

반환

FilterStringAsync

생성

FilterStringAsync 함수는 사용자가 받은 문자열을 사용하여 TextService 를 사용하고 올바르게 필터링된 텍스트를 반환하여 올바르게 필터링된 텍스트를 배포하는 데 사용됩니다.

사용

이 메서드는 사용자가 메시지를 제출할 때마다 호출해야 합니다. 이 함수의 결과를 캐시하지 마십시오. 이 메서드를 별도의 메시지에

그러나 이 결과 개체를 유지하여 서버에 나중에 참여하는 사용자에게 동일한 메시지를 표시하는 것이 좋습니다. 예를 들어: 이 개체를 사용하여 서버 채팅 로그를 안전하고 효율적으로 구현하여 사용자가 나중에 서버에 참여하더라도 최소한의 필터링을 사용하여 텍스트를

선택적인 Enum.TextFilterContext 매개 변수는 쿼리의 필터링 결과에 영향을 주지 않습니다. 이 값은 Roblox의 텍스트 필터링을 개선하기 위해 사용됩니다.

개인 텍스트는 모든 플레이어가 볼 수있는 것이 아닌 특정 플레이어만 볼 수있는 텍스트입니다. 예를 들어, 채팅이 단일 플레이어가 볼 수있는 것이라면, 채팅은 비공개간주됩니다. 팀이나 서버에 잠재적으로 표시 될 수있는 채팅은

참고:

  • 이 메서드는 항상 텍스트 필터링 서비스 호출을 반환합니다.
  • 이 메서드는 해결할 수 없는 서비스 오류가 발생했을 때 발생할 수 있습니다. 이 함수가 오류를 표시하면 요청을 다시 시도하지 마십시오; 이 메서드는 내부적으로 자체 재시도 논리를 구현합니다. 이 메서드가 실패하면 텍스트를 사용자에게 표시하지 않습니다.
  • 이 메서드는 현재 서버에서 fromUserId가 온라인이 아닌 경우에만 발생합니다. 우리는 미래에 오프라인 또는 다른 서버에 있는 사용자를 지원할 계획입니다.

매개 변수

stringToFilter: string

필터링할 텍스트입니다.

fromUserId: number

텍스트를 필터링하는 플레이어의 ID입니다.

필터링된 메시지가 사용될 컨텍스트입니다.

기본값: "PrivateChat"

반환

코드 샘플

This code sample includes a simple demonstration of how TextService:FilterStringAsync() should be implemented in a system where players are allowed to name their pets.

Note, this code sample includes the server-side implementation only (to be placed in a Script). Examples of how to implement the client-side of this system are included under the RemoteEvent and RemoteFunction examples.

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

생성

서체 가족의 이름과 얼굴이 담긴 테이블을 반환합니다.

반환된 테이블은 다음과 같이 구조화됩니다.


type FaceInfo = {
Name: string, -- 예: "Regular", "Book", "Italic", "Thin Italic"
Weight: Enum.FontWeight,
Style: Enum.FontStyle, -- 이탈리아어 또는 일반
}
type FamilyInfo = {
Name: string, -- 예: "Source Sans Pro", "Grenze Gotisch"
Faces: {FaceInfo} -- 최소 1개가 있지만 최대 18개까지 있을 수 있습니다.
}

서체 가족이 이전 호출으로 로드된 경우 GetFamilyInfoAsync 또는 텍스트 개체에 속성이 있는 텍스트 개체 ContentProvider:PreloadAsync() 또는 텍스트 개체에 속성이 있는 텍스트 개체 TextLabel.FontFace 개체를 반환하지 않고 메서드는 실행되지 않습니다.

오류

이 메서드는 네트워크 오류 때문에 실패할 수 있습니다. 오류 처리를 위해 항상 pcall로 감싼다.

이 시나리오에서 오류가 발생합니다.

  • 패스된 가족은 Empty 문자열입니다.
  • 가족을 다운로드하는 데 실패했습니다.
  • 자산 ID가 유효하지 않거나 존재하지 않는 자산을 가리키고 있습니다.

매개 변수

assetId: ContentId

검색할 글꼴 아이디입니다.


반환

서체 가족에 대한 정보.

코드 샘플

This example showcases a possible usage of the TextService:GetFamilyInfoAsync() method.

It prints out information about a font family to the output window.

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:GetTextSize() 와 유사하지만, Font 개체를 사용하는 대신 Enum.Font , 더 많은 글꼴에 액세스할 수 있습니다.

문자열, 크기 및 서체와 같은 속성 집합을 사용하여 텍스트의 크기를 측정하는 데 사용됩니다.

일부 글꼴은 측정하려면 로드해야 하므로 이는 생성 함수가 아닙니다. 글꼴이 이미 로드된 경우 생성되지 않습니다. ContentProvider:PreloadAsync() 를 사용하여 글꼴을 로드하는지 확인할 수 있습니다.

오류

이 메서드는 네트워크 오류 때문에 실패할 수 있습니다. 오류 처리를 위해 항상 pcall로 감싼다.

이 시나리오에서 오류가 발생합니다.

  • Class.GetTextBoundsProps.Font 는 빈 가족을 가지고 있습니다.
  • paramètres 인수가 없습니다.
  • 글꼴 가족 또는 글꼴 얼굴을 다운로드할 수 없습니다.

매개 변수


반환

텍스트의 크기를 Vector2 로 지정합니다.

코드 샘플

This example shows how you can use TextService:GetTextBoundsAsync().

It measures the size of some text in a specific font, then prints the result.

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

반환

이벤트