Asset Service
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
ข้อมูลสรุป
คุณสมบัติ
วิธีการ
เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
วิธีการ
Compose Decal Async
ส่งค่ากลับ
()
ตัวอย่างโค้ด
สร้าง Decal
local AssetService = game:GetService("AssetService")
-- สร้างอินสแตนซ์ของ decal สองตัว
local decalA = Instance.new("Decal")
local decalB = Instance.new("Decal")
-- สร้างตารางข้อมูล composite
local compositeInfo = {
{
ColorMap = decalA.ColorMapContent,
RoughnessMap = decalA.RoughnessMapContent,
MetalnessMap = decalA.MetalnessMapContent,
NormalMap = decalA.NormalMapContent,
},
{
ColorMap = Content.fromAssetId(123456),
RoughnessMap = decalB.RoughnessMapContent,
MetalnessMap = decalB.MetalnessMapContent,
NormalMap = decalB.NormalMapContent,
}
}
-- สร้าง decal เพื่อรวม
local compositeDecal = Instance.new("Decal")
-- รวม decal ที่มีอยู่โดยใช้ AssetService
local success, errorMessage = pcall(function()
AssetService:ComposeDecalAsync(compositeDecal, compositeInfo)
end)
if success then
print("รวม decal สำเร็จ!")
-- Logic เพื่อแสดง/ใช้ decal ที่นี่
else
warn("ล้มเหลวในการรวม decal:", errorMessage)
endCreate Asset Async
Asset Service: Create Asset Async(
พารามิเตอร์
| ค่าเริ่มต้น: nil |
ส่งค่ากลับ
ตัวอย่างโค้ด
AssetService:CreateAssetAsync
local AssetService = game:GetService("AssetService")
local editableMesh = AssetService:CreateEditableMesh()
-- เพิ่มจุดยอด, หน้าต่าง, และ uvs ลงใน mesh
local requestParameters = {
CreatorId = 123,
CreatorType = Enum.AssetCreatorType.User,
Name = "สินทรัพย์ของฉัน",
Description = "สินทรัพย์ที่ดี",
}
local ok, result, idOrUploadErr = pcall(function()
return AssetService:CreateAssetAsync(editableMesh, Enum.AssetType.Mesh, requestParameters)
end)
if not ok then
warn(`เกิดข้อผิดพลาดในการเรียก CreateAssetAsync: {result}`)
elseif result == Enum.CreateAssetResult.Success then
print(`สำเร็จ, ID สินทรัพย์ใหม่: {idOrUploadErr}`)
else
warn(`ข้อผิดพลาดในการอัปโหลดใน CreateAssetAsync: {result}, {idOrUploadErr}`)
endCreate Asset Version Async
Asset Service: Create Asset Version Async(
พารามิเตอร์
| ค่าเริ่มต้น: nil |
ส่งค่ากลับ
ตัวอย่างโค้ด
AssetService:CreateAssetVersionAsync
local AssetService = game:GetService("AssetService")
local assetIdToUpdate = 321
local model = Instance.new("Model")
local requestParameters = {
CreatorId = 123,
CreatorType = Enum.AssetCreatorType.User,
}
local ok, result, versionOrUploadErr = pcall(function()
return AssetService:CreateAssetVersionAsync(model, Enum.AssetType.Model, assetIdToUpdate, requestParameters)
end)
if not ok then
warn(`เกิดข้อผิดพลาดในการเรียก CreateAssetVersionAsync: {result}`)
elseif result == Enum.CreateAssetResult.Success then
print(`สำเร็จ, เวอร์ชันสินทรัพย์ใหม่: {versionOrUploadErr}`)
else
warn(`เกิดข้อผิดพลาดในการอัปโหลดใน CreateAssetVersionAsync: {result}, {versionOrUploadErr}`)
endCreate Data Model Content Async
พารามิเตอร์
ส่งค่ากลับ
Create Decal Async
Create Editable Image
พารามิเตอร์
ส่งค่ากลับ
Create Editable Image Async
Asset Service: Create Editable Image Async(
พารามิเตอร์
ส่งค่ากลับ
Create Editable Mesh
พารามิเตอร์
ส่งค่ากลับ
Create Editable Mesh Async
พารามิเตอร์
ส่งค่ากลับ
Create Mesh Part Async
พารามิเตอร์
| ค่าเริ่มต้น: nil |
ส่งค่ากลับ
Create Place Async
Create Place In Player Inventory Async
Create Surface Appearance Async
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
AssetService:CreateSurfaceAppearanceAsync
local AssetService = game:GetService("AssetService")
local Workspace = game:GetService("Workspace")
-- สีเขียว - เนื้อหาภาพที่แก้ไขได้
local colorEditableImage = AssetService:CreateEditableImage({ Size = Vector2.new(4, 4) })
colorEditableImage:DrawRectangle(Vector2.zero, colorEditableImage.Size, Color3.fromRGB(0, 255, 0), 0, Enum.ImageCombineType.Overwrite)
-- Emissive (ดูเฉพาะช่องสีแดง) - เนื้อหาของ DataModel
local mapSize = 128
local quarterMapSize = mapSize / 4
local emissiveEditableImage = AssetService:CreateEditableImage({ Size = Vector2.new(mapSize, mapSize) })
-- สร้างลวดลายวงกลมโดยทำให้พื้นหลังทั้งหมดมีค่า emissive เป็น 0 และวงกลมสองวงที่อยู่ตรงข้ามกันมีค่า emissive เป็น 1.
emissiveEditableImage:DrawRectangle(Vector2.zero, emissiveEditableImage.Size, Color3.new(0, 0, 0), 0, Enum.ImageCombineType.Overwrite)
emissiveEditableImage:DrawCircle(Vector2.new(quarterMapSize, quarterMapSize*3), quarterMapSize, Color3.new(1, 0, 0), 0, Enum.ImageCombineType.Overwrite)
emissiveEditableImage:DrawCircle(Vector2.new(quarterMapSize*3, quarterMapSize), quarterMapSize, Color3.new(1, 0, 0), 0, Enum.ImageCombineType.Overwrite)
local dmcResult, emissiveDataModelContent = AssetService:CreateDataModelContentAsync(Content.fromObject(emissiveEditableImage))
assert(dmcResult == Enum.CreateContentResult.Success)
-- Metalness (ดูเฉพาะช่องสีแดง) - เนื้อหา Asset ID
local METALNESS_ASSET_ID = "rbxassetid://658743164"
local surfaceAppearance = AssetService:CreateSurfaceAppearanceAsync({
ColorMap = Content.fromObject(colorEditableImage),
EmissiveMask = emissiveDataModelContent,
MetalnessMap = Content.fromUri(METALNESS_ASSET_ID)
})
-- คุณยังสามารถเปลี่ยนแปลงคุณสมบัติส่วนใหญ่ได้ ยกเว้นเนื้อหาที่ใช้สำหรับแผนที่และ EmissiveMask.
surfaceAppearance.EmissiveStrength = 20
local meshPart = AssetService:CreateMeshPartAsync(Content.fromAssetId(16799342206))
meshPart.Parent = Workspace
meshPart.Anchored = true
meshPart.Position = Vector3.new(0, 2, 0)
-- ใช้ surface appearance กับ mesh part
surfaceAppearance.Parent = meshPartGet Asset Ids For Package
Get Asset Ids For Package Async
Get Audio Metadata Async
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
ดึงข้อมูลเมตาดาต้าเสียง
local AssetService = game:GetService("AssetService")
local SoundService = game:GetService("SoundService")
local trackIDs = {
SoundService.Sound1.SoundId,
SoundService.Sound2.SoundId,
SoundService.Sound3.SoundId,
SoundService.Sound4.SoundId,
}
local success, result = pcall(function()
return AssetService:GetAudioMetadataAsync(trackIDs)
end)
if success then
for i = 1, #trackIDs do
local contentId = "rbxassetid://" .. result[i].AssetId
if trackIDs[i] == contentId then
print(result[i].Title, "โดย", result[i].Artist)
else
warn("ไม่มีข้อมูลเมตาสำหรับสินทรัพย์ที่ร้องขอ #" .. tostring(i))
end
end
endGet Bundle Details Async
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
การรับรายละเอียดชุด
local AssetService = game:GetService("AssetService")
local BUNDLE_ID = 14
local success, result = pcall(function()
return AssetService:GetBundleDetailsAsync(BUNDLE_ID)
end)
if success then
print(result)
--[[
{
["BundleType"] = "BodyParts",
["Description"] = "ปี 5003, Battlebot 5000 ต้องเผชิญหน้ากับศัตรูที่แข็งแกร่งที่สุดของเขา หรือเผชิญกับการกลายเป็นล้าสมัย.",
["Id"] = 14,
["Items"] = {
[1] = {...},
[2] = {
["Id"] = 1678225030,
["Name"] = "SinisterBot 5001 แขนซ้าย",
["Type"] = "Asset"
},
[3] = {...},
[4] = {...},
[5] = {...},
[6] = {...},
[7] = {...}
},
["Name"] = "SinisterBot 5001"
}
--]]
endGet Composed Decal Layers
พารามิเตอร์
ส่งค่ากลับ
{ { [string]: Content | Vector2 } }
ตัวอย่างโค้ด
คัดลอก Decal ที่ประกอบขึ้น
local AssetService = game:GetService("AssetService")
local Workspace = game:GetService("Workspace")
local sourceDecal = Workspace.Part.Decal
-- อ่านสแต็คชั้นที่ ComposeDecalAsync เก็บไว้บน decal
local layers = AssetService:GetComposedDecalLayers(sourceDecal)
if #layers == 0 then
print("Decal นี้ไม่ได้ประกอบ")
return
end
for index, layer in layers do
print("ชั้น", index, "ColorMap:", layer.ColorMap)
end
-- ชั้นเหล่านี้ใช้รูปแบบที่ ComposeDecalAsync ยอมรับ ดังนั้นจึงสามารถส่งกลับไปยังมันได้
local copy = Instance.new("Decal")
local success, errorMessage = pcall(function()
AssetService:ComposeDecalAsync(copy, layers)
end)
if success then
copy.Parent = sourceDecal.Parent
else
warn("ล้มเหลวในการประกอบ decal:", errorMessage)
endGet Creator Asset ID
Get Game Places Async
ส่งค่ากลับ
ตัวอย่างโค้ด
AssetService:GetGamePlacesAsync
local AssetService = game:GetService("AssetService")
local placePages = AssetService:GetGamePlacesAsync()
while true do
for _, place in placePages:GetCurrentPage() do
print("ชื่อ:", place.Name)
print("PlaceId:", place.PlaceId)
end
if placePages.IsFinished then
break
end
placePages:AdvanceToNextPageAsync()
endLoad Asset Async
Prompt Create Platform Content Async
Asset Service: Prompt Create Platform Content Async(
พารามิเตอร์
ส่งค่ากลับ
Prompt Import Animation Clip From Video Async
Save Place Async
พารามิเตอร์
ส่งค่ากลับ
()
Search Audio
Search Audio Async
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
การค้นหาชื่อเพลง
local AssetService = game:GetService("AssetService")
local audioSearchParams = Instance.new("AudioSearchParams")
audioSearchParams.SearchKeyword = "happy"
local success, result = pcall(function()
return AssetService:SearchAudioAsync(audioSearchParams)
end)
if success then
local currentPage = result:GetCurrentPage()
for _, audio in currentPage do
print(audio.Title)
end
else
warn("ข้อผิดพลาดของ AssetService: " .. result)
end
--[[ รูปแบบข้อมูลที่ส่งกลับ
{
"AudioType": string,
"Artist": string,
"Title": string,
"Tags": {
"string"
},
"Id": number,
"IsEndorsed": boolean,
"Description": string,
"Duration": number,
"CreateTime": string,
"UpdateTime": string,
"Creator": {
"Id": number,
"Name": string,
"Type": number,
"IsVerifiedCreator": boolean
}
}
--]]