| @ -0,0 +1,124 @@ | ||||
| #include "K2Node_CSAsyncAction.h" | ||||
|  | ||||
| #include "BlueprintActionDatabaseRegistrar.h" | ||||
| #include "BlueprintFunctionNodeSpawner.h" | ||||
| #include "BlueprintNodeSpawner.h" | ||||
| #include "Delegates/Delegate.h" | ||||
| #include "EdGraph/EdGraphNode.h" | ||||
| #include "Extensions/BlueprintActions/CSBlueprintAsyncActionBase.h" | ||||
| #include "HAL/Platform.h" | ||||
| #include "Misc/AssertionMacros.h" | ||||
| #include "Templates/Casts.h" | ||||
| #include "Templates/SubclassOf.h" | ||||
| #include "TypeGenerator/CSClass.h" | ||||
| #include "UObject/Class.h" | ||||
| #include "UObject/Field.h" | ||||
| #include "UObject/NameTypes.h" | ||||
| #include "UObject/ObjectPtr.h" | ||||
| #include "UObject/UnrealType.h" | ||||
| #include "UObject/WeakObjectPtrTemplates.h" | ||||
|  | ||||
| #define LOCTEXT_NAMESPACE "K2Node" | ||||
|  | ||||
| UK2Node_CSAsyncAction::UK2Node_CSAsyncAction() | ||||
| { | ||||
| 	ProxyActivateFunctionName = GET_FUNCTION_NAME_CHECKED(UCSBlueprintAsyncActionBase, Activate); | ||||
| } | ||||
|  | ||||
| void UK2Node_CSAsyncAction::SetNodeFunc(UEdGraphNode* NewNode, bool /*bIsTemplateNode*/, TWeakObjectPtr<UFunction> FunctionPtr) | ||||
| { | ||||
| 	UK2Node_CSAsyncAction* AsyncTaskNode = CastChecked<UK2Node_CSAsyncAction>(NewNode); | ||||
| 	if (FunctionPtr.IsValid()) | ||||
| 	{ | ||||
| 		UFunction* Func = FunctionPtr.Get(); | ||||
| 		FObjectProperty* ReturnProp = CastFieldChecked<FObjectProperty>(Func->GetReturnProperty()); | ||||
| 						 | ||||
| 		AsyncTaskNode->ProxyFactoryFunctionName = Func->GetFName(); | ||||
| 		AsyncTaskNode->ProxyFactoryClass        = Func->GetOuterUClass(); | ||||
| 		AsyncTaskNode->ProxyClass               = ReturnProp->PropertyClass; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void UK2Node_CSAsyncAction::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const | ||||
| { | ||||
| 	struct GetMenuActions_Utils | ||||
| 	{ | ||||
| 		static bool IsFactoryMethod(const UFunction* Function, const UClass* InTargetType) | ||||
| 		{ | ||||
| 			if (!Function->HasAnyFunctionFlags(FUNC_Static)) | ||||
| 			{ | ||||
| 				return false; | ||||
| 			} | ||||
|  | ||||
| 			if (!Function->GetOwnerClass()->HasAnyClassFlags(CLASS_Deprecated | CLASS_NewerVersionExists)) | ||||
| 			{ | ||||
| 				FObjectProperty* ReturnProperty = CastField<FObjectProperty>(Function->GetReturnProperty()); | ||||
| 				// see if the function is a static factory method | ||||
| 				bool const bIsFactoryMethod = (ReturnProperty != nullptr) && (ReturnProperty->PropertyClass != nullptr) && | ||||
| 					ReturnProperty->PropertyClass->IsChildOf(InTargetType); | ||||
|  | ||||
| 				return bIsFactoryMethod; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		static UBlueprintNodeSpawner* MakeAction(UClass* NodeClass, const UFunction* FactoryFunc) | ||||
| 		{ | ||||
| 			UClass* FactoryClass = FactoryFunc ? FactoryFunc->GetOwnerClass() : nullptr; | ||||
| 			if (FactoryClass && FactoryClass->HasMetaData(TEXT("HasDedicatedAsyncNode"))) | ||||
| 			{ | ||||
| 				// Wants to use a more specific blueprint node to handle the async action | ||||
| 				return nullptr; | ||||
| 			} | ||||
|  | ||||
| 			UBlueprintNodeSpawner* NodeSpawner = UBlueprintFunctionNodeSpawner::Create(FactoryFunc); | ||||
| 			check(NodeSpawner != nullptr); | ||||
| 			NodeSpawner->NodeClass = NodeClass; | ||||
|  | ||||
| 			TWeakObjectPtr<UFunction> FunctionPtr = MakeWeakObjectPtr(const_cast<UFunction*>(FactoryFunc)); | ||||
| 			NodeSpawner->CustomizeNodeDelegate = UBlueprintNodeSpawner::FCustomizeNodeDelegate::CreateStatic(SetNodeFunc, FunctionPtr); | ||||
|  | ||||
| 			return NodeSpawner; | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
| 	UClass* NodeClass = GetClass(); | ||||
| 	UClass* TargetType = UCSBlueprintAsyncActionBase::StaticClass(); | ||||
|  | ||||
| 	for (TObjectIterator<UCSClass> ClassIt; ClassIt; ++ClassIt) | ||||
| 	{ | ||||
| 		UCSClass* Class = *ClassIt; | ||||
| 		if (Class->HasAnyClassFlags(CLASS_Abstract) || !Class->IsChildOf(TargetType)) | ||||
| 		{ | ||||
| 			continue; | ||||
| 		} | ||||
|  | ||||
| 		for (TFieldIterator<UFunction> FuncIt(Class, EFieldIteratorFlags::ExcludeSuper); FuncIt; ++FuncIt) | ||||
| 		{ | ||||
| 			UFunction* Function = *FuncIt; | ||||
| 			if (!GetMenuActions_Utils::IsFactoryMethod(Function, TargetType)) | ||||
| 			{ | ||||
| 				continue; | ||||
| 			} | ||||
| 			else if (UBlueprintNodeSpawner* NewAction = GetMenuActions_Utils::MakeAction(NodeClass, Function)) | ||||
| 			{ | ||||
| 				ActionRegistrar.AddBlueprintAction(Class, NewAction); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void UK2Node_CSAsyncAction::ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph) | ||||
| { | ||||
| 	if (ProxyClass->bLayoutChanging) | ||||
| 	{ | ||||
| 		return; | ||||
| 	} | ||||
| 	 | ||||
| 	Super::ExpandNode(CompilerContext, SourceGraph); | ||||
| } | ||||
|  | ||||
| #undef LOCTEXT_NAMESPACE | ||||
| @ -0,0 +1,30 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "K2Node_BaseAsyncTask.h" | ||||
| #include "UObject/ObjectMacros.h" | ||||
| #include "UObject/UObjectGlobals.h" | ||||
|  | ||||
| #include "K2Node_CSAsyncAction.generated.h" | ||||
|  | ||||
| class FBlueprintActionDatabaseRegistrar; | ||||
| class UObject; | ||||
|  | ||||
| UCLASS() | ||||
| class UNREALSHARPBLUEPRINT_API UK2Node_CSAsyncAction : public UK2Node_BaseAsyncTask | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
|  | ||||
| public: | ||||
|  | ||||
| 	UK2Node_CSAsyncAction(); | ||||
|  | ||||
| 	static void SetNodeFunc(UEdGraphNode* NewNode, bool, TWeakObjectPtr<UFunction> FunctionPtr); | ||||
|  | ||||
| 	// UK2Node interface | ||||
| 	virtual void GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const override; | ||||
| 	virtual void ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph) override; | ||||
| 	// End of UK2Node interface | ||||
| }; | ||||
| @ -0,0 +1,124 @@ | ||||
| #include "K2Node_CSCancellableAsyncAction.h" | ||||
|  | ||||
| #include "BlueprintActionDatabaseRegistrar.h" | ||||
| #include "BlueprintFunctionNodeSpawner.h" | ||||
| #include "BlueprintNodeSpawner.h" | ||||
| #include "Delegates/Delegate.h" | ||||
| #include "EdGraph/EdGraphNode.h" | ||||
| #include "Extensions/BlueprintActions/CSCancellableAsyncAction.h" | ||||
| #include "HAL/Platform.h" | ||||
| #include "Misc/AssertionMacros.h" | ||||
| #include "Templates/Casts.h" | ||||
| #include "Templates/SubclassOf.h" | ||||
| #include "TypeGenerator/CSClass.h" | ||||
| #include "UObject/Class.h" | ||||
| #include "UObject/Field.h" | ||||
| #include "UObject/NameTypes.h" | ||||
| #include "UObject/ObjectPtr.h" | ||||
| #include "UObject/UnrealType.h" | ||||
| #include "UObject/WeakObjectPtrTemplates.h" | ||||
|  | ||||
| #define LOCTEXT_NAMESPACE "K2Node" | ||||
|  | ||||
| UK2Node_CSCancellableAsyncAction::UK2Node_CSCancellableAsyncAction() | ||||
| { | ||||
| 	ProxyActivateFunctionName = GET_FUNCTION_NAME_CHECKED(UCSCancellableAsyncAction, Activate); | ||||
| } | ||||
|  | ||||
| void UK2Node_CSCancellableAsyncAction::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const | ||||
| { | ||||
| 	struct GetMenuActions_Utils | ||||
| 	{ | ||||
| 		static bool IsFactoryMethod(const UFunction* Function, const UClass* InTargetType) | ||||
| 		{ | ||||
| 			if (!Function->HasAnyFunctionFlags(FUNC_Static)) | ||||
| 			{ | ||||
| 				return false; | ||||
| 			} | ||||
|  | ||||
| 			if (!Function->GetOwnerClass()->HasAnyClassFlags(CLASS_Deprecated | CLASS_NewerVersionExists)) | ||||
| 			{ | ||||
| 				FObjectProperty* ReturnProperty = CastField<FObjectProperty>(Function->GetReturnProperty()); | ||||
| 				// see if the function is a static factory method | ||||
| 				bool const bIsFactoryMethod = (ReturnProperty != nullptr) && (ReturnProperty->PropertyClass != nullptr) && | ||||
| 					ReturnProperty->PropertyClass->IsChildOf(InTargetType); | ||||
|  | ||||
| 				return bIsFactoryMethod; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		static void SetNodeFunc(UEdGraphNode* NewNode, bool /*bIsTemplateNode*/, TWeakObjectPtr<UFunction> FunctionPtr) | ||||
| 		{ | ||||
| 			UK2Node_CSCancellableAsyncAction* AsyncTaskNode = CastChecked<UK2Node_CSCancellableAsyncAction>(NewNode); | ||||
| 			if (FunctionPtr.IsValid()) | ||||
| 			{ | ||||
| 				UFunction* Func = FunctionPtr.Get(); | ||||
| 				FObjectProperty* ReturnProp = CastFieldChecked<FObjectProperty>(Func->GetReturnProperty()); | ||||
| 						 | ||||
| 				AsyncTaskNode->ProxyFactoryFunctionName = Func->GetFName(); | ||||
| 				AsyncTaskNode->ProxyFactoryClass        = Func->GetOuterUClass(); | ||||
| 				AsyncTaskNode->ProxyClass               = ReturnProp->PropertyClass; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		static UBlueprintNodeSpawner* MakeAction(UClass* NodeClass, const UFunction* FactoryFunc) | ||||
| 		{ | ||||
| 			UClass* FactoryClass = FactoryFunc ? FactoryFunc->GetOwnerClass() : nullptr; | ||||
| 			if (FactoryClass && FactoryClass->HasMetaData(TEXT("HasDedicatedAsyncNode"))) | ||||
| 			{ | ||||
| 				// Wants to use a more specific blueprint node to handle the async action | ||||
| 				return nullptr; | ||||
| 			} | ||||
|  | ||||
| 			UBlueprintNodeSpawner* NodeSpawner = UBlueprintFunctionNodeSpawner::Create(FactoryFunc); | ||||
| 			check(NodeSpawner != nullptr); | ||||
| 			NodeSpawner->NodeClass = NodeClass; | ||||
|  | ||||
| 			TWeakObjectPtr<UFunction> FunctionPtr = MakeWeakObjectPtr(const_cast<UFunction*>(FactoryFunc)); | ||||
| 			NodeSpawner->CustomizeNodeDelegate = UBlueprintNodeSpawner::FCustomizeNodeDelegate::CreateStatic(GetMenuActions_Utils::SetNodeFunc, FunctionPtr); | ||||
|  | ||||
| 			return NodeSpawner; | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
| 	UClass* NodeClass = GetClass(); | ||||
| 	UClass* TargetType = UCSCancellableAsyncAction::StaticClass(); | ||||
|  | ||||
| 	for (TObjectIterator<UCSClass> ClassIt; ClassIt; ++ClassIt) | ||||
| 	{ | ||||
| 		UCSClass* Class = *ClassIt; | ||||
| 		if (Class->HasAnyClassFlags(CLASS_Abstract) || !Class->IsChildOf(TargetType)) | ||||
| 		{ | ||||
| 			continue; | ||||
| 		} | ||||
|  | ||||
| 		for (TFieldIterator<UFunction> FuncIt(Class, EFieldIteratorFlags::ExcludeSuper); FuncIt; ++FuncIt) | ||||
| 		{ | ||||
| 			UFunction* Function = *FuncIt; | ||||
| 			if (!GetMenuActions_Utils::IsFactoryMethod(Function, TargetType)) | ||||
| 			{ | ||||
| 				continue; | ||||
| 			} | ||||
| 			else if (UBlueprintNodeSpawner* NewAction = GetMenuActions_Utils::MakeAction(NodeClass, Function)) | ||||
| 			{ | ||||
| 				ActionRegistrar.AddBlueprintAction(Class, NewAction); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void UK2Node_CSCancellableAsyncAction::ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph) | ||||
| { | ||||
| 	if (ProxyClass->bLayoutChanging) | ||||
| 	{ | ||||
| 		return; | ||||
| 	} | ||||
| 	 | ||||
| 	Super::ExpandNode(CompilerContext, SourceGraph); | ||||
| } | ||||
|  | ||||
| #undef LOCTEXT_NAMESPACE | ||||
| @ -0,0 +1,28 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "K2Node_CSAsyncAction.h" | ||||
| #include "UObject/ObjectMacros.h" | ||||
| #include "UObject/UObjectGlobals.h" | ||||
|  | ||||
| #include "K2Node_CSCancellableAsyncAction.generated.h" | ||||
|  | ||||
| class FBlueprintActionDatabaseRegistrar; | ||||
| class UObject; | ||||
|  | ||||
| UCLASS() | ||||
| class UK2Node_CSCancellableAsyncAction : public UK2Node_CSAsyncAction | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
|  | ||||
| public: | ||||
|  | ||||
| 	UK2Node_CSCancellableAsyncAction(); | ||||
| 	 | ||||
| 	// UK2Node interface | ||||
| 	virtual void GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const override; | ||||
| 	virtual void ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph) override; | ||||
| 	// End of UK2Node interface | ||||
| }; | ||||
| @ -0,0 +1,28 @@ | ||||
| using UnrealBuildTool; | ||||
|  | ||||
| public class UnrealSharpBlueprint : ModuleRules | ||||
| { | ||||
|     public UnrealSharpBlueprint(ReadOnlyTargetRules Target) : base(Target) | ||||
|     { | ||||
|         PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; | ||||
|  | ||||
|         PublicDependencyModuleNames.AddRange( | ||||
|             new string[] | ||||
|             { | ||||
|                 "Core", | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|         PrivateDependencyModuleNames.AddRange( | ||||
|             new string[] | ||||
|             { | ||||
|                 "CoreUObject", | ||||
|                 "Engine", | ||||
|                 "UnrealSharpCore", | ||||
|                 "BlueprintGraph" | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|         PublicDefinitions.Add("SkipGlueGeneration"); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,17 @@ | ||||
| #include "UnrealSharpBlueprint.h" | ||||
|  | ||||
| #define LOCTEXT_NAMESPACE "FUnrealSharpBlueprintModule" | ||||
|  | ||||
| void FUnrealSharpBlueprintModule::StartupModule() | ||||
| { | ||||
| 	 | ||||
| } | ||||
|  | ||||
| void FUnrealSharpBlueprintModule::ShutdownModule() | ||||
| { | ||||
| 	 | ||||
| } | ||||
|  | ||||
| #undef LOCTEXT_NAMESPACE | ||||
|      | ||||
| IMPLEMENT_MODULE(FUnrealSharpBlueprintModule, UnrealSharpBlueprint) | ||||
| @ -0,0 +1,14 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "Modules/ModuleManager.h" | ||||
|  | ||||
| class FUnrealSharpBlueprintModule : public IModuleInterface | ||||
| { | ||||
| public: | ||||
|  | ||||
|     // IModuleInterface interface begin | ||||
|     virtual void StartupModule() override; | ||||
|     virtual void ShutdownModule() override; | ||||
|     // End | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user