AvatarCreationService 是一个支持开发者虚拟形象创作者的服务,提供方法来支持体验内的虚拟形象创建提示。
概要
方法
获取有关资产必须遵守以通过 UGC 验证的规则的数据。
一次获取虚拟形象创建代币列表的虚拟形象创建代币详情。
- PromptCreateAvatarAsync(tokenId : string,player : Player,humanoidDescription : HumanoidDescription):Tuple
提示 Player 从一个 HumanoidDescription 购买并创建虚拟形象。
- ValidateUGCAccessoryAsync(player : Player,accessory : Instance,accessoryType : Enum.AccessoryType):Tuple
仅限工作室。对 Enum.AccessoryType 进行 UGC 验证。
仅限工作室。对 Enum.BodyPart 进行 UGC 验证。
仅限工作室。对整个身体进行 UGC 验证。
活动
- AvatarModerationCompleted(outfitId : number,moderationStatus : Enum.ModerationStatus):RBXScriptSignal
属性
方法
GetValidationRules
获取有关资产必须遵守以通过 UGC 验证的规则的数据。验证是创建虚拟形象之前的必要步骤,包括网格三角形限制、纹理大小限制、身体部分尺寸限制、附件位置限制等各种检查。
返回的验证规则词典以下形式:
{["MeshRules"] = {["BodyPartMaxTriangles"] = {Enum.AssetType.DynamicHead: number,Enum.AssetType.LeftArm: number,Enum.AssetType.RightArm: number,Enum.AssetType.Torso: number,Enum.AssetType.LeftLeg: number,Enum.AssetType.RightLeg: number,},["AccessoryMaxTriangles"]: number,["MeshVertColor"]: Color3,["CageMeshMaxDistanceFromRenderMesh"]: number,},["TextureRules"] = {["MaxTextureSize"]: number,},["BodyPartRules"] = {[Enum.AssetType.DynamicHead] = {["Bounds"] = {["Classic"] = {["MinSize"]: Vector3,["MaxSize"]: Vector3,},["ProportionsSlender"] = {["MinSize"]: Vector3,["MaxSize"]: Vector3,},["ProportionsNormal"] = {["MinSize"]: Vector3,["MaxSize"]: Vector3,},},["SubParts"] = {["Head"] = {["NeckRigAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},["FaceFrontAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},["HatAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},["HairAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},["FaceCenterAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},},},},[Enum.AssetType.LeftArm] = {["Bounds"] = {["Classic"] = {["MinSize"]: Vector3,["MaxSize"]: Vector3,},["ProportionsSlender"] = {["MinSize"]: Vector3,["MaxSize"]: Vector3,},["ProportionsNormal"] = {["MinSize"]: Vector3,["MaxSize"]: Vector3,},},["SubParts"] = {["LeftHand"] = {["LeftWristRigAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},["LeftGripAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},},["LeftUpperArm"] = {["LeftShoulderRigAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},["LeftShoulderAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},["LeftElbowRigAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},},["LeftLowerArm"] = {["LeftElbowRigAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},["LeftWristRigAttachment"] = {["LowerBound"]: Vector3,["UpperBound"]: Vector3,},},},},...},["AccessoryRules"] = {[Enum.AssetType.HairAccessory] = {["Attachments"] = {{["Size"]: Vector3,["Offset"]: Vector3,["Name"]: string,},},["RigidAllowed"]: boolean,},...}}
返回
验证规则的词典如上述详细。
GetBatchTokenDetailsAsync
一次获取虚拟形象创建代币列表的虚拟形象创建代币详情(代币通过 创建代币生成过程 生成)。返回一个阵列的虚拟形象创建代币详情;每个代币详情是指在下面的示例结果中指定的领域的词典:
{["Name"] = "string",["Description"] = "string",["UniverseId"] = 0,["CreatorId"] = 0,["CreatorType"] = Enum.CreatorType.User,["OnSale"] = true,["Price"] = 0,["OffSaleReasons"] = {"string",}}
参数
获得详细信息的虚拟形象创建代币ID列表。
返回
上述所述的虚拟形象创建代币详情的阵列。
PromptCreateAvatarAsync
提示 Player 从一个 HumanoidDescription 购买并创建虚拟形象。创建的价格由虚拟形象创建代币的价格决定。这个虚拟形象创建代币是购买和创建身体所需的,可以通过遵循 创建代币生成过程 来生成。
对于虚拟形象作品,HumanoidDescription 期望包含为每个身体部位创建的新资产(Head、Torso、RightLeg、LeftLeg、RightArm、LeftArm)。可选地,它还可以包括新的 Hair 饰品。
为了支持这一点, HumanoidDescription 应包含 6 个 BodyPartDescription 孩子(每个身体部分一个)。对于每个, 属性引用一个 包含所有构成身体部分的 实例,例如一个 文件夹,包含 , ,和 。BodyPartDescription.BodyPart 属性也应设置为相关的Enum.BodyPart。
每个身体部分 MeshPart 也需要包括:
- An EditableImage .
- 一个 WrapDeformer 具有 EditableMesh 。
如果包含头发等配件,那么 HumanoidDescription 应包含一个子 AccessoryDescription ,其中:
- AccessoryDescription.Instance 属性引用 Accessory 实例。
最后, HumanoidDescription 应包含 BodyTypeScale , HeadScale , HeightScale , WidthScale 和 ProportionScale 的人形尺寸。注意导入基础体的尺寸,使其与提供给 HumanoidDescription 的尺寸匹配。
参数
虚拟形象创建代币的ID。代币必须有效,即方法调用的宇宙与代币创建的宇宙相同。此外,代币创建者必须维护ID验证和Roblox Premium。要创建一个在此 API 中使用的代币,请遵循 代币创建 过程。
用于作品建的虚拟形象的 HumanoidDescription。
返回
包含以下顺序的 tuple:
一个 Enum.PromptCreateAvatarResult 指示创建提示的结果。
一个字符串结果。在 Enum.PromptCreateAvatarResult.Success 的情况下,这将表示包裹 ID。在任何失败枚列的情况下,这将显示结果错误消信息。
一个可选的次要字符串结果。在 Enum.PromptCreateAvatarResult.Success 的情况下,这将表示服装 ID。在任何失败枚列的情况下,这将是 nil 。
代码示例
The following code populates a HumanoidDescription in the expected format, prompts for avatar creation, and responds to the result.
local AvatarCreationService = game:GetService("AvatarCreationService")
export type BodyPartInfo = {
bodyPart: Enum.BodyPart,
instance: Instance, --Folder with Created MeshParts
}
export type BodyPartList = { BodyPartInfo }
local function publishAvatar(bodyPartInstances: BodyPartList, player: Player, tokenId: string)
local humanoidDescription = Instance.new("HumanoidDescription")
for _, bodyPartInfo in bodyPartInstances do
local bodyPartDescription = Instance.new("BodyPartDescription")
bodyPartDescription.Instance = bodyPartInfo.instance
bodyPartDescription.BodyPart = bodyPartInfo.bodyPart
bodyPartDescription.Parent = humanoidDescription
end
local pcallSuccess, result, resultMessage = pcall(function()
return AvatarCreationService:PromptCreateAvatarAsync(tokenId, player, humanoidDescription)
end)
if pcallSuccess then
if result == Enum.PromptCreateAvatarResult.Success then
print("Successfully uploaded with BundleId: ", resultMessage)
else
print("Unsuccessfully uploaded with error message:", resultMessage)
end
else
print("Avatar failed to create.")
end
end
ValidateUGCAccessoryAsync
仅限工作室。给予一个 Player 和 Instance 对于一个 Enum.AccessoryType ,决定是否通过 UGC 验证。
参数
实例验证已运行。
Enum.AccessoryType 实例应该是。期望 Eyebrow , Eyelash , 或 Hair .
返回
包含以下顺序的 tuple:
- 一个用于指示是否验证成功的 boolean 值,用于饰品。
- 可选的字符串表。这包括验证失败的原因,如果验证成功,则 nil 如果验证成功。
ValidateUGCBodyPartAsync
仅限工作室。给出一个 Player 和 Instance 对于一个 Enum.BodyPart ,决定是否通过 UGC 验证。在下列示例格式中,期望 instance 参数作为 Folder 以相关 MeshParts :
然而,如果期望的 bodyPart 是 Enum.BodyPart.Head , 函数直接接受单数 Head``Class.MeshPart 。
参数
实例验证已运行。
Enum.BodyPart 实例应该是。
返回
包含以下顺序的 tuple:
- 一个指示是否验证成功的 boolean 值,用于身体部分。
- 可选的字符串表。这包括验证失败的原因,如果验证成功,则 nil 如果验证成功。
ValidateUGCFullBodyAsync
仅限工作室。给予 Player 和 HumanoidDescription , 所有在 HumanoidDescription 中的实例都将被验证。
该 HumanoidDescription 期望包含在每个需要的 BodyPartDescription 值上设置的实例,用于 6 个必需的 Enum.BodyPart 值。可选地,它可以包括在 AccessoryDescription 子上设置的实例为 Eyebrow , Eyelash , 和 Hair AccessoryTypes 。
参数
HumanoidDescription 代表在验证运行时使用的身体。
返回
包含以下顺序的 tuple:
- 一个指示是否验证成功的 boolean 值,用于身体。
- 可选的字符串表。这包括验证失败的原因,如果验证成功,则 nil 如果验证成功。