使用者設定是一個單一對象,用於存儲基本使用者設定,這些設定在所有遊戲中持續存在。目前只存儲 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)
概要
方法
如果指定的使用者功能已啟用,則返回真值。如果使用者功能不存在,則會發生錯誤。
清除使用者設定的保存狀態,並恢復其預設值。
如果給定的 className 已創建服務,返回指定的服務,如果名稱無效,錯誤。
返回要求的類別名稱的服務,如果不存在,則創建它。
屬性
方法
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