Lớp công cụ
VRService
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Thuộc Tính
Phương Pháp
GetUserCFrame(type: Enum.UserCFrame):CFrame |
RequestNavigation(cframe: CFrame,inputUserCFrame: Enum.UserCFrame):() |
SetTouchpadMode(pad: Enum.VRTouchpad,mode: Enum.VRTouchpadMode):() |
Sự Kiện
NavigationRequested(cframe: CFrame,inputUserCFrame: Enum.UserCFrame):RBXScriptSignal |
UserCFrameChanged(type: Enum.UserCFrame,value: CFrame):RBXScriptSignal |
UserCFrameEnabled(type: Enum.UserCFrame,enabled: boolean):RBXScriptSignal |
Mẫu mã
Dịch vụ VR
local VRService = game:GetService("VRService")
local part = workspace.Part
local handOffset = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
-- Đối với headscale
handOffset = handOffset.Rotation + handOffset.Position * workspace.CurrentCamera.HeadScale
part.CFrame = workspace.CurrentCamera.CFrame * handOffsetTài Liệu Tham Khảo API
Thuộc Tính
GuiInputUserCFrame
Mẫu mã
VRService.GuiInputUserCFrame
local VRService = game:GetService("VRService")
if VRService.VREnabled then
print(VRService.GuiInputUserCFrame.Name)
else
print("Không phát hiện thiết bị VR!")
endVREnabled
Mẫu mã
Theo dõi đầu 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
-- Đặt CFrame ban đầu
head.CFrame = VRService:GetUserCFrame(Enum.UserCFrame.Head)
-- Theo dõi chuyển động tai nghe VR và phản chiếu cho đầu nhân vật
VRService.UserCFrameChanged:Connect(TrackHead)
endPhương Pháp
GetTouchpadMode
Tham Số
Lợi Nhuận
Mẫu mã
VRService:GetTouchpadMode
local VRService = game:GetService("VRService")
-- Lấy chế độ cảm ứng
VRService:GetTouchpadMode(Enum.VRTouchpad.Left)GetUserCFrame
Tham Số
Lợi Nhuận
Mẫu mã
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)
-- Tính toán cho headscale
handOffset = handOffset.Rotation + handOffset.Position * camera.HeadScale
part.CFrame = camera.CFrame * handOffsetGetUserCFrameEnabled
Tham Số
Lợi Nhuận
Mẫu mã
VRService:GetUserCFrameEnabled
local VRService = game:GetService("VRService")
local isEnabled = VRService:GetUserCFrameEnabled(Enum.UserCFrame.Head)
if isEnabled then
print("Thiết bị VR đã được bật!")
else
print("Thiết bị VR đã bị tắt!")
endRecenterUserHeadCFrame
VRService:RecenterUserHeadCFrame():()
Lợi Nhuận
()
Mẫu mã
VRService:RecenterUserHeadCFrame
local VRService = game:GetService("VRService")
-- Kích hoạt lại CFrame của đầu người dùng
VRService:RecenterUserHeadCFrame()Tham Số
Lợi Nhuận
()
Mẫu mã
Dịch vụ VR: Yêu cầu điều hướng
local VRService = game:GetService("VRService")
local destination = workspace:FindFirstChild("NavigationDestination")
VRService:RequestNavigation(Enum.UserCFrame.Head, destination.CFrame)SetTouchpadMode
Tham Số
Lợi Nhuận
()
Mẫu mã
VRService:ĐặtChếĐộTouchpad
local VRService = game:GetService("VRService")
VRService:SetTouchpadMode(Enum.VRTouchpad.Left, Enum.VRTouchpadMode.Touch)Sự Kiện
Tham Số
Mẫu mã
Dịch vụ VR.NavigationRequested
local VRService = game:GetService("VRService")
VRService.NavigationRequested:Connect(function(cframe, inputUserCFrame)
print(inputUserCFrame.Name .. " đã thực hiện yêu cầu với CFrame: " .. cframe)
end)TouchpadModeChanged
Tham Số
Mẫu mã
VRService.ThayĐổiChếĐộBảngCảmỨng
local VRService = game:GetService("VRService")
VRService.TouchpadModeChanged:Connect(function(pad, mode)
print(pad.Name .. " Bảng Cảm Ứng đã thay đổi sang trạng thái: " .. mode.Name)
end)UserCFrameChanged
Tham Số
Mẫu mã
VRService.UserCFrameChanged
local VRService = game:GetService("VRService")
VRService.UserCFrameChanged:Connect(function(userCFrameType, cframeValue)
print(userCFrameType.Name .. " đã thay đổi. Khung được cập nhật: " .. tostring(cframeValue))
end)UserCFrameEnabled
Tham Số
Mẫu mã
VRService.UserCFrameEnabled
local VRService = game:GetService("VRService")
VRService.UserCFrameEnabled:Connect(function(type, enabled)
if enabled then
print(type.Name .. " đã được kích hoạt!")
else
print(type.Name .. " đã bị vô hiệu hóa!")
end
end)