[UE4]C++代码读写配置文件(*.ini)

版权声明:本文为博主原创文章,转载请注明来源:http://blog.csdn.net/wag2765 https://blog.csdn.net/wag2765/article/details/84766365

读取

//in your player controller class
void AVictoryController::VictoryConfigGetTests()
{
	//Basic Syntax
	/*
	bool GetString( 
		const TCHAR* Section, 
		const TCHAR* Key, 
		FString& Value, 
		const FString& Filename 
	);
	*/
 
	if(!GConfig) return;
	//~~
 
	//Retrieve Default Game Type
	FString ValueReceived;
	GConfig->GetString(
		TEXT("/Script/Engine.WorldInfo"),
		TEXT("GlobalDefaultGameType"),
		ValueReceived,
		GGameIni
	);
 
	ClientMessage("GlobalDefaultGameType");
	ClientMessage(ValueReceived);
 
        //Retrieve Max Objects not considered by GC
	int32 IntValueReceived = 0;
	GConfig->GetInt(
		TEXT("Core.System"),
		TEXT("MaxObjectsNotConsideredByGC"),
		IntValueReceived,
		GEngineIni
	);
 
	ClientMessage("MaxObjectsNotConsideredByGC");
	ClientMessage(FString::FromInt(IntValueReceived));
 
         //Retrieve Near Clip Plane (how close things can get to camera)
	float floatValueReceived = 0;
	GConfig->GetFloat(
		TEXT("/Script/Engine.Engine"),
		TEXT("NearClipPlane"),
		floatValueReceived,
		GEngineIni
	);
 
	ClientMessage("NearClipPlane");
	ClientMessage(FString::SanitizeFloat(floatValueReceived));
}

  

写入

//write to existing Game.ini
//the results get stored in YourGameDir\Saved\Config\Windows
void AVictoryController::VictoryConfigSetTests()
{
	if(!GConfig) return;
	//~~
 
	//New Section to Add
	FString VictorySection = "Victory.Core";
 
	//String
	GConfig->SetString (
		*VictorySection,
		TEXT("RootDir"),
		TEXT("E:\UE4\IsAwesome"),
		GGameIni
	);
 
	//FColor
	GConfig->SetColor (
		*VictorySection,
		TEXT("Red"),
		FColor(255,0,0,255),
		GGameIni
	);
 
	//FVector
	GConfig->SetVector (
		*VictorySection,
		TEXT("PlayerStartLocation"),
		FVector(0,0,512),
		GGameIni
	);
 
	//FRotator
	GConfig->SetRotator (
		*VictorySection,
		TEXT("SunRotation"),
		FRotator(-90,0,0),
		GGameIni
	);
 
	//ConfigCacheIni.h
	//void Flush( bool Read, const FString& Filename=TEXT("") );
	GConfig->Flush(false,GGameIni);
}

 

 

Config Files, Read & Write to Config Files

https://wiki.unrealengine.com/Config_Files,_Read_%26_Write_to_Config_Files

 

 

展开阅读全文

没有更多推荐了,返回首页