赞
踩
UE5 C++ SplineMesh的蓝图函数库实现方法
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<USplineMeshComponent*> BBB;
- };
UAAABlueprintFunctionLibrary.cpp
- // Fill out your copyright notice in the Description page of Project Settings.
-
-
- #include "AAABlueprintFunctionLibrary.h"
-
- #include <filesystem>
- TArray<USplineMeshComponent*> 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; i<Point-1; i++)
- {
- FVector startlocation,startTangent,Endlocation,EndTangent;
- Spline01->GetLocationAndTangentAtSplinePoint(i,startlocation,startTangent,Scapse);
- Spline01->GetLocationAndTangentAtSplinePoint(i+1,Endlocation,EndTangent,Scapse);
-
- USplineMeshComponent* SplineMesh = NewObject<USplineMeshComponent>(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);
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。