KeyframeSequenceProvider
*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.
Le service KeyframeSequenceProvider fournit des fonctions pour charger et prévisualiser KeyframeSequences .Il inclut un certain nombre de fonctions utiles lorsque vous travaillez avec Animations .
Un KeyframeSequence stocke une série de Poses qui encodent la hiérarchie et le mouvement d'une animations.Les données d'animation que Roblox utilise dans la lecture d'une animations, référencées par la propriété Animation.AnimationId, peuvent être construites à partir d'un KeyframeSequence.KeyframeSequences sont généralement créés par le Roblox Éditeur d'animation mais peuvent être créés via d'autres plugins ou même manuellement
Échantillons de code
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)
Résumé
Méthodes
Génère un ID de ressource temporaire à partir d'un KeyframeSequence qui peut être utilisé pour le test localisé d'une animations. Génère une URL active:// active.
Génère un ID de ressource temporaire à partir d'un KeyframeSequence qui peut être utilisé pour le test localisé d'une animations. Génère un hash.
Cette fonction renvoie un objet InventoryPages qui peut être utilisé pour itérer sur les animations appartenant à un utilisateur spécifique.
Retourne une séquence de cadre clé en fonction de l'ID spécifié asynchrone.
Propriétés
Méthodes
RegisterActiveKeyframeSequence
Génère un ID de ressource temporaire à partir d'un KeyframeSequence qui peut être utilisé pour le test localisé d'une animations.
Cette fonction effectue la même fonction à KeyframeSequenceProvider:RegisterKeyframeSequence() cependant cette fonction génère une URL active:// au lieu d'un hash.
L'ID généré peut être utilisé dans une propriété Animation.AnimationId pour le test.
L'ID de ressource généré par cette fonction est temporaire et ne peut pas être utilisé en dehors de Studio.Les développeurs souhaitant générer un ID de ressource pouvant être utilisé en ligne doivent télécharger le KeyframeSequence à Roblox.
Paramètres
Le KeyframeSequence à utiliser.
Retours
Un ID de ressource temporaire généré pour la lecture d'animation localisée.
Échantillons de code
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
Génère un ID de ressource temporaire à partir d'un KeyframeSequence qui peut être utilisé pour le test localisé d'une animations.
Cette fonction effectue la même fonction à cependant cette fonction génère un hash au lieu d'une URL active://.
L'ID généré peut être utilisé pour la propriété Animation.AnimationId pour tester les animations.
L'ID de ressource généré par cette fonction est temporaire et ne peut pas être utilisé en dehors de Studio.Les développeurs souhaitant générer un ID de ressource pouvant être utilisé en ligne doivent télécharger le KeyframeSequence à Roblox.
Paramètres
Le KeyframeSequence à utiliser.
Retours
Un ID de ressource temporaire généré pour la lecture d'animation localisée.
Échantillons de code
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
Cette fonction renvoie un objet InventoryPages qui peut être utilisé pour itérer sur les animations appartenant à un utilisateur spécifique.
Cette fonction a plusieurs utilisations potentielles, comme permettre aux utilisateurs de parcourir et d'importer des animations dans un plugin d'animation personnalisé.
Paramètres
L'ID utilisateur de l'utilisateur.
Retours
Un InventoryPages d'animations.
Échantillons de code
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 renvoie un KeyframeSequence basé sur l'ID de ressource spécifié.L'assetId doit correspondre à une animations.La fonction produira jusqu'à ce que le KeyframeSequence soit chargé à partir du site Web.Parce que c'est un appel web, il devrait être emballé dans un appel pcall.
Paramètres
L'ID du contenu de l'animations.
Retours
Le KeyframeSequence trouvé.
Échantillons de code
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