当前位置:   article > 正文

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

ue5 c++ ublueprintfunctionlibrary

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

 UAAABlueprintFunctionLibrary

UAAABlueprintFunctionLibrary.h

  1. // Fill out your copyright notice in the Description page of Project Settings.
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "Components/SplineComponent.h"
  5. #include "Components/SplineMeshComponent.h"
  6. #include "Kismet/BlueprintFunctionLibrary.h"
  7. #include "AAABlueprintFunctionLibrary.generated.h"
  8. /**
  9. *
  10. */
  11. UENUM(BlueprintType)
  12. enum class EMyEnum:uint8
  13. {
  14. KeepRelativeTransform UMETA(DisplayName = "KeepRelativeTransform"),
  15. KeepWorldTransform UMETA(DisplayName = "KeepWorldTransform"),
  16. };
  17. UCLASS()
  18. class SPLINECPP_API UAAABlueprintFunctionLibrary : public UBlueprintFunctionLibrary
  19. {
  20. GENERATED_BODY()
  21. public:
  22. UFUNCTION(BlueprintCallable,Category = "Move SplineMesh")
  23. static void CanSplineMeshMovAble(USplineComponent* Spline01,USplineComponent* Spline02,UStaticMesh* SplineStaticMesh,ESplineMeshAxis::Type ForwardAxis,ESplineCoordinateSpace::Type Scapse,bool Movable,EMyEnum MyEnumParam);
  24. static void abc();
  25. private:
  26. static TArray<USplineMeshComponent*> BBB;
  27. };

UAAABlueprintFunctionLibrary.cpp

  1. // Fill out your copyright notice in the Description page of Project Settings.
  2. #include "AAABlueprintFunctionLibrary.h"
  3. #include <filesystem>
  4. TArray<USplineMeshComponent*> UAAABlueprintFunctionLibrary::BBB;
  5. void UAAABlueprintFunctionLibrary::CanSplineMeshMovAble(USplineComponent* Spline01, USplineComponent* Spline02,
  6. UStaticMesh* SplineStaticMesh, ESplineMeshAxis::Type ForwardAxis, ESplineCoordinateSpace::Type Scapse,bool Movable,EMyEnum MyEnumParam)
  7. {
  8. abc();
  9. if (!Spline01)
  10. {
  11. return;
  12. }
  13. Spline01->RegisterComponent();
  14. int32 Point = Spline01->GetNumberOfSplinePoints();
  15. if (Point<2)
  16. {
  17. return;
  18. }
  19. for (int32 i = 0; i<Point-1; i++)
  20. {
  21. FVector startlocation,startTangent,Endlocation,EndTangent;
  22. Spline01->GetLocationAndTangentAtSplinePoint(i,startlocation,startTangent,Scapse);
  23. Spline01->GetLocationAndTangentAtSplinePoint(i+1,Endlocation,EndTangent,Scapse);
  24. USplineMeshComponent* SplineMesh = NewObject<USplineMeshComponent>(Spline01);
  25. SplineMesh->SetMobility(EComponentMobility::Movable);
  26. SplineMesh->SetStaticMesh(SplineStaticMesh);
  27. SplineMesh->SetForwardAxis(ForwardAxis);
  28. SplineMesh->SetStartAndEnd(startlocation,startTangent,Endlocation,EndTangent);
  29. switch (MyEnumParam)
  30. {
  31. case EMyEnum::KeepRelativeTransform:
  32. SplineMesh->AttachToComponent(Spline01,FAttachmentTransformRules::KeepRelativeTransform);
  33. break;
  34. case EMyEnum::KeepWorldTransform:
  35. SplineMesh->AttachToComponent(Spline01,FAttachmentTransformRules::KeepWorldTransform);
  36. break;
  37. default:
  38. break;
  39. }
  40. SplineMesh->RegisterComponent();
  41. BBB.Add(SplineMesh);
  42. }
  43. }
  44. void UAAABlueprintFunctionLibrary::abc()
  45. {
  46. //GEngine->AddOnScreenDebugMessage(-1,0.5f,FColor::Red,FString::Printf("%s"),BBB.GetTypeSize(),true);
  47. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/894979
推荐阅读
相关标签
  

闽ICP备14008679号