KeyframeSequenceProvider
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Dịch vụ KeyframeSequenceProvider cung cấp chức năng để tải và xem trước KeyframeSequences .Nó bao gồm một số chức năng hữu ích khi làm việc với Animations .
Một KeyframeSequence cửa hàng lưu trữ một loạt Poses mã hóa cấu trúc và chuyển động của một hiệu ứng động.Dữ liệu hoạt hình Roblox sử dụng trong phát lại của một hiệu ứng động, được tham chiếu bởi thuộc tính Animation.AnimationId, có thể được xây dựng từ một KeyframeSequence . KeyframeSequences thường được tạo bởi Roblox Trình chỉnh sửa hoạt hình nhưng có thể được tạo thông qua các plugin khác hoặc thậm chí thủ công.
Mẫu mã
This code sample contains a simple function to generate an Animation with a generated hash ID to preview a KeyframeSequence locally.
local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
local function createPreviewAnimation(keyframeSequence)
local hashId = KeyframeSequenceProvider:RegisterKeyframeSequence(keyframeSequence)
local Animation = Instance.new("Animation")
Animation.AnimationId = hashId
return Animation
end
local keyframeSequence = Instance.new("KeyframeSequence")
local animation = createPreviewAnimation(keyframeSequence)
print(animation)
Tóm Tắt
Phương Pháp
Tạo một ID tài sản tạm thời từ một KeyframeSequence có thể được sử dụng để thử nghiệm địa phương hóa cho một hoạt hiệu ứng động. Tạo một URL active:// .
Tạo một ID tài sản tạm thời từ một KeyframeSequence có thể được sử dụng để thử nghiệm địa phương hóa cho một hoạt hiệu ứng động. Tạo một hash.
Chức năng này trả về một đối tượng InventoryPages có thể được sử dụng để lặp lại các hoạt họa thuộc về một người dùng cụ thể.
Trả về một chuỗi khung chìa khóa dựa trên ID tài sản được chỉ định theo cách không đồng bộ.
Thuộc Tính
Phương Pháp
RegisterActiveKeyframeSequence
Tạo một ID tài sản tạm thời từ một KeyframeSequence có thể được sử dụng để thử nghiệm địa phương hóa cho một hiệu ứng động.
Chức năng này thực hiện chức năng tương tự với KeyframeSequenceProvider:RegisterKeyframeSequence() tuy nhiên chức năng này tạo ra một URL active:// thay vì một hash.
ID được tạo có thể được sử dụng trong một thuộc tính Animation.AnimationId để kiểm tra.
ID tài sản được tạo bởi chức năng này là tạm thời và không thể sử dụng bên ngoài Studio.Các nhà phát triển muốn tạo một ID tài sản có thể được sử dụng trực tuyến nên tải lên KeyframeSequence vào Roblox.
Tham Số
Các KeyframeSequence được sử dụng.
Lợi Nhuận
Một ID tài sản tạm thời được tạo ra cho phát lại hoạt hình địa phương.
Mẫu mã
This code sample contains a simple function to generate an Animation with a generated hash ID to preview a KeyframeSequence locally.
local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
local function createPreviewAnimation(keyframeSequence)
local hashId = KeyframeSequenceProvider:RegisterKeyframeSequence(keyframeSequence)
local Animation = Instance.new("Animation")
Animation.AnimationId = hashId
return Animation
end
local keyframeSequence = Instance.new("KeyframeSequence")
local animation = createPreviewAnimation(keyframeSequence)
print(animation)
RegisterKeyframeSequence
Tạo một ID tài sản tạm thời từ một KeyframeSequence có thể được sử dụng để thử nghiệm địa phương hóa cho một hiệu ứng động.
Chức năng này thực hiện chức năng tương tự với KeyframeSequenceProvider:RegisterActiveKeyframeSequence() tuy nhiên chức năng này tạo ra một hash thay vì một URL active:// .
ID được tạo có thể được sử dụng cho thuộc tính Animation.AnimationId để kiểm tra hoạt họa.
ID tài sản được tạo bởi chức năng này là tạm thời và không thể sử dụng bên ngoài Studio.Các nhà phát triển muốn tạo một ID tài sản có thể được sử dụng trực tuyến nên tải lên KeyframeSequence vào Roblox.
Tham Số
Các KeyframeSequence được sử dụng.
Lợi Nhuận
Một ID tài sản tạm thời được tạo ra cho phát lại hoạt hình địa phương.
Mẫu mã
local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
local asset = KeyframeSequenceProvider:RegisterKeyframeSequence(workspace.KeyframeSequence)
local animation = Instance.new("Animation")
animation.Name = "TestAnimation"
animation.AnimationId = asset
animation.Parent = workspace
GetAnimations
Chức năng này trả về một đối tượng InventoryPages có thể được sử dụng để lặp lại các hoạt họa thuộc về một người dùng cụ thể.
Chức năng này có một số cách sử dụng tiềm năng, chẳng hạn như cho phép người dùng duyệt và nhập các hoạt họa vào một plugin hoạt họa tùy chỉnh.
Tham Số
ID người dùng của người dùng.
Lợi Nhuận
Một InventoryPages của hoạt hình.
Mẫu mã
This code sample includes a demonstration of how the content IDs of animations belonging to a player can be downloaded using KeyframeSequenceProvider:GetAnimations(). To run this code be sure to change the USER_ID variable to the ID of the user whose animations you want to download.
local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
local USER_ID = 0 -- Insert your UserId here
local function extractPages(pagesObject)
local array = {}
while true do
local thisPage = pagesObject:GetCurrentPage()
for _, v in pairs(thisPage) do
table.insert(array, v)
end
if pagesObject.IsFinished then
break
end
pagesObject:AdvanceToNextPageAsync()
end
return array
end
local inventoryPages = KeyframeSequenceProvider:GetAnimations(USER_ID)
local animationIds = extractPages(inventoryPages)
for _, id in pairs(animationIds) do
print(id)
end
print("total: ", #animationIds)
GetKeyframeSequenceAsync
GetKeyframeSequenceAsync trả về một KeyframeSequence dựa trên ID tài sản được chỉ định.ID tài sản phải phù hợp với một hoạt hiệu ứng động.Chức năng sẽ hoạt động cho đến khi KeyframeSequence được tải từ trang web.Bởi vì đây là một cuộc gọi web nó nên được bọc trong một cuộc gọi pcall.
Tham Số
ID nội dung của hoạt hiệu ứng động.
Lợi Nhuận
The KeyframeSequence được tìm thấy.
Mẫu mã
Demonstrates getting an animation's KeyframeSequence using KeyframeSequenceProvider:GetKeyframeSequenceAsync() and printing the time of each keyframe.
local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
local ANIMATION_ID = "rbxassetid://507771019"
-- Get the keyframe sequence for the asset
local keyframeSequence
local success, err = pcall(function()
keyframeSequence = KeyframeSequenceProvider:GetKeyframeSequenceAsync(ANIMATION_ID)
end)
if success then
-- Iterate over each keyframe and print its time value
local keyframeTable = keyframeSequence:GetKeyframes()
for key, value in keyframeTable do
print(`The time of keyframe number {key} is: {value.Time}`)
end
else
print(`Error getting KeyframeSequence: {err}`)
end