| @ -0,0 +1,26 @@ | ||||
| using UnrealBuildTool; | ||||
|  | ||||
| public class UnrealSharpUtilities : ModuleRules | ||||
| { | ||||
|     public UnrealSharpUtilities(ReadOnlyTargetRules Target) : base(Target) | ||||
|     { | ||||
|         PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; | ||||
|  | ||||
|         PublicDependencyModuleNames.AddRange( | ||||
|             new string[] | ||||
|             { | ||||
|                 "Core", | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|         PrivateDependencyModuleNames.AddRange( | ||||
|             new string[] | ||||
|             { | ||||
|                 "CoreUObject", | ||||
|                 "Engine", | ||||
|                 "Slate", | ||||
|                 "SlateCore" | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,19 @@ | ||||
| #include "UnrealSharpUtilities.h" | ||||
|  | ||||
| #define LOCTEXT_NAMESPACE "FUnrealSharpUtilitiesModule" | ||||
|  | ||||
| DEFINE_LOG_CATEGORY(LogUnrealSharpUtilities); | ||||
|  | ||||
| void FUnrealSharpUtilitiesModule::StartupModule() | ||||
| { | ||||
|      | ||||
| } | ||||
|  | ||||
| void FUnrealSharpUtilitiesModule::ShutdownModule() | ||||
| { | ||||
|      | ||||
| } | ||||
|  | ||||
| #undef LOCTEXT_NAMESPACE | ||||
|      | ||||
| IMPLEMENT_MODULE(FUnrealSharpUtilitiesModule, UnrealSharpUtilities) | ||||
| @ -0,0 +1,13 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "Modules/ModuleManager.h" | ||||
|  | ||||
| DECLARE_LOG_CATEGORY_EXTERN(LogUnrealSharpUtilities, Log, All); | ||||
|  | ||||
| class FUnrealSharpUtilitiesModule : public IModuleInterface | ||||
| { | ||||
| public: | ||||
|     virtual void StartupModule() override; | ||||
|     virtual void ShutdownModule() override; | ||||
| }; | ||||
| @ -0,0 +1,103 @@ | ||||
| #include "UnrealSharpUtils.h" | ||||
|  | ||||
| #include "UnrealSharpUtilities.h" | ||||
| #include "Logging/StructuredLog.h" | ||||
|  | ||||
| FName FCSUnrealSharpUtils::GetNamespace(const UObject* Object) | ||||
| { | ||||
| 	FName PackageName = GetModuleName(Object); | ||||
| 	return GetNamespace(PackageName); | ||||
| } | ||||
|  | ||||
| FName FCSUnrealSharpUtils::GetNamespace(const FName PackageName) | ||||
| { | ||||
| 	return *FString::Printf(TEXT("%s.%s"), TEXT("UnrealSharp"), *PackageName.ToString()); | ||||
| } | ||||
|  | ||||
| FName FCSUnrealSharpUtils::GetNativeFullName(const UField* Object) | ||||
| { | ||||
| 	FName Namespace = GetNamespace(Object); | ||||
| 	return *FString::Printf(TEXT("%s.%s"), *Namespace.ToString(), *Object->GetName()); | ||||
| } | ||||
|  | ||||
| void FCSUnrealSharpUtils::PurgeMetaData(const UObject* Object) | ||||
| { | ||||
| #if WITH_METADATA | ||||
| 	if (!IsValid(Object)) | ||||
| 	{ | ||||
| 		UE_LOGFMT(LogUnrealSharpUtilities, Error, "Tried to purge metadata of an invalid object"); | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	UPackage* Owner = Object->GetOutermost(); | ||||
| #if ENGINE_MINOR_VERSION >= 6 | ||||
| 	if (TMap<FName, FString>* MetaData = Owner->GetMetaData().GetMapForObject(Object)) | ||||
| #else | ||||
| 	if (TMap<FName, FString>* MetaData = Owner->GetMetaData()->GetMapForObject(Object)) | ||||
| #endif | ||||
| 	{ | ||||
| 		MetaData->Empty(); | ||||
| 	} | ||||
| #endif | ||||
| } | ||||
|  | ||||
| FName FCSUnrealSharpUtils::GetModuleName(const UObject* Object) | ||||
| { | ||||
| 	return FPackageName::GetShortFName(Object->GetPackage()->GetFName()); | ||||
| } | ||||
|  | ||||
| bool FCSUnrealSharpUtils::IsStandalonePIE() | ||||
| { | ||||
| #if WITH_EDITOR | ||||
| 	return !GIsEditor; | ||||
| #else | ||||
| 		return false; | ||||
| #endif | ||||
| } | ||||
|  | ||||
| void FCSUnrealSharpUtils::PurgeStruct(UStruct* Struct) | ||||
| { | ||||
| 	if (!IsValid(Struct)) | ||||
| 	{ | ||||
| 		UE_LOG(LogUnrealSharpUtilities, Warning, TEXT("Tried to purge an invalid struct: %s"), *GetNameSafe(Struct)); | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	PurgeMetaData(Struct); | ||||
|  | ||||
| 	Struct->PropertyLink = nullptr; | ||||
| 	Struct->DestructorLink = nullptr; | ||||
| 	Struct->ChildProperties = nullptr; | ||||
| 	Struct->Children = nullptr; | ||||
| 	Struct->PropertiesSize = 0; | ||||
| 	Struct->MinAlignment = 0; | ||||
| 	Struct->RefLink = nullptr; | ||||
| } | ||||
|  | ||||
| FGuid FCSUnrealSharpUtils::ConstructGUIDFromName(const FName& Name) | ||||
| { | ||||
| 	return ConstructGUIDFromString(Name.ToString()); | ||||
| } | ||||
|  | ||||
| FString FCSUnrealSharpUtils::MakeQuotedPath(const FString& Path) | ||||
| { | ||||
| 	if (Path.IsEmpty()) | ||||
| 	{ | ||||
| 		return TEXT(""); | ||||
| 	} | ||||
|  | ||||
| 	if (Path.StartsWith(TEXT("\"")) && Path.EndsWith(TEXT("\""))) | ||||
| 	{ | ||||
| 		return Path; | ||||
| 	} | ||||
|  | ||||
| 	return FString::Printf(TEXT("\"%s\""), *Path); | ||||
| } | ||||
|  | ||||
| FGuid FCSUnrealSharpUtils::ConstructGUIDFromString(const FString& Name) | ||||
| { | ||||
| 	const uint32 BufferLength = Name.Len() * sizeof(Name[0]); | ||||
| 	uint32 HashBuffer[5]; | ||||
| 	FSHA1::HashBuffer(*Name, BufferLength, reinterpret_cast<uint8*>(HashBuffer)); | ||||
| 	return FGuid(HashBuffer[1], HashBuffer[2], HashBuffer[3], HashBuffer[4]);  | ||||
| } | ||||
| @ -0,0 +1,47 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "Kismet/BlueprintFunctionLibrary.h" | ||||
|  | ||||
| #define UE_VERSION_VAL(Major, Minor) ((Major) * 10000 + (Minor)) | ||||
| #define UE_CURRENT_VERSION UE_VERSION_VAL(ENGINE_MAJOR_VERSION, ENGINE_MINOR_VERSION) | ||||
| #define UE_VERSION_BEFORE(Major, Minor) (UE_CURRENT_VERSION < UE_VERSION_VAL(Major, Minor)) | ||||
| #define UE_VERSION_SINCE(Major, Minor)  (UE_CURRENT_VERSION >= UE_VERSION_VAL(Major, Minor)) | ||||
| #define UE_VERSION_EQUAL(Major, Minor)  (UE_CURRENT_VERSION == UE_VERSION_VAL(Major, Minor)) | ||||
|  | ||||
| namespace FCSUnrealSharpUtils | ||||
| { | ||||
| 	UNREALSHARPUTILITIES_API FName GetNamespace(const UObject* Object); | ||||
| 	UNREALSHARPUTILITIES_API FName GetNamespace(FName PackageName); | ||||
| 	UNREALSHARPUTILITIES_API FName GetNativeFullName(const UField* Object); | ||||
|  | ||||
| 	UNREALSHARPUTILITIES_API void PurgeMetaData(const UObject* Object); | ||||
| 	 | ||||
| 	UNREALSHARPUTILITIES_API FName GetModuleName(const UObject* Object); | ||||
|  | ||||
| 	UNREALSHARPUTILITIES_API bool IsStandalonePIE(); | ||||
|  | ||||
| 	UNREALSHARPUTILITIES_API void PurgeStruct(UStruct* Struct); | ||||
|  | ||||
| 	UNREALSHARPUTILITIES_API FGuid ConstructGUIDFromString(const FString& Name); | ||||
| 	UNREALSHARPUTILITIES_API FGuid ConstructGUIDFromName(const FName& Name); | ||||
|  | ||||
| 	UNREALSHARPUTILITIES_API FString MakeQuotedPath(const FString& Path); | ||||
|  | ||||
| 	template<typename T> | ||||
| 	static void GetAllCDOsOfClass(TArray<T*>& OutObjects) | ||||
| 	{ | ||||
| 		for (TObjectIterator<UClass> It; It; ++It) | ||||
| 		{ | ||||
| 			UClass* ClassObject = *It; | ||||
| 		 | ||||
| 			if (!ClassObject->IsChildOf(T::StaticClass()) || ClassObject->HasAnyClassFlags(CLASS_Abstract)) | ||||
| 			{ | ||||
| 				continue; | ||||
| 			} | ||||
|  | ||||
| 			T* CDO = ClassObject->GetDefaultObject<T>(); | ||||
| 			OutObjects.Add(CDO); | ||||
| 		} | ||||
| 	} | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user