-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from g0415shenw/main
提交基础版本
- Loading branch information
Showing
11 changed files
with
218 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"FileVersion": 3, | ||
"Version": 1, | ||
"VersionName": "1.0", | ||
"FriendlyName": "InConfig", | ||
"Description": "", | ||
"Category": "Other", | ||
"CreatedBy": "", | ||
"CreatedByURL": "", | ||
"DocsURL": "", | ||
"MarketplaceURL": "", | ||
"SupportURL": "", | ||
"CanContainContent": true, | ||
"IsBetaVersion": false, | ||
"IsExperimentalVersion": false, | ||
"Installed": false, | ||
"Modules": [ | ||
{ | ||
"Name": "InConfig", | ||
"Type": "Runtime", | ||
"LoadingPhase": "PreLoadingScreen" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
# InConfig | ||
# InConfig | ||
本插件旨在简化配置文件的读写。通过本插件进行读写配置文件,可以适用于编辑器和运行时模型。 | ||
|
||
# 使用方法 | ||
## 设置配置文件 | ||
目前支持字符串和整数的配置文件读写。通过调用蓝图方式,可以实现自动生成配置文件,并且生成的配置文件在打包的时候,会自动被拷贝到安装程序中。 | ||
![SetConfig](./Images/SetConfig.jpg) | ||
生成的配置文件如下: | ||
![ConfigFile](./Images/ConfigFile.jpg) | ||
|
||
## 读取配置文件 | ||
目前仅仅支持字符串和整数的配置文件读写。 | ||
![GetConfig](./Images/GetConfig.jpg) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Some copyright should be here... | ||
|
||
using UnrealBuildTool; | ||
|
||
public class InConfig : ModuleRules | ||
{ | ||
public InConfig(ReadOnlyTargetRules Target) : base(Target) | ||
{ | ||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; | ||
|
||
PublicIncludePaths.AddRange( | ||
new string[] { | ||
// ... add public include paths required here ... | ||
} | ||
); | ||
|
||
|
||
PrivateIncludePaths.AddRange( | ||
new string[] { | ||
// ... add other private include paths required here ... | ||
} | ||
); | ||
|
||
|
||
PublicDependencyModuleNames.AddRange( | ||
new string[] | ||
{ | ||
"Core", | ||
// ... add other public dependencies that you statically link with here ... | ||
} | ||
); | ||
|
||
|
||
PrivateDependencyModuleNames.AddRange( | ||
new string[] | ||
{ | ||
"CoreUObject", | ||
"Engine", | ||
"Slate", | ||
"SlateCore", | ||
// ... add private dependencies that you statically link with here ... | ||
} | ||
); | ||
|
||
|
||
DynamicallyLoadedModuleNames.AddRange( | ||
new string[] | ||
{ | ||
// ... add any modules that your module loads dynamically here ... | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright Epic Games, Inc. All Rights Reserved. | ||
|
||
#include "InConfig.h" | ||
|
||
#define LOCTEXT_NAMESPACE "FInConfigModule" | ||
|
||
void FInConfigModule::StartupModule() | ||
{ | ||
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module | ||
|
||
} | ||
|
||
void FInConfigModule::ShutdownModule() | ||
{ | ||
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, | ||
// we call this function before unloading the module. | ||
|
||
} | ||
|
||
#undef LOCTEXT_NAMESPACE | ||
|
||
IMPLEMENT_MODULE(FInConfigModule, InConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright Epic Games, Inc. All Rights Reserved. | ||
|
||
#include "InConfigBPLibrary.h" | ||
#include "InConfig.h" | ||
#include "Misc/Paths.h" | ||
#include "Misc/App.h" | ||
#include "HAL/FileManager.h" | ||
|
||
FString UInConfigBPLibrary::GetConfigPath() | ||
{ | ||
FString ProjectPath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir()); | ||
FString ProjectName = FApp::GetProjectName(); | ||
FString ConfigPath = ProjectPath + "Config/" + ProjectName + ".ini"; | ||
return ConfigPath; | ||
} | ||
void UInConfigBPLibrary::CheckAndCreateConfig() | ||
{ | ||
FString ProjectPath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir()); | ||
FString ProjectName = FApp::GetProjectName(); | ||
FString ConfigPath = GetConfigPath(); | ||
FString DefaultGamePath = ProjectPath + "Config/" + "DefaultGame.ini"; | ||
|
||
if (true == FPaths::FileExists(ConfigPath)) | ||
{ | ||
return; | ||
} | ||
auto file = IFileManager::Get().CreateFileWriter(*ConfigPath); | ||
if (nullptr == file) | ||
{ | ||
return; | ||
} | ||
file->Close(); | ||
|
||
FString fileName = ProjectName + "/" + "Config/" + ProjectName + ".ini"; | ||
GConfig->SetString(TEXT("Staging"), TEXT("+WhitelistConfigFiles"), *fileName, *DefaultGamePath); | ||
} | ||
|
||
bool UInConfigBPLibrary::GetConfigString(FString Section, FString Key, FString& value) | ||
{ | ||
FString ConfigPath = GetConfigPath(); | ||
return GConfig->GetString(*Section, *Key, value, ConfigPath); | ||
} | ||
|
||
void UInConfigBPLibrary::SetConfigString(FString Section, FString Key, FString value) | ||
{ | ||
CheckAndCreateConfig(); | ||
FString ConfigPath = GetConfigPath(); | ||
GConfig->SetString(*Section, *Key, *value, ConfigPath); | ||
} | ||
|
||
bool UInConfigBPLibrary::GetConfigInt(FString Section, FString Key, int32& value) | ||
{ | ||
FString ConfigPath = GetConfigPath(); | ||
return GConfig->GetInt(*Section, *Key, value, ConfigPath); | ||
} | ||
|
||
|
||
void UInConfigBPLibrary::SetConfigInt(FString Section, FString Key, int32 value) | ||
{ | ||
CheckAndCreateConfig(); | ||
FString ConfigPath = GetConfigPath(); | ||
GConfig->SetInt(*Section, *Key, value, ConfigPath); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright Epic Games, Inc. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include "Modules/ModuleManager.h" | ||
|
||
class FInConfigModule : public IModuleInterface | ||
{ | ||
public: | ||
|
||
/** IModuleInterface implementation */ | ||
virtual void StartupModule() override; | ||
virtual void ShutdownModule() override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright Epic Games, Inc. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include "Kismet/BlueprintFunctionLibrary.h" | ||
#include "InConfigBPLibrary.generated.h" | ||
|
||
|
||
UCLASS() | ||
class UInConfigBPLibrary : public UBlueprintFunctionLibrary | ||
{ | ||
GENERATED_BODY() | ||
|
||
private: | ||
static void CheckAndCreateConfig(); | ||
static FString GetConfigPath(); | ||
public: | ||
UFUNCTION(BlueprintCallable, Category = "InConfig") | ||
static bool GetConfigString(FString Section, FString Key, FString& value); | ||
|
||
UFUNCTION(BlueprintCallable, Category = "InConfig") | ||
static void SetConfigString(FString Section, FString Key, FString value); | ||
|
||
UFUNCTION(BlueprintCallable, Category = "InConfig") | ||
static bool GetConfigInt(FString Section, FString Key, int32& value); | ||
|
||
UFUNCTION(BlueprintCallable, Category = "InConfig") | ||
static void SetConfigInt(FString Section, FString Key, int32 value); | ||
}; |