c11.编辑器配置属性|DevelopSettings
大约 1 分钟
方案1 ISettingsModule
- 模块激活/销毁时
void FCommonGameModule::StartupModule()
{
RegisterSettings();
}
void FCommonGameModule::ShutdownModule()
{
if (UObjectInitialized())
{
UnregisterSettings();
}
}
- 利用 FModuleManager拿到设置,并动态注册
void FCommonGameModule::RegisterSettings()
{
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
ISettingsSectionPtr UIManagerSettingsSection = SettingsModule->RegisterSettings("Project", "Game", "UI Polic",
LOCTEXT("UINavigationSettingsName", "UI Policy"),
LOCTEXT("UINavigationSettingsDescription", "Configure the UI policy."),
GetMutableDefault<UGameUIManagerSubsystem>()
);
if (UIManagerSettingsSection.IsValid())
{
UIManagerSettingsSection->OnModified().BindRaw(this, &FCommonGameModule::HandleSettingsSaved);
}
}
}
void FCommonGameModule::UnregisterSettings()
{
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
SettingsModule->UnregisterSettings("Project", "Game", "UIPolicy");
}
}
bool FCommonGameModule::HandleSettingsSaved()
{
GetMutableDefault<UGameUIManagerSubsystem>()->SaveConfig();
return true;
}
方案2 继承 UDeveloperSettings或UDeveloperSettingsBackedByCVars
UCLASS(config=Game, defaultconfig, meta=(DisplayName="Common Loading Screen"))
class UCommonLoadingScreenSettings : public UDeveloperSettingsBackedByCVars
{
GENERATED_BODY()
public:
UCommonLoadingScreenSettings();
public:
UPROPERTY(config, EditAnywhere, Category=Display, meta=(MetaClass="/Script/UMG.UserWidget"))
FSoftClassPath StartUpLoadingScreenWidget;
}
//拿到设置类
const UCommonLoadingScreenSettings* Settings = GetDefault<UCommonLoadingScreenSettings>();
//动态修改
const UCommonLoadingScreenSettings* Settings = GetMutableDefault<UCommonLoadingScreenSettings>();