概要
屬性
方法
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 |
範例程式碼
VR服務
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
參數
範例程式碼
VRService:GetTouchpadMode
local VRService = game:GetService("VRService")
VRService:GetTouchpadMode(Enum.VRTouchpad.Left)GetUserCFrame
參數
返回
範例程式碼
VRService:GetUserCFrame
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:RecenterUserHeadCFrame
local VRService = game:GetService("VRService")
-- 重新置中使用者的頭部 CFrame
VRService:RecenterUserHeadCFrame()參數
返回
()
範例程式碼
VRService:RequestNavigation
local VRService = game:GetService("VRService")
local destination = workspace:FindFirstChild("NavigationDestination")
VRService:RequestNavigation(Enum.UserCFrame.Head, destination.CFrame)SetTouchpadMode
參數
返回
()
範例程式碼
VRService:SetTouchpadMode
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 .. " Touchpad 改變為狀態: " .. 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)