UE5 C++ SplineMesh蓝图函数库实现(小白笔记)

UE5 C++ SplineMesh的蓝图函数库实现方法

UE5 C++ SplineMesh蓝图函数库实现(小白笔记)_第1张图片

 UAAABlueprintFunctionLibrary

UAAABlueprintFunctionLibrary.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/SplineComponent.h"
#include "Components/SplineMeshComponent.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "AAABlueprintFunctionLibrary.generated.h"

/**
 * 
 */
UENUM(BlueprintType)
enum class EMyEnum:uint8
{
		KeepRelativeTransform UMETA(DisplayName = "KeepRelativeTransform"),
		KeepWorldTransform UMETA(DisplayName = "KeepWorldTransform"),
};

UCLASS()
class SPLINECPP_API UAAABlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
public:
	UFUNCTION(BlueprintCallable,Category = "Move SplineMesh")
	static void CanSplineMeshMovAble(USplineComponent* Spline01,USplineComponent* Spline02,UStaticMesh* SplineStaticMesh,ESplineMeshAxis::Type ForwardAxis,ESplineCoordinateSpace::Type Scapse,bool Movable,EMyEnum MyEnumParam);

	static void abc();
private:
	static TArray BBB;
};

UAAABlueprintFunctionLibrary.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "AAABlueprintFunctionLibrary.h"

#include 
TArray UAAABlueprintFunctionLibrary::BBB;

void UAAABlueprintFunctionLibrary::CanSplineMeshMovAble(USplineComponent* Spline01, USplineComponent* Spline02,
                                                        UStaticMesh* SplineStaticMesh, ESplineMeshAxis::Type ForwardAxis, ESplineCoordinateSpace::Type Scapse,bool Movable,EMyEnum MyEnumParam)
{
	abc();
	if (!Spline01)
	{
		return;
	}

	Spline01->RegisterComponent();
	int32 Point = Spline01->GetNumberOfSplinePoints();

	if (Point<2)
	{
		return;
	}
	
	for (int32 i = 0; iGetLocationAndTangentAtSplinePoint(i,startlocation,startTangent,Scapse);
		Spline01->GetLocationAndTangentAtSplinePoint(i+1,Endlocation,EndTangent,Scapse);

		USplineMeshComponent* SplineMesh = NewObject(Spline01);
		SplineMesh->SetMobility(EComponentMobility::Movable);
		SplineMesh->SetStaticMesh(SplineStaticMesh);
		SplineMesh->SetForwardAxis(ForwardAxis);

		SplineMesh->SetStartAndEnd(startlocation,startTangent,Endlocation,EndTangent);
		switch (MyEnumParam)
		{
		case EMyEnum::KeepRelativeTransform:
			SplineMesh->AttachToComponent(Spline01,FAttachmentTransformRules::KeepRelativeTransform);
			break;
		case EMyEnum::KeepWorldTransform:
			SplineMesh->AttachToComponent(Spline01,FAttachmentTransformRules::KeepWorldTransform);
			break;
			default:
				break;
		}
		SplineMesh->RegisterComponent();

		BBB.Add(SplineMesh);
		
		
	}
}

void UAAABlueprintFunctionLibrary::abc()
{
	//GEngine->AddOnScreenDebugMessage(-1,0.5f,FColor::Red,FString::Printf("%s"),BBB.GetTypeSize(),true);
	
}

你可能感兴趣的:(ue5,笔记)