KeyframeSequenceProvider

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
服務
未複製

鑰匙框順序提供者 服務提供載入和預覽 的功能。它包含一些與 Animations 工作時有用的功能。

A KeyframeSequence 儲存一系列 Poses 用來編碼動畫的階層和運動。使用 Animation.AnimationId 屬性參考的動畫資料,在播放動畫時由 Roblox 使用,可以從 KeyframeSequence 中構建。KeyframeSequences 通常由 Roblox 動畫編輯器 創建,但也可以通過其他插件或甚至手動創建。

範例程式碼

This code sample contains a simple function to generate an Animation with a generated hash ID to preview a KeyframeSequence locally.

Create temporary animation

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)

概要

方法

屬性

方法

RegisterActiveKeyframeSequence

ContentId

KeyframeSequence 生成暫時資產ID,可用於動畫的本地化測試。

此功能執行與 KeyframeSequenceProvider:RegisterKeyframeSequence() 相同的功能,但此功能會生成一個 active:// 網址,而不是一個哈希。

生成的ID可以在Animation.AnimationId屬性中用於測試。

由此函數生成的資產ID是暫時的,無法在 Studio 之外使用。想要在線使用的資產ID生成的開發人員應該將 KeyframeSequence 上傳到 Roblox。

參數

keyframeSequence: Instance

要使用的 KeyframeSequence

預設值:""

返回

ContentId

為本地化動畫播放生成的暫時資產ID。

範例程式碼

This code sample contains a simple function to generate an Animation with a generated hash ID to preview a KeyframeSequence locally.

Create temporary animation

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

ContentId

KeyframeSequence 生成暫時資產ID,可用於動畫的本地化測試。

此功能執行與 KeyframeSequenceProvider:RegisterActiveKeyframeSequence() 相同的功能,但此功能會生成一個哈希而不是 active:// 網址。

生成的ID可用於測試動畫的Animation.AnimationId屬性。

由此函數生成的資產ID是暫時的,無法在 Studio 之外使用。想要在線使用的資產ID生成的開發人員應該將 KeyframeSequence 上傳到 Roblox。

參數

keyframeSequence: Instance

要使用的 KeyframeSequence

預設值:""

返回

ContentId

為本地化動畫播放生成的暫時資產ID。

範例程式碼

KeyframeSequenceProvider:RegisterKeyframeSequence

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

暫停

此功能返回一個 InventoryPages 對象,可用於循環特定用戶擁有的動畫。

此功能有許多潛在用途,例如讓使用者瀏覽和匯入動畫到自訂動畫外掛程式。

參數

userId: number

使用者的使用者ID。

預設值:""

返回

一個 InventoryPages 的動畫。

範例程式碼

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.

KeyframeSequenceProvider GetAnimations

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 返回基於指定資產ID的 KeyframeSequence 。資產ID必須對應一個動畫。該功能將持續直到 KeyframeSequence 從網站載入。因為這是一個網路呼叫,因此應該包含在 pcall 中。

參數

assetId: ContentId

動畫的內容 ID。

預設值:""

返回

範例程式碼

Demonstrates getting an animation's KeyframeSequence using KeyframeSequenceProvider:GetKeyframeSequenceAsync() and printing the time of each keyframe.

Getting an animation's KeyframeSequence

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

活動