概要
方法
将当前振动值设置为指定的 UserInputType 和 Enum.VibrationMotor 。
返回 true 如果指定的电机可用于与指定的 Enum.UserInputType 一起使用。
返回 true 如果指定的 Enum.UserInputType 支持震动反馈。
- SetMotor(inputType : Enum.UserInputType,vibrationMotor : Enum.VibrationMotor,vibrationValues : Tuple):()
设置指定的 UserInputType 和 Enum.VibrationMotor 的振动强度。
属性
方法
GetMotor
将当前振动值设置为指定的 UserInputType 和 Enum.VibrationMotor 。如果 SetMotor() 先没有调用,将不会返回任何东西。
参数
指定的 Enum.UserInputType 。
指定的 Enum.VibrationMotor 。
返回
当前振动值设置为指定的 Enum.UserInputType 和 Enum.VibrationMotor 或 nil 如果 SetMotor() 尚未调用前。
IsMotorSupported
返回 true 如果指定的电机可用于与指定的 Enum.UserInputType 一起使用。
参数
正在检查特定的 Enum.UserInputType 以获得 Enum.VibrationMotor 协助持。
指定的 Enum.VibrationMotor 检查是否支持指定的 Enum.UserInputType 。
返回
如果指定的发动机可以与指定的 一起使用,则 否则。
IsVibrationSupported
返回 true 如果指定的 Enum.UserInputType 支持震动反馈。
参数
指定的 Enum.UserInputType 检查是否支持触觉反馈。
返回
如果指定的 true 支持触觉反馈,Boolean 的值为 Enum.UserInputType。
SetMotor
设置指定的 inputType 和 vibrationMotor 的振动强度。请注意,几乎所有使用案例都指定 Enum.UserInputType.Gamepad1 为 inputType ,这在内部映射到设备的相应硬件。
参数
指定的 Enum.UserInputType 。
指定的 Enum.VibrationMotor 。
电机应振动的程度。仅使用 tuple 中的第一个值,该值应为数字。
返回
代码示例
This example makes the small motor vibrate depending on how much pressure is applied to the left trigger, and the large motor vibrate depending on how much pressure is applied to the right trigger.
local UserInputService = game:GetService("UserInputService")
local HapticService = game:GetService("HapticService")
local cachedInputs = {}
local keyToVibration = {
[Enum.KeyCode.ButtonL2] = Enum.VibrationMotor.Small,
[Enum.KeyCode.ButtonR2] = Enum.VibrationMotor.Large,
}
local function onInputChanged(property)
if property == "Position" then
HapticService:SetMotor(inputType, vibrationMotor, input.Position.Z)
end
end
local function onInputBegan(input)
if not cachedInputs[input] then
local inputType = input.UserInputType
if inputType.Name:find("Gamepad") then
local vibrationMotor = keyToVibration[input.KeyCode]
if vibrationMotor then
-- Watch this input manually to accurately update the vibration motor
cachedInputs[input] = input.Changed:Connect(onInputChanged)
end
end
end
end
UserInputService.InputBegan:Connect(onInputBegan)