--[[ 测试版 V2.9:UI 构造完全统一版 - 修复:Jump 按钮改用与 WASD 相同的 Frame+TextLabel 构造 - 保持:所有按钮字体比例 0.28 - 保持:WASD 紧凑间距 (0.88),ShiftLock 功能 - 位置:Jump 靠右 (0.88),Shift 位于右下 ]] local VirtualInputManager = game:GetService("VirtualInputManager") local Players = game:GetService("Players") local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local player = Players.LocalPlayer local pGui = player:WaitForChild("PlayerGui") local camera = workspace.CurrentCamera -- 1. 屏蔽原生拉杆 RunService.Stepped:Connect(function() local touchGui = pGui:FindFirstChild("TouchGui") if touchGui then touchGui.Enabled = false local frame = touchGui:FindFirstChild("TouchControlFrame") if frame then frame.Position = UDim2.new(2, 0, 2, 0) end end end) -- 2. 清理旧 UI if pGui:FindFirstChild("Beta_V2_9") then pGui.Beta_V2_9:Destroy() end -- 3. 创建容器 local ScreenGui = Instance.new("ScreenGui") ScreenGui.Name = "Beta_V2_9" ScreenGui.Parent = pGui ScreenGui.ResetOnSpawn = false ScreenGui.IgnoreGuiInset = true -- 4. 参数设定 local screen = ScreenGui.AbsoluteSize local btnSize = math.clamp(screen.X * 0.09, 70, 100) local gap = btnSize * 0.88 local startX, startY = 0.15, 0.55 -- 5. 统一按钮创建函数 (核心:Frame + TextLabel + Stroke) local function createStyledButton(name, text, pos, size) local frame = Instance.new("Frame") frame.Name = name frame.Size = size frame.Position = pos frame.BackgroundColor3 = Color3.fromRGB(30, 30, 30) frame.BackgroundTransparency = 0.4 frame.ZIndex = 10 frame.Parent = ScreenGui local corner = Instance.new("UICorner") corner.CornerRadius = UDim.new(0.3, 0) corner.Parent = frame local txt = Instance.new("TextLabel") txt.Size = UDim2.new(1, 0, 1, 0) txt.Text = text txt.TextColor3 = Color3.new(1, 1, 1) txt.BackgroundTransparency = 1 txt.Font = Enum.Font.GothamBold txt.TextSize = size.Y.Offset * 0.28 -- 统一比例 txt.Parent = frame local stroke = Instance.new("UIStroke") stroke.Color = Color3.new(1, 1, 1) stroke.Thickness = 2.5 stroke.Transparency = 0.6 stroke.Parent = frame return frame end -- 6. 创建 WASD (视觉部分) local KeysUI = {} KeysUI.W = createStyledButton("W_Key", "W", UDim2.new(startX, 0, startY, -gap), UDim2.new(0, btnSize, 0, btnSize)) KeysUI.S = createStyledButton("S_Key", "S", UDim2.new(startX, 0, startY, gap), UDim2.new(0, btnSize, 0, btnSize)) KeysUI.A = createStyledButton("A_Key", "A", UDim2.new(startX, -gap, startY, 0), UDim2.new(0, btnSize, 0, btnSize)) KeysUI.D = createStyledButton("D_Key", "D", UDim2.new(startX, gap, startY, 0), UDim2.new(0, btnSize, 0, btnSize)) -- 7. WASD 拉杆感应逻辑层 local TouchArea = Instance.new("TextButton") TouchArea.Name = "TouchSenseLayer" local areaSize = gap * 3.0 TouchArea.Size = UDim2.new(0, areaSize, 0, areaSize) TouchArea.Position = UDim2.new(startX, -areaSize/2 + btnSize/2, startY, -areaSize/2 + btnSize/2) TouchArea.BackgroundTransparency = 1 TouchArea.Text = "" TouchArea.ZIndex = 15 TouchArea.Parent = ScreenGui local ActiveKeys = {W = false, A = false, S = false, D = false} local function updateInput(inputPos) local center = Vector2.new(TouchArea.AbsolutePosition.X + TouchArea.AbsoluteSize.X/2, TouchArea.AbsolutePosition.Y + TouchArea.AbsoluteSize.Y/2) local delta = inputPos - center local threshold = gap * 0.32 local newStates = {W = delta.Y < -threshold, S = delta.Y > threshold, A = delta.X < -threshold, D = delta.X > threshold} for k, isDown in pairs(newStates) do if ActiveKeys[k] ~= isDown then ActiveKeys[k] = isDown VirtualInputManager:SendKeyEvent(isDown, Enum.KeyCode[k], false, game) KeysUI[k].BackgroundColor3 = isDown and Color3.new(1, 1, 1) or Color3.fromRGB(30, 30, 30) KeysUI[k].TextLabel.TextColor3 = isDown and Color3.new(0, 0, 0) or Color3.new(1, 1, 1) end end end TouchArea.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.Touch then updateInput(Vector2.new(input.Position.X, input.Position.Y)) end end) TouchArea.InputChanged:Connect(function(input) if input.UserInputType == Enum.UserInputType.Touch then updateInput(Vector2.new(input.Position.X, input.Position.Y)) end end) TouchArea.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.Touch then for k, v in pairs(ActiveKeys) do if v then ActiveKeys[k] = false VirtualInputManager:SendKeyEvent(false, Enum.KeyCode[k], false, game) KeysUI[k].BackgroundColor3 = Color3.fromRGB(30, 30, 30) KeysUI[k].TextLabel.TextColor3 = Color3.new(1, 1, 1) end end end end) -- 8. 【Jump 按钮】:构造完全模仿 WASD local jumpSize = btnSize * 1.5 local JumpUI = createStyledButton("Jump_Visual", "JUMP", UDim2.new(0.88, -jumpSize/2, startY, 0), UDim2.new(0, jumpSize, 0, jumpSize)) local JumpHitbox = Instance.new("TextButton") JumpHitbox.Name = "JumpHitbox" JumpHitbox.Size = UDim2.new(1, 0, 1, 0) JumpHitbox.BackgroundTransparency = 1 JumpHitbox.Text = "" JumpHitbox.ZIndex = 20 JumpHitbox.Parent = JumpUI JumpHitbox.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then JumpUI.BackgroundColor3 = Color3.new(1, 1, 1) JumpUI.TextLabel.TextColor3 = Color3.new(0, 0, 0) VirtualInputManager:SendKeyEvent(true, Enum.KeyCode.Space, false, game) end end) JumpHitbox.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then JumpUI.BackgroundColor3 = Color3.fromRGB(30, 30, 30) JumpUI.TextLabel.TextColor3 = Color3.new(1, 1, 1) VirtualInputManager:SendKeyEvent(false, Enum.KeyCode.Space, false, game) end end) -- 9. ShiftLock 按钮 (右下角) local shiftSize = btnSize * 1.1 local isShiftLock = false local ShiftUI = createStyledButton("Shift_Visual", "LOCK: OFF", UDim2.new(0.88, -shiftSize/2, startY + jumpSize*0.8, 0), UDim2.new(0, shiftSize, 0, shiftSize)) ShiftUI.BackgroundColor3 = Color3.fromRGB(150, 0, 0) ShiftUI.TextLabel.TextSize = shiftSize * 0.2 local ShiftHitbox = Instance.new("TextButton") ShiftHitbox.Size = UDim2.new(1,0,1,0) ShiftHitbox.BackgroundTransparency = 1 ShiftHitbox.Text = "" ShiftHitbox.ZIndex = 20 ShiftHitbox.Parent = ShiftUI ShiftHitbox.MouseButton1Click:Connect(function() isShiftLock = not isShiftLock if isShiftLock then ShiftUI.TextLabel.Text = "LOCK: ON" ShiftUI.BackgroundColor3 = Color3.fromRGB(0, 150, 0) else ShiftUI.TextLabel.Text = "LOCK: OFF" ShiftUI.BackgroundColor3 = Color3.fromRGB(150, 0, 0) end end) RunService.RenderStepped:Connect(function() if isShiftLock then UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then local lookVector = camera.CFrame.LookVector player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position, player.Character.HumanoidRootPart.Position + Vector3.new(lookVector.X, 0, lookVector.Z)) end end end) print("测试版 V2.9:Jump 按钮 UI 风格已与 WASD 完全统一。")