Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------------
- --[[ Set-Up ]]
- --------------------------------------------------------------------------------------
- if game:GetService("CoreGui"):FindFirstChild("KeyframeEvents") then
- game:GetService("CoreGui"):FindFirstChild("KeyframeEvents"):Destroy()
- end
- local toolbar = plugin:CreateToolbar("KeyframeEvents")
- local button = toolbar:CreateButton("Open GUI", "Keyframe Events for animations", "rbxassetid://10043212933")
- button.ClickableWhenViewportHidden = true
- local Selection = game:GetService("Selection")
- local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
- local TweenService = game:GetService("TweenService")
- local RunService = game:GetService("RunService")
- local StudioService = game:GetService("StudioService")
- local Folder = script.Parent
- local GUI = Folder.KeyframeEvents:Clone()
- GUI.Main.Visible = false
- local NoModelWarning = GUI.NoModelWarning
- local TopFrame = GUI.Main.TopFrame
- local PartHighlighter = require(Folder.PartHighlighter)
- local SliderModule = require(Folder.SliderModule)
- local SliderFrame = TopFrame.Info.KeyframesSlider
- local SelectedKeyframeTextbox = TopFrame.Info.SelectedKeyframe
- local dummy = nil
- local animator:Animator = nil
- local playingAnim = false
- local stopAnim = false
- local ParticleButton = TopFrame.ParticleButton
- local ParticleButtonFrame = ParticleButton.Frame
- local SoundButton = TopFrame.SoundButton
- local SoundButtonFrame = SoundButton.Frame
- local PartButton = TopFrame.PartButton
- local PartButtonFrame = PartButton.Frame
- GUI.Parent = game:GetService("CoreGui")
- GUI.Enabled = false
- local guiVisible = false
- local function toggleGui()
- guiVisible = not guiVisible
- GUI.Enabled = guiVisible
- end
- local Slider = SliderModule.new(SliderFrame,0.5)
- --------------------------------------------------------------------------------------
- --[[ Functions ]]
- --------------------------------------------------------------------------------------
- PartHighlighter.Initialize(plugin)
- PartHighlighter.ToggleFeature()
- function weld(x, y)
- if x == y then return end
- local CJ = CFrame.new(x.Position)
- local w = Instance.new("ManualWeld")
- w.Part0 = x
- w.Part1 = y
- w.C0 = x.CFrame:inverse() * CJ
- w.C1 = y.CFrame:inverse() * CJ
- w.Parent = x
- return w
- end
- local t = {}
- local rootPart
- local track = nil
- local function checkSelectionAndShowGui()
- local selectedObjects = Selection:Get()
- if #selectedObjects == 1 then
- local selected = selectedObjects[1]
- if selected:IsA("Model") and selected:FindFirstChild("AnimSaves") then
- --
- GUI.Main.Visible = true
- NoModelWarning.Visible = false
- stopAnim = false
- animator = selected.Humanoid.Animator
- t = selected:FindFirstChild("AnimSaves").Potion:GetChildren()
- table.sort(t, function(a, b)
- return a.Time < b.Time -- Compare the time values
- end)
- for i, v in pairs(t) do
- t[i] = v.Time
- end
- --
- local function studioPreviewAnimation(model, animation)
- -- find the AnimationController and Animator
- local animationController = model:FindFirstChildOfClass("Humanoid")
- or model:FindFirstChildOfClass("AnimationController")
- local animator = animationController and animationController:FindFirstChildOfClass("Animator")
- if not animationController or not animator then
- return
- end
- local asset = KeyframeSequenceProvider:RegisterKeyframeSequence(workspace.KeyframeSequence)
- local animation = workspace:FindFirstChild("TestAnimation")
- if animation == nil then
- animation = Instance.new("Animation")
- animation.Name = "TestAnimation"
- animation.AnimationId = asset
- animation.Parent = workspace
- end
- track = animator:LoadAnimation(animation)
- --track.Looped = true
- track:Play()
- --track:AdjustSpeed(0)
- --[[task.spawn(function()
- -- preview the animation
- local startTime = tick()
- while (tick() - startTime) < track.Length do
- local step = RunService.Heartbeat:wait()
- animator:StepAnimations(step)
- if stopAnim then
- track:Stop(0)
- animator:StepAnimations(0)
- return
- end
- end
- end)]]
- -- stop the animation
- --track:Stop(0)
- --animator:StepAnimations(0)
- -- reset the joints
- for _, descendant in pairs(model:GetDescendants()) do
- if descendant:IsA("Motor6D") then
- local joint = descendant
- joint.CurrentAngle = 0
- joint.Transform = CFrame.new()
- end
- end
- end
- studioPreviewAnimation(selected)
- --[[task.spawn(function()
- while not stopAnim and task.wait(0.1) do
- local step = game:GetService("RunService").Heartbeat:wait()
- animator:StepAnimations(step)
- end
- end)]]
- else
- NoModelWarning.Visible = true
- GUI.Main.Visible = false
- stopAnim = true
- end
- else
- NoModelWarning.Visible = true
- GUI.Main.Visible = false
- end
- end
- local function setAllFramesInvisible()
- ParticleButtonFrame.Visible = false
- SoundButtonFrame.Visible = false
- PartButtonFrame.Visible = false
- end
- local function toggleFrameVisibility(buttonFrame)
- if buttonFrame.Visible then
- setAllFramesInvisible()
- else
- setAllFramesInvisible()
- buttonFrame.Visible = true
- end
- end
- --------------------------------------------------------------------------------------
- --[[ Connections ]]
- --------------------------------------------------------------------------------------
- ParticleButton.MouseButton1Click:Connect(function()
- toggleFrameVisibility(ParticleButtonFrame)
- end)
- SoundButton.MouseButton1Click:Connect(function()
- toggleFrameVisibility(SoundButtonFrame)
- end)
- PartButton.MouseButton1Click:Connect(function()
- toggleFrameVisibility(PartButtonFrame)
- end)
- local index = nil
- local lastindex = nil
- local burger = nil
- Slider.Changed:Connect(function(changedValue)
- if #t > 0 then
- index = math.round(#t - (#t - (changedValue*#t)))
- if index then
- print("Closest value found at index: " .. index)
- SelectedKeyframeTextbox.Text = "Selected Keyframe: [ ".. index .." ]"
- --if track and #t > 0 then
- -- track.TimePosition = t[index]
- --end
- local timePerFrame = 0.01
- if lastindex then
- if lastindex > index then
- timePerFrame = -(index - lastindex)
- else
- timePerFrame = index - lastindex
- end
- end
- if stopAnim then
- track:Stop(0)
- animator:StepAnimations(0)
- lastindex = index
- end
- animator:StepAnimations(timePerFrame)
- lastindex = index
- else
- print("No close value found.")
- end
- end
- end)
- Selection.SelectionChanged:Connect(checkSelectionAndShowGui)
- button.Click:Connect(toggleGui)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement