概要
属性
方法
GetUserCFrame(type: Enum.UserCFrame):CFrame |
RequestNavigation(cframe: CFrame,inputUserCFrame: Enum.UserCFrame):() |
SetTouchpadMode(pad: Enum.VRTouchpad,mode: Enum.VRTouchpadMode):() |
活动
NavigationRequested(cframe: CFrame,inputUserCFrame: Enum.UserCFrame):RBXScriptSignal |
UserCFrameChanged(type: Enum.UserCFrame,value: CFrame):RBXScriptSignal |
UserCFrameEnabled(type: Enum.UserCFrame,enabled: boolean):RBXScriptSignal |
代码示例
虚拟现实服务
local VRService = game:GetService("VRService")
local part = workspace.Part
local handOffset = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
-- 考虑头部缩放
handOffset = handOffset.Rotation + handOffset.Position * workspace.CurrentCamera.HeadScale
part.CFrame = workspace.CurrentCamera.CFrame * handOffsetAPI 参考
属性
GuiInputUserCFrame
代码示例
VRService.GuiInputUserCFrame
local VRService = game:GetService("VRService")
if VRService.VREnabled then
print(VRService.GuiInputUserCFrame.Name)
else
print("没有检测到VR设备!")
endVREnabled
代码示例
虚拟现实头部追踪
local VRService = game:GetService("VRService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local function TrackHead(inputType, value)
if inputType == Enum.UserCFrame.Head then
head.CFrame = value
end
end
if VRService.VREnabled then
-- 设置初始 CFrame
head.CFrame = VRService:GetUserCFrame(Enum.UserCFrame.Head)
-- 跟踪 VR 头戴设备的移动并为角色的头部镜像
VRService.UserCFrameChanged:Connect(TrackHead)
end方法
GetTouchpadMode
参数
代码示例
虚拟现实服务:获取触摸板模式
local VRService = game:GetService("VRService")
-- 获取左侧触摸板的当前模式
VRService:GetTouchpadMode(Enum.VRTouchpad.Left)GetUserCFrame
参数
返回
代码示例
VRService:获取用户坐标系
local Workspace = game:GetService("Workspace")
local VRService = game:GetService("VRService")
local camera = Workspace.CurrentCamera
local part = script.Parent.Part
local handOffset = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
-- 考虑到头部缩放
handOffset = handOffset.Rotation + handOffset.Position * camera.HeadScale
part.CFrame = camera.CFrame * handOffsetGetUserCFrameEnabled
参数
返回
代码示例
VRService:GetUserCFrameEnabled
local VRService = game:GetService("VRService")
local isEnabled = VRService:GetUserCFrameEnabled(Enum.UserCFrame.Head)
if isEnabled then
print("VR 设备已启用!")
else
print("VR 设备已禁用!")
endRecenterUserHeadCFrame
VRService:RecenterUserHeadCFrame():()
返回
()
代码示例
VRService:重新居中用户头部CFrame
local VRService = game:GetService("VRService")
-- 重新居中用户的头部CFrame
VRService:RecenterUserHeadCFrame()参数
返回
()
代码示例
VRService:请求导航
local VRService = game:GetService("VRService")
local destination = workspace:FindFirstChild("NavigationDestination")
VRService:RequestNavigation(Enum.UserCFrame.Head, destination.CFrame)SetTouchpadMode
参数
返回
()
代码示例
VR服务:设置触摸板模式
local VRService = game:GetService("VRService")
-- 设置触摸板模式为触控
VRService:SetTouchpadMode(Enum.VRTouchpad.Left, Enum.VRTouchpadMode.Touch)活动
参数
代码示例
VRService.NavigationRequested
local VRService = game:GetService("VRService")
VRService.NavigationRequested:Connect(function(cframe, inputUserCFrame)
print(inputUserCFrame.Name .. " 以 CFrame 发送请求: " .. cframe)
end)TouchpadModeChanged
参数
代码示例
VRService.TouchpadModeChanged
local VRService = game:GetService("VRService")
VRService.TouchpadModeChanged:Connect(function(pad, mode)
print(pad.Name .. " 触控板状态变更为: " .. mode.Name)
end)UserCFrameChanged
参数
代码示例
VRService.UserCFrameChanged
local VRService = game:GetService("VRService")
VRService.UserCFrameChanged:Connect(function(userCFrameType, cframeValue)
print(userCFrameType.Name .. " 更改了。更新的帧: " .. tostring(cframeValue))
end)UserCFrameEnabled
参数
代码示例
VRService.UserCFrameEnabled
local VRService = game:GetService("VRService")
VRService.UserCFrameEnabled:Connect(function(type, enabled)
if enabled then
print(type.Name .. " 被启用!")
else
print(type.Name .. " 被禁用!")
end
end)