用户设置是一个单例对象,用于存储基本用户设置,这些设置在所有游戏中持续存在。目前,它只存储 UserGameSettings 对象。
您可以通过 UserSettings() 函数检索到这个对象的引用,该函数将它返回。
代码示例
A basic sample of how the IsUserFeatureEnabled function is used by Roblox to control certain features.
if UserSettings():IsUserFeatureEnabled("UserNoCameraClickToMove") then
print("'ClickToMove' should no longer be loaded from the CameraScript!")
else
print("'ClickToMove' is still loaded from the CameraScript!")
end
A LocalScript that demonstrates how you can detect whether a game is in full screen or not.
local gameSettings = UserSettings().GameSettings
local function checkFullScreenMode()
local inFullscreen = gameSettings:InFullScreen()
if inFullscreen then
print("Full Screen mode enabled!")
else
print("Full Screen mode disabled!")
end
end
checkFullScreenMode()
gameSettings.FullscreenChanged:Connect(checkFullScreenMode)
A basic example that shows how you can listen to changes in the user's settings. With this code pasted into a LocalScript running in the StarterPlayerScripts, you can change settings in Roblox's game menu, and see their values appear in the output as detected changes.
local gameSettings = UserSettings().GameSettings
local function onGameSettingChanged(nameOfSetting)
-- Fetch the value of this setting through a pcall to make sure we can retrieve it.
-- Sometimes the event fires with properties that LocalScripts can't access.
local canGetSetting, setting = pcall(function()
return gameSettings[nameOfSetting]
end)
if canGetSetting then
print("Your " .. nameOfSetting .. " has changed to: " .. tostring(setting))
end
end
gameSettings.Changed:Connect(onGameSettingChanged)
概要
方法
如果指定的用户功能启用,返回真值。如果用户功能不存在,将发生错误。
清除用户设置的保存状态,恢复其默认值。
返回指定类别的服务,如果已创建,则返回无效名称的错误。
返回服务与请求的类名称,如果不存在,创建它。
属性
方法
IsUserFeatureEnabled
如果指定的用户功能启用,返回真值。如果用户功能不存在,将发生错误。
这个函数检查一个列表的 FFlags,其名称以“用户”开头。该函数用于由 Roblox 创建的脚本使用,功能与 GlobalSettings:GetFFlag() 相似。
参数
返回
代码示例
A basic sample of how the IsUserFeatureEnabled function is used by Roblox to control certain features.
if UserSettings():IsUserFeatureEnabled("UserNoCameraClickToMove") then
print("'ClickToMove' should no longer be loaded from the CameraScript!")
else
print("'ClickToMove' is still loaded from the CameraScript!")
end