自定义设置 TestSetting.h
#pragma once
#include "CoreMinimal.h"
#include "TestSetting.generated.h"
UCLASS(config = TestSetting)
class TESTPLUGIN_API UTestSetting : public UObject {
GENERATED_BODY()
public:
UPromethSetting()
: MeshReaderLog(false)
{}
UPROPERTY(config, EditAnywhere, Category = Debug, meta = (DisplayName = "Show MeshReaderLog", ToolTip = "MeshReaderLog"))
bool MeshReaderLog;
};
注册设置:一般在插件的StartupModule()注册
#include "TestPlugin.h"
#include "Core.h"
#include "Modules/ModuleManager.h"
#include "Interfaces/IPluginManager.h"
#include "TestSetting.h"
#if WITH_EDITOR
#include "ISettingsModule.h"
#endif
void FTestPluginModule::StartupModule() {
#if WITH_EDITOR
// 注册自定义设置
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings")) {
SettingsModule->RegisterSettings(
"Project",
"Plugins",
"TestPlugin",
LOCTEXT("TestPlugin_Name", "TestPlugin"),
LOCTEXT("TestPlugin_Description", "TestPlugin"),
GetMutableDefault<UTestSetting >()
);
}
#endif
}
读取自定义设置的内容
UTestSetting * Settings = GetMutableDefault<UTestSetting >();
if (Settings) {
bool bOutputLog = Settings->MeshReaderLog;
}
取消注册:一般在插件的StopModule()
void FTestPluginModule::ShutdownModule()
{
#if WITH_EDITOR
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings")) {
SettingsModule->UnregisterSettings("Project", "Plugins", "TestPlugin");
}
#endif
}