TextService

사용되지 않는 항목 표시

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

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

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

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

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

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

요약

메서드

속성

메서드

GetTextSize

지정된 서식 매개변수와 크기 제약 조건을 사용할 때 텍스트와 함께 가져올 Vector2 차원(픽셀)을 계산합니다.

참고, 글꼴 크기 매개 변수는 Enum.FontSize Enum을 허용하지 않습니다.대신 Enum.FontSize Enum에 해당하는 정수 크기가 사용되어야 합니다.이는 Enum.FontSize Enum의 값과 같지 않습니다.예를 들어, Size11 글꼴의 경우 정수 11 이 사용되어야 합니다.

이 함수는 TextLabel.TextBounds 속성의 TextLabelTextButton 개체에 대한 유용한 대안입니다.차원 텍스트를 계산하기 위해 TextLabel.TextBounds 속성을 사용하는 것은 만들어야 하는 TextLabel 개체가 많기 때문에 실용적이지 않은 경우가 많습니다.

GetTextSize로 특정 TextLabel 또는 TextButton 의 특정 텍스트 문자열에 필요한 차원은 개체가 생성되거나 텍스트 속성이 설정되기 전에 계산될 수 있습니다.

개발자는 결과에 여백 픽셀을 추가하여 텍스트가 끄기않도록 하는 것이 좋습니다.

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

매개 변수

string: string

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

기본값: ""
fontSize: number

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

기본값: ""
font: Enum.Font

사용된 글꼴.

기본값: ""
frameSize: Vector2

사용할 텍스트 개체의 TextLabel.AbsoluteSize입니다. 텍스트가 어떻게 감싸일지 계산하는 데 필요합니다.

기본값: ""

반환

지정된 서식으로 표시되는 문자열에 필요한 공간 크기, 픽셀로.

코드 샘플

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를 사용하여 사용자로부터 받은 문자열을 필터링하고, 올바르게 필터링된 텍스트를 배포하기 위해 사용할 수 있는 TextFilterResult를 반환합니다.

사용

이 메서드는 사용자가 메시지를 제출할 때마다 한 번 호출되어야 합니다.이 함수의 결과를 캐시하지 않고 별도의 메시지에 다시 사용하지 마십시오.사용자가 동일한 텍스트를 여러 번 제출하면 메시지가 전송될 때마다 이 메서드가 다시 호출되어야 합니다.결과가 캐시되고 재사용되면 스팸 감지 및 많은 종류의 컨텍스트 인식 필터링이 중단되어 사용자 안전이 위험에 처할 수 있습니다.잘못 사용된 캐시된 결과를 사용하는 게임은 조정을 받을 수 있습니다.

그러나 나중에 서버에 참여하는 사용자에게 동일한 메시지를 표시하기 위해 이러한 결과 개체를 유지하는 것이 권장됩니다.예를 들어: 이를 사용하여 나중에 가입하는 사용자에게 항상 가장 제한적인 필터링을 사용하여 서버 채팅 로그를 안전하고 효율적으로 구현하거나, 애완동물의 이름처럼 사용자가 게임에 참여한 후 처음 표시된 텍스트를 효율적으로 표시할 수 있습니다.

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

비공개 텍스트는 모든 플레이어가 아니라 특정 플레이어만 볼 수 있는 것입니다.예를 들어, 채팅이 단일 플레이어나 선택한 플레이어 그룹에 의해 보이면 채팅은 비공개로 간주됩니다.팀을 위한 채팅 또는 서버와 같이 더 넓은 그룹에 표시될 수 있는 채팅은 공개로 간주됩니다.텍스트가 어떻게 적격인지 확실하지 않은 경우 선택적 필드를 비워두십시오.

참고:

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

매개 변수

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

생성

폰트 패밀리의 이름과 얼굴을 포함하는 테이블을 반환합니다.

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


type FaceInfo = {
Name: string, -- 예: "일반", "책", "이탈릭", "얇은 이탈릭"
Weight: Enum.FontWeight,
Style: Enum.FontStyle, -- 정상 또는 이탈릭 Either Normal or Italic
}
type FamilyInfo = {
Name: string, -- 예: "소스 샌즈 프로", "그레즈 고티크"
Faces: {FaceInfo} -- 항상 최소 1개 이상, 최대 18개까지 있을 수 있습니다.
}

글꼴 가족이 이전에 GetFamilyInfoAsync 또는 ContentProvider:PreloadAsync() 또는 TextLabel.FontFace 속성 설정있는 텍스트 개체에 의해 이미 로드되었으면 메서드는 포기하지 않고 반환됩니다.

오류

네트워크 오류로 인해 이 메서드가 실패할 수 있습니다. 항상 오류 처리를 위해 pcall로 감싸야 합니다.

다음 시나리오에서 오류를 던집니다:

  • 전달된 가족은 빈 문자열입니다.
  • 가족을 다운로드하는 데 실패했습니다.
  • 자산 ID가 유효하지 않거나 존재하지 않는 자산으로 가리킵니다.

매개 변수

assetId: ContentId

조회할 글꼴 가족의 자산 ID.

기본값: ""

반환

글꼴 가족에 대한 정보.

코드 샘플

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

생성

이 메서드는 와 유사하지만, 더 많은 글꼴에 액세스할 수 있는 개체를 대신 사용합니다.

일부 텍스트의 문자열, 길이 및 글꼴과 같은 속성 집합을 측정하는 데 사용됩니다.

일부 글꼴을 측정하려면 로드해야 할 수도 있기 때문에 이것은 생산 함수입니다. This is a yield function because some fonts may need to be loaded in order to measure them.글꼴이 이미 로드되었으면 생성되지 않습니다.ContentProvider:PreloadAsync() 폰트가 로드되는지 확인하기 위해 사용할 수 있습니다.

오류

네트워크 오류로 인해 이 메서드가 실패할 수 있습니다. 항상 오류 처리를 위해 pcall로 감싸야 합니다.

다음 시나리오에서 오류를 던집니다:

  • GetTextBoundsParams.Font 에는 빈 가족이 있습니다.
  • params 인수는 nil 이었습니다.
  • 폰트 패밀리 또는 폰트 페이스 다운로드에 실패했습니다.

매개 변수

GetTextBoundsParams 개체에 대한 참조.

기본값: ""

반환

텍스트의 크기가 Vector2로 표시됩니다.

코드 샘플

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
기본값: ""

반환

이벤트