Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local toolbar = plugin:CreateToolbar("Face Selector")
- local button = toolbar:CreateButton("Show Selected Face", "Shows selected face of models and baseparts. Can also display directional vectors.", "rbxassetid://5602410390")
- local mouse = plugin:GetMouse()
- local runService = game:GetService("RunService")
- local selection = game:GetService("Selection")
- local coreGUI = game:GetService("CoreGui")
- if coreGUI:FindFirstChild("Tukars|FaceSelectingGUI") then coreGUI["Tukars|FaceSelectingGUI"]:Destroy() end
- local gui = script.Parent["Tukars|FaceSelectingGUI"]:Clone()
- gui.Parent = coreGUI
- local enabled = false
- local tweening = false
- local connections = {}
- if coreGUI:FindFirstChild("Tukars|Visuals") then coreGUI["Tukars|Visuals"]:Destroy() end
- local visuals = script.Parent["Tukars|Visuals"]:Clone()
- visuals.Parent = coreGUI
- local faces = visuals.Face
- local direction = visuals.Direction
- local binded = false
- local selectedFace = nil
- local currentlySelected = nil
- local active = true
- local showDirectionalVectors = false
- local inBounds = false
- local gColor = Enum.StudioStyleGuideColor
- local gModifier = Enum.StudioStyleGuideModifier
- local function getUIColor(guideColor, guideModifier)
- return settings().Studio.Theme:GetColor(gColor[guideColor], gModifier[guideModifier])
- end
- local function updatePluginTheme()
- gui.Main.BackgroundColor3 = getUIColor("MainBackground", "Default")
- gui.Main.Face.TextColor3 = getUIColor("MainText", "Default")
- for _, ui in pairs(gui.Main.FaceSelector:GetChildren()) do
- if ui ~= gui.Main.FaceSelector.UIListLayout then
- local typ = ui.Name == selectedFace and "Selected" or "Default"
- ui.BackgroundColor3 = getUIColor("RibbonButton", typ)
- ui.TextColor3 = getUIColor("MainText", typ)
- ui.BorderColor3 = getUIColor("Border", "Default")
- end
- end
- for _, ui in pairs(gui.Main.CheckBoxes:GetDescendants()) do
- if ui.Name == "CheckBox" then
- ui.BackgroundColor3 = getUIColor("RibbonButton", "Selected")
- elseif ui.Name == "Display" then
- ui.BackgroundColor3 = getUIColor("Button", "Selected")
- elseif ui:IsA("TextLabel") then
- ui.TextColor3 = getUIColor("MainText", "Default")
- end
- end
- end
- updatePluginTheme()
- local v3 = Vector3.new
- local function withinBounds(obj)
- local tx,ty = obj.AbsolutePosition.X, obj.AbsolutePosition.Y
- local bx,by = tx + obj.AbsoluteSize.X, ty + obj.AbsoluteSize.Y
- return (mouse.X >= tx and mouse.X <= bx and mouse.Y >= ty and mouse.Y <= by)
- end
- local function update()
- for _, ui in pairs(gui.Main.FaceSelector:GetChildren()) do
- if ui ~= gui.Main.FaceSelector.UIListLayout then
- if withinBounds(ui) and ui.Name ~= selectedFace then
- ui.BackgroundColor3 = getUIColor("RibbonButton", "Hover")
- ui.TextColor3 = getUIColor("MainText", "Hover")
- elseif ui.Name ~= selectedFace then
- ui.BackgroundColor3 = getUIColor("RibbonButton", "Default")
- ui.TextColor3 = getUIColor("MainText", "Default")
- end
- end
- end
- if withinBounds(gui.ActivationZone) then
- if not inBounds then
- gui.Main:TweenPosition(UDim2.new(0.5, 0, 0, 6), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.15, true)
- inBounds = true
- end
- else
- if inBounds then
- gui.Main:TweenPosition(UDim2.new(0.5, 0, 0, -175), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.15, true)
- inBounds = false
- end
- end
- end
- local faceOffsets = {
- Back = v3(0,0,1),
- Bottom = v3(0,-1,0),
- Front = v3(0,0,-1),
- Left = v3(-1,0,0),
- Right = v3(1,0,0),
- Top = v3(0,1,0),
- }
- local function getObjSize()
- local objCFrame, objSize
- if currentlySelected:IsA("Model") then
- return currentlySelected:GetBoundingBox()
- elseif currentlySelected:IsA("BasePart") then
- return currentlySelected.CFrame, currentlySelected.Size
- end
- end
- local function updateLookVectorText(upda)
- if upda then
- for _,t in pairs(gui.Main.CheckBoxes.Vectors:GetChildren()) do
- local vector = currentlySelected.CFrame[t.Name]
- for _,d in pairs(t:GetChildren()) do
- if d.Name ~= "Text" then
- d.Text = string.sub(tostring(vector[d.Name]), 0, 6)
- end
- end
- end
- else
- for _,t in pairs(gui.Main.CheckBoxes.Vectors:GetChildren()) do
- for _,d in pairs(t:GetChildren()) do
- if d.Name ~= "Text" then
- d.Text = ""
- end
- end
- end
- end
- end
- local function updateObject()
- local targfaces = {"Top", "Bottom", "Left", "Right"}
- if currentlySelected then
- local objCFrame, objSize = getObjSize()
- if selectedFace then
- local index = 1
- for i,v in pairs(faceOffsets) do
- if v:Cross(faceOffsets[selectedFace]) ~= v3() then
- local targetAdornee = faces[targfaces[index]]
- targetAdornee.Adornee = currentlySelected
- local targOffset = faceOffsets[selectedFace] + v
- targetAdornee.SizeRelativeOffset = targOffset
- local targetSize = v:Cross(faceOffsets[selectedFace])
- local xsize = targetSize.X ~= 0 and objSize.X + 0.15 or 0.15
- local ysize = targetSize.Y ~= 0 and objSize.Y + 0.15 or 0.15
- local zsize = targetSize.Z ~= 0 and objSize.Z + 0.15 or 0.15
- targetAdornee.Size = v3(xsize, ysize, zsize)
- index = index + 1
- end
- end
- else
- for i,v in pairs(targfaces) do
- local targetAdornee = faces[v]
- targetAdornee.Adornee = nil
- end
- end
- updateLookVectorText(true)
- local targetSize = math.max(objSize.X, objSize.Y, objSize.Z)
- local directions = visuals.Direction
- for i,v in pairs(visuals.Direction:GetChildren()) do
- v.Adornee = currentlySelected
- end
- direction.lookVector.Size = v3(0.1, 0.1, targetSize)
- direction.lookVector.SizeRelativeOffset = v3(0, 0, -targetSize/objSize.Z)
- direction.rightVector.Size = v3(targetSize, 0.1, 0.1)
- direction.rightVector.SizeRelativeOffset = v3(targetSize/objSize.X, 0, 0)
- direction.upVector.Size = v3(0.1, targetSize, 0.1)
- direction.upVector.SizeRelativeOffset = v3(0, targetSize/objSize.Y, 0)
- else
- for i,v in pairs(targfaces) do
- faces[v].Adornee = nil
- end
- for i,v in pairs(visuals.Direction:GetChildren()) do
- v.Adornee = nil
- end
- updateLookVectorText(false)
- end
- end
- local selectedObjectEvent
- local function connectSelectionChanged()
- for i,v in pairs(selection:Get()) do
- if v:IsA("BasePart") or v:IsA("Model") then
- currentlySelected = v
- updateObject()
- selectedObjectEvent = currentlySelected.Changed:Connect(updateObject)
- break
- end
- end
- table.insert(connections, selection.SelectionChanged:Connect(function()
- currentlySelected = nil
- for i,v in pairs(selection:Get()) do
- if v:IsA("BasePart") or v:IsA("Model") then
- currentlySelected = v
- updateObject()
- selectedObjectEvent = currentlySelected.Changed:Connect(updateObject)
- break
- end
- end
- if not currentlySelected then
- if selectedObjectEvent then
- selectedObjectEvent:Disconnect()
- selectedObjectEvent = nil
- end
- updateObject()
- end
- end))
- end
- local function startPlugin()
- plugin:Activate(true)
- gui.Enabled = true
- binded = true
- runService:BindToRenderStep("FaceSelector by Tukars", Enum.RenderPriority.Last.Value, update)
- table.insert(connections, settings().Studio.ThemeChanged:Connect(updatePluginTheme))
- tweening = true
- connectSelectionChanged()
- for _, ui in pairs(gui.Main.FaceSelector:GetChildren()) do
- if ui ~= gui.Main.FaceSelector.UIListLayout then
- table.insert(connections, ui.MouseButton1Click:Connect(function()
- if gui.Main.FaceSelector:FindFirstChild("selectedFace") then
- gui.Main.FaceSelector[selectedFace].BackgroundColor3 = getUIColor("RibbonButton", "Default")
- gui.Main.FaceSelector[selectedFace].TextColor3 = getUIColor("MainText", "Default")
- end
- if ui.Name ~= selectedFace then
- selectedFace = ui.Name
- ui.BackgroundColor3 = getUIColor("RibbonButton", "Selected")
- ui.TextColor3 = getUIColor("MainText", "Selected")
- else
- selectedFace = nil
- end
- updateObject()
- end))
- end
- end
- table.insert(connections, gui.Main.CheckBoxes.ActiveGui.CheckBox.MouseButton1Click:Connect(function()
- active = not active
- local transparency = active and 0.5 or 1
- gui.Main.CheckBoxes.ActiveGui.CheckBox.Display.Transparency = active and 0 or 1
- for _,ad in pairs(visuals.Face:GetChildren()) do
- ad.Transparency = transparency
- end
- for _,ad in pairs(visuals.Direction:GetChildren()) do
- ad.Transparency = (active and showDirectionalVectors) and 0.5 or 1
- end
- end))
- table.insert(connections, gui.Main.CheckBoxes.ShowVectors.CheckBox.MouseButton1Click:Connect(function()
- showDirectionalVectors = not showDirectionalVectors
- gui.Main.CheckBoxes.ShowVectors.CheckBox.Display.Transparency = showDirectionalVectors and 0 or 1
- local transparency = (showDirectionalVectors and active) and 0.5 or 1
- for _,ad in pairs(visuals.Direction:GetChildren()) do
- ad.Transparency = transparency
- end
- --set all vector to transparency val, if active 1
- end))
- gui.Main:TweenPosition(UDim2.new(0.5, 0, 0, 6), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 0.15, true)
- wait(0.25)
- enabled = true
- tweening = false
- end
- local function stopPlugin()
- for _,connection in pairs(connections) do
- connection:Disconnect()
- end
- connections = {}
- currentlySelected = nil
- updateObject()
- tweening = true
- gui.Main:TweenPosition(UDim2.new(0.5, 0, 0, -175), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 0.15, true)
- wait(0.25)
- enabled = false
- tweening = false
- if binded then
- runService:UnbindFromRenderStep("FaceSelector by Tukars")
- end
- binded = false
- gui.Enabled = false
- plugin:Deactivate()
- end
- button.Click:connect(function()
- if not tweening then
- if enabled then
- stopPlugin()
- else
- startPlugin()
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement