在 Roblox 中,動畫被鎖定在擁有那些動畫的使用者擁有的體驗上。若要防止動畫在你將體驗轉移到群組時破碎,你必須將動畫資產發布給新體驗群組所有者。
如果您有大量需要上傳的動畫,您可以使用社群支持的工具 Roblox 動畫傳輸 重新上傳動畫並將舊的 AnimationIds 重新映射到新的相應 AnimationIds 。
前提
在傳送動畫之前,你必須安裝 npx。npx讓您可以從包裝中執行指令,而不需要將這些包裝安裝到您的系統上。要檢查 npx ,請在終端窗口安裝 node.js 並執行 npx –version 。
有關必備條件的更多信息,請參閱 Roblox 動畫傳輸 README 。
將地圖動畫ID轉換為名稱
如果您的動畫被儲存在體驗中的預先準備角色模型下的動畫實例中,您可以生成一個文本文件來將 AnimationIds 映射到對應的名稱。
在 Roblox Studio 中,執行以下指令碼。Studio 將結果輸出為單一長字串。
local Workspace = game:GetService("Workspace")local ANIMSTRING = ""for _, character in Workspace:GetChildren() doif not character:IsA("Model") thencontinueendlocal animations = character:FindFirstChild("Animations")if not animations thencontinueendfor _, animation in animations:GetChildren() dolocal animationId = string.match(animation.AnimationId, "%d+")if animationId thenANIMSTRING ..= (animationId .. " " .. character.Name .. "_" .. string.gsub(animation.Name, " ", "_") .. "\n")endendendprint(ANIMSTRING)在您的電腦上創建一個新的文本文件。
將 Studio 的字串輸出貼到文本文件中。
清除任何與檔案內容自動添加的額外 -Edit 和 -Studio 字串有關的差異。
將所有空格替換為橫線以限制整體上管理的名稱數量。
(可選) 準備文字檔案
Roblox 對動畫上傳有內部速率限制。Roblox 動畫轉移工具不遵守此速率限制,可能會在轉移過程中造成問題並破壞最終的文字檔案。例如,你可能會轉移 1200 個動畫,但最終只有 900 個動畫並沒有方法來確定哪些未能轉移。
為了確保最終檔案不會斷裂,您可以:
- 將文字檔案分為多個檔案,每個檔案最多有 200 個動畫。
- 在每個個別檔案上使用 Roblox 動畫傳輸工具。為了防止任何主要速度限制問題,請在每個批量之間等待幾分鐘。
傳輸動畫
當您的文字檔案準備好之後,開始傳輸過程:
- 開啟終端窗口。
- 執行 npx roblox-animation-transfer --inFile animations.txt --group YOUR_GROUP_ID --outFile newAnimations.txt 。
- --inFile 必須指向你想上傳的動畫的文件。這個檔案可以是你最初創建的大型文字檔案,或者如果你選擇將較大的文件分解為多個較小的文件,那就是第一個較小的文件。
- --group 必須指向接收動畫傳輸的群組 GroupId 。您可以在 Roblox 網站上的群組 URL 中找到群組 ID。
- --outFile 必須指向你想要放置新動畫的文件。
如果傳輸過程成功,在 outFile 中的動畫會列出與在 inFile 中提供的順序相同。如果一些動畫無法傳輸,工具會嘗試再次傳輸它們;如果第二次嘗試成功,這些動畫將被添加到列表的尾部在 outFile 。
在運行時載入動執行階段
傳送您的動畫到新群組所有者後,您必須交換舊動畫換取新動畫。
在工作室中,創建 Animations 模組。
創建兩個子模塊,一個對應使用者,或原始擁有者,另一個對應群組或新擁有者。
若選擇將體驗發布到另一個位置,請執行以下腳指令碼。預設情況下,腳本會返回使用者的動畫。
local module = {}local GROUP_ID = 12345678local gameContext = {["User"] = require(script:WaitForChild("Animations_User")),["Group"] = require(script:WaitForChild("Animations_Group"))}local function getAnimationMapForGameContext()if game.CreatorType == Enum.CreatorType.Group and game.CreatorId == GROUP_ID thenreturn gameContext.Groupendreturn gameContext.Userendlocal animationMap = getAnimationMapForGameContext()function module.getAnimation(animName: string)return animationMap[animName]endreturn module將生成的文字檔案轉換為 Studio 的動畫地圖。
- 將 animFileText 變量中的動畫列替換為你想要轉換為動畫地圖的文字檔案的內容。
- 執行以下指令以返回字串:
local animFileText = [[4215167 Animation_Name_16171235 Animation_Name_21251267 Animation_Name_3]]local function convertFileToAnimationMap(animFileText: string)local NEW_ANIMATION_MAP = ""local lines = string.split(animFileText, "\n")for _, line in lines dolocal components = string.split(line, " ")if #components ~= 2 thencontinueendlocal animationId = components[1]local animationName = components[2]NEW_ANIMATION_MAP = string.format("%s\t[\"%s\"] = \"rbxassetid://%s\",\n", NEW_ANIMATION_MAP, animationName, animationId)endreturn string.format("return {\n%s}", NEW_ANIMATION_MAP)endprint(convertFileToAnimationMap(animFileText))創建一個新的 ModuleScript 父級給你的 Animations 模組。
將返回的 animFileText 字串放置在 ModuleScript 內。
更新體驗以源所有動畫通過 Animations 模組運行以下指令碼:
local Animations = require(PATH.TO.ANIMATIONS)local warriorWalk = Instance.new("Animation")warriorWalk.AnimationId = Animations.getAnimation("Warrior_Walk")