先来看看可以实现的效果:
.cpp文件
#include "drawPolygon.h"
#include "Components/LineBatchComponent.h"
#include "Engine/World.h"
#include "EngineGlobals.h"
#include "PrimitiveViewRelevance.h"
#include "PrimitiveSceneProxy.h"
#include "Engine/Engine.h"
#include "MaterialShared.h"
#include "Materials/Material.h"
#include "Engine/CollisionProfile.h"
#include "SceneManagement.h"
#include "DynamicMeshBuilder.h"
void UdrawPolygon::DrawCircleArc(UObject* WorldContextObject, const FVector& Center, float Radius, const FVector& X, const FVector& Y, int32 Segments, const FColor& Color, uint8 DepthPriority, float fLifeTime)
{
ULineBatchComponent* const LineBatcher = WorldContextObject->GetWorld()->PersistentLineBatcher;
LineBatcher->DrawCircle(Center, X, Y, Color, Radius, Segments, DepthPriority);
}
.h文件
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "drawPolygon.generated.h"
UCLASS()
class DRAWCIRCLE_API UdrawPolygon : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable, Category = "Custom", meta = (Keywords = "draw"))
static void DrawCircleArc(UObject* WorldContextObject, const FVector& Center, float Radius, const FVector& X, const FVector& Y, int32 Segments, const FColor& Color, uint8 DepthPriority, float fLifeTime);
};
1、创建输入参数变量
2、绘制界面绑定变量
3、变量输入
参数说明:
Center:中心点
X:X方向比例, 默认向量1,0,0
Y:Y方向比例, 默认向量0,1,0
Radius:需要绘制的圆圈半径
Segments: 圆圈的分段数,默认180,数值大较为平滑
color:根据需要输入RGBA颜色值
Depth Priority: 深度优先级,默认为5
F Lift Time: 持续的时间,根据需要调整
案例中根据分类生成不同颜色不同半径的圆圈。
此部分根据具体的业务规则编写代码,此处仅展示一个根据输入值代入公式输出半径值的案例。
原始案例公式:
创建局部变量并设置默认值,即为公式中常数值的代入。
在关卡蓝图中进行方法集成。