| @ -0,0 +1,19 @@ | ||||
| // Fill out your copyright notice in the Description page of Project Settings. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "CSScriptBuilder.h" | ||||
| #include "UObject/Object.h" | ||||
| #include "CSGlueGenerator.generated.h" | ||||
|  | ||||
| UCLASS(NotBlueprintable, NotBlueprintType) | ||||
| class UNREALSHARPRUNTIMEGLUE_API UCSGlueGenerator : public UObject | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
| public: | ||||
| 	virtual void Initialize() {} | ||||
| 	virtual void ForceRefresh() {} | ||||
| protected: | ||||
| 	void SaveRuntimeGlue(const FCSScriptBuilder& ScriptBuilder, const FString& FileName, const FString& Suffix = FString(TEXT(".cs"))); | ||||
| }; | ||||
| @ -0,0 +1,18 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "Engine/DeveloperSettings.h" | ||||
| #include "CSRuntimeGlueSettings.generated.h" | ||||
|  | ||||
| class UCSGlueGenerator; | ||||
|  | ||||
| UCLASS(NotBlueprintable, Config = "Editor", DefaultConfig, DisplayName = "UnrealSharp Runtime Glue Settings") | ||||
| class UCSRuntimeGlueSettings : public UDeveloperSettings | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
| public: | ||||
| 	UCSRuntimeGlueSettings(); | ||||
| 	 | ||||
| 	UPROPERTY(Config, EditAnywhere) | ||||
| 	TArray<TSoftClassPtr<UCSGlueGenerator>> Generators; | ||||
| }; | ||||
| @ -0,0 +1,165 @@ | ||||
| #pragma once | ||||
|  | ||||
| class UNREALSHARPRUNTIMEGLUE_API FCSScriptBuilder | ||||
| { | ||||
| public: | ||||
| 	enum class IndentType | ||||
| 	{ | ||||
| 		Spaces, | ||||
| 		Tabs | ||||
| 	}; | ||||
| 	 | ||||
| 	explicit FCSScriptBuilder(IndentType InIndentMode) | ||||
| 	: UnsafeBlockCount(0) | ||||
| 	, IndentCount(0) | ||||
| 	, IndentMode(InIndentMode) | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| 	void Indent() | ||||
| 	{ | ||||
| 		++IndentCount; | ||||
| 	} | ||||
|  | ||||
| 	void Unindent() | ||||
| 	{ | ||||
| 		--IndentCount; | ||||
| 	} | ||||
|  | ||||
| 	void AppendLine() | ||||
| 	{ | ||||
| 		if (Report.Len() != 0) | ||||
| 		{ | ||||
| 			Report.Append(LINE_TERMINATOR); | ||||
| 		} | ||||
|  | ||||
| 		if (IndentMode == IndentType::Spaces) | ||||
| 		{ | ||||
| 			for (int32 Index = 0; Index < IndentCount; Index++) | ||||
| 			{ | ||||
| 				Report.Append(TEXT("    ")); | ||||
| 			} | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			for (int32 Index = 0; Index < IndentCount; Index++) | ||||
| 			{ | ||||
| 				Report.Append(TEXT("\t")); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	void Append(FStringView String) | ||||
| 	{ | ||||
| 		Report.Append(String); | ||||
| 	} | ||||
|  | ||||
| 	void Append(const FString& String) | ||||
| 	{ | ||||
| 		Report.Append(String); | ||||
| 	} | ||||
|  | ||||
| 	void Append(const TCHAR* String) | ||||
| 	{ | ||||
| 		Report.Append(String); | ||||
| 	} | ||||
|  | ||||
| 	void Append(const FName& Name) | ||||
| 	{ | ||||
| 		Report.Append(Name.ToString()); | ||||
| 	} | ||||
|  | ||||
| 	void AppendLine(const FText& Text) | ||||
| 	{ | ||||
| 		AppendLine(); | ||||
|  | ||||
| 		if (const FString* SourceString = FTextInspector::GetSourceString(Text)) | ||||
| 		{ | ||||
| 			Report.Append(*SourceString); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			Report.Append(Text.ToString()); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	void AppendLine(FStringView String) | ||||
| 	{ | ||||
| 		AppendLine(); | ||||
| 		Report.Append(String); | ||||
| 	} | ||||
|  | ||||
| 	void AppendLine(const FString& String) | ||||
| 	{ | ||||
| 		AppendLine(); | ||||
| 		Report.Append(String); | ||||
| 	} | ||||
|  | ||||
| 	void AppendLine(const ANSICHAR* Line) | ||||
| 	{ | ||||
| 		AppendLine(); | ||||
| 		Report.Append(Line); | ||||
| 	} | ||||
|  | ||||
| 	void AppendLine(const FName& Name) | ||||
| 	{ | ||||
| 		AppendLine(); | ||||
| 		Report.Append(Name.ToString()); | ||||
| 	} | ||||
|  | ||||
| 	void AppendLine(const TCHAR* Line) | ||||
| 	{ | ||||
| 		AppendLine(); | ||||
| 		Report.Append(Line); | ||||
| 	} | ||||
|  | ||||
| 	void OpenBrace() | ||||
| 	{ | ||||
| 		AppendLine(TEXT("{")); | ||||
| 		Indent(); | ||||
| 	} | ||||
|  | ||||
| 	void CloseBrace() | ||||
| 	{ | ||||
| 		Unindent(); | ||||
| 		AppendLine(TEXT("}")); | ||||
| 	} | ||||
|  | ||||
| 	void EndUnsafeBlock() | ||||
| 	{ | ||||
| 		check(UnsafeBlockCount >= 0); | ||||
| 		if (!--UnsafeBlockCount) | ||||
| 		{ | ||||
| 			CloseBrace(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	void Clear() | ||||
| 	{ | ||||
| 		Report.Reset(); | ||||
| 	} | ||||
|  | ||||
| 	FText ToText() const | ||||
| 	{ | ||||
| 		return FText::FromString(ToString()); | ||||
| 	} | ||||
|  | ||||
| 	FString ToString() const | ||||
| 	{ | ||||
| 		return Report.ToString(); | ||||
| 	} | ||||
|  | ||||
| 	bool IsEmpty() const | ||||
| 	{ | ||||
| 		return Report.Len() == 0; | ||||
| 	} | ||||
|  | ||||
| private: | ||||
|  | ||||
| 	TStringBuilder<2048> Report; | ||||
| 	TArray<FString> Directives; | ||||
| 	int32 UnsafeBlockCount; | ||||
| 	int32 IndentCount; | ||||
| 	IndentType IndentMode; | ||||
| 	 | ||||
| }; | ||||
| @ -0,0 +1,49 @@ | ||||
| // Fill out your copyright notice in the Description page of Project Settings. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "CSGlueGenerator.h" | ||||
| #include "CSAssetManagerGlueGenerator.generated.h" | ||||
|  | ||||
| UCLASS(DisplayName="Asset Manager Glue Generator", NotBlueprintable, NotBlueprintType) | ||||
| class UCSAssetManagerGlueGenerator : public UCSGlueGenerator | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
| private: | ||||
| 	// UCSGlueGenerator interface | ||||
| 	virtual void Initialize() override; | ||||
| 	virtual void ForceRefresh() override | ||||
| 	{ | ||||
| 		ProcessAssetIds(); | ||||
| 		ProcessAssetTypes(); | ||||
| 	} | ||||
| 	// End of UCSGlueGenerator interface | ||||
|  | ||||
| 	void TryRegisterAssetTypes(); | ||||
| 	 | ||||
| 	void OnModulesChanged(FName InModuleName, EModuleChangeReason InModuleChangeReason); | ||||
| 	void OnCompletedInitialScan(); | ||||
|  | ||||
| 	void OnAssetRemoved(const FAssetData& AssetData); | ||||
| 	void OnAssetRenamed(const FAssetData& AssetData, const FString& OldObjectPath); | ||||
| 	void OnInMemoryAssetCreated(UObject* Object); | ||||
| 	void OnInMemoryAssetDeleted(UObject* Object); | ||||
|  | ||||
| 	void OnAssetSearchRootAdded(const FString& RootPath); | ||||
|  | ||||
| 	void OnAssetManagerSettingsChanged(UObject* Object, FPropertyChangedEvent& PropertyChangedEvent); | ||||
|  | ||||
| 	bool IsRegisteredAssetType(const FAssetData& AssetData) { return IsRegisteredAssetType(AssetData.GetClass()); } | ||||
| 	bool IsRegisteredAssetType(UClass* Class); | ||||
|  | ||||
| 	void WaitUpdateAssetTypes() | ||||
| 	{ | ||||
| 		GEditor->GetTimerManager()->SetTimerForNextTick(FTimerDelegate::CreateUObject(this, &ThisClass::ProcessAssetIds)); | ||||
| 	} | ||||
|  | ||||
| 	void ProcessAssetIds(); | ||||
| 	void ProcessAssetTypes(); | ||||
|  | ||||
| 	bool bHasRegisteredAssetTypes = false; | ||||
| }; | ||||
| @ -0,0 +1,20 @@ | ||||
| // Fill out your copyright notice in the Description page of Project Settings. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "CSGlueGenerator.h" | ||||
| #include "CSGameplayTagsGlueGenerator.generated.h" | ||||
|  | ||||
| UCLASS(DisplayName="Gameplay Tags Glue Generator", NotBlueprintable, NotBlueprintType) | ||||
| class UCSGameplayTagsGlueGenerator : public UCSGlueGenerator | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
| private: | ||||
| 	// UCSGlueGenerator interface | ||||
| 	virtual void Initialize() override; | ||||
| 	virtual void ForceRefresh() override { ProcessGameplayTags(); } | ||||
| 	// End of UCSGlueGenerator interface | ||||
|  | ||||
| 	void ProcessGameplayTags(); | ||||
| }; | ||||
| @ -0,0 +1,22 @@ | ||||
| // Fill out your copyright notice in the Description page of Project Settings. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "CSGlueGenerator.h" | ||||
| #include "CSTraceTypeQueryGlueGenerator.generated.h" | ||||
|  | ||||
| UCLASS(DisplayName="Trace Type Query Glue Generator", NotBlueprintable, NotBlueprintType) | ||||
| class UCSTraceTypeQueryGlueGenerator : public UCSGlueGenerator | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
| private: | ||||
| 	// UCSGlueGenerator interface | ||||
| 	virtual void Initialize() override; | ||||
| 	virtual void ForceRefresh() override { ProcessTraceTypeQuery(); } | ||||
| 	// End of UCSGlueGenerator interface | ||||
|  | ||||
| 	void OnCollisionProfileChanged(UCollisionProfile* CollisionProfile); | ||||
| 	 | ||||
| 	void ProcessTraceTypeQuery(); | ||||
| }; | ||||
| @ -0,0 +1,32 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "CSGlueGenerator.h" | ||||
| #include "Modules/ModuleManager.h" | ||||
|  | ||||
| class UCSGlueGenerator; | ||||
|  | ||||
| DECLARE_MULTICAST_DELEGATE_TwoParams(FOnRuntimeGlueChanged, UCSGlueGenerator*, const FString&); | ||||
|  | ||||
| DECLARE_LOG_CATEGORY_EXTERN(LogUnrealSharpRuntimeGlue, Log, All); | ||||
|  | ||||
| class FUnrealSharpRuntimeGlueModule : public IModuleInterface | ||||
| { | ||||
| public: | ||||
|     virtual void StartupModule() override; | ||||
|     virtual void ShutdownModule() override; | ||||
|  | ||||
|     UNREALSHARPRUNTIMEGLUE_API static FUnrealSharpRuntimeGlueModule& Get() | ||||
|     { | ||||
|         return FModuleManager::LoadModuleChecked<FUnrealSharpRuntimeGlueModule>("UnrealSharpRuntimeGlue"); | ||||
|     } | ||||
|     UNREALSHARPRUNTIMEGLUE_API void ForceRefreshRuntimeGlue(); | ||||
|     UNREALSHARPRUNTIMEGLUE_API FOnRuntimeGlueChanged& GetOnRuntimeGlueChanged() { return OnRuntimeGlueChanged; } | ||||
|      | ||||
| private: | ||||
|     void InitializeRuntimeGlueGenerators(); | ||||
|     void OnModulesChanged(FName ModuleName, EModuleChangeReason Reason); | ||||
|      | ||||
|     TMap<TObjectKey<UClass>, UCSGlueGenerator*> RuntimeGlueGenerators; | ||||
|     FOnRuntimeGlueChanged OnRuntimeGlueChanged; | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user