Engine Class
VRService
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
สรุป
คุณสมบัติ
วิธีการ
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 * handOffsetเอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
GuiInputUserCFrame
ตัวอย่างโค้ด
VRService.GuiInputUserCFrame
local VRService = game:GetService("VRService")
if VRService.VREnabled then
print(VRService.GuiInputUserCFrame.Name)
else
print("ไม่พบอุปกรณ์ VR!")
endVREnabled
ตัวอย่างโค้ด
ติดตามหัว VR
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
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")
-- เรียกใช้ฟังก์ชันเพื่อตั้งตำแหน่งหัว
VRService:RecenterUserHeadCFrame()พารามิเตอร์
ส่งค่ากลับ
()
ตัวอย่างโค้ด
VRService:RequestNavigation
local VRService = game:GetService("VRService")
local destination = workspace:FindFirstChild("NavigationDestination")
VRService:RequestNavigation(Enum.UserCFrame.Head, destination.CFrame)SetTouchpadMode
พารามิเตอร์
ส่งค่ากลับ
()
ตัวอย่างโค้ด
โหมดการสัมผัสของ VRService
local VRService = game:GetService("VRService")
-- ตั้งค่าโหมดสัมผัสของ VRTouchpad.Left เป็น Touch
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)