1. 在UMG中可以使用UWidgetBlueprintLibrary类来绘制,
UWidgetBlueprintLibrary类提供了一系列的静态函数可以使用。
但只提供了DrawLine,DrawLines,DrawBox,DrawText,DrawTextFormatted函数,
如果要自己绘制的圆形,需要在DrawLine的基础上自己来写。
实际上UWidgetBlueprintLibrary类是对FSlateDrawElement的封装,所以也可以直接调用FSlateDrawElement
FSlateDrawElement提供了MakeBox,MakeText,MakeSpline这些函数
这种方式绘制的话有局限性:
1)这种方法只能在UMG中绘制,因为它需要UMG的Onpaint函数传入context参数。
2)用DrawLine自己封装的画圆函数锯齿严重,如果开启反锯齿参数,圆上居然有缺口的现象
2. 在Actor的Event tick函数里,可以使用drawdebug函数族来绘制图形。
3. 继承UMeshComponent组件来实现一个自己的组件,并添加到一个Actor中。
在这里可以使用PDI函数来绘制。
4. 直接使用UProceduralMeshComponent组件并添加到Actor中。
UProceduralMeshComponent提供了CreateMeshSection_LinearColor函数,把我们需要绘制的图型的顶点坐标,
UV坐标,顶点颜色传入这个函数即可绘制。这样我们可以随意自由的绘制任何我们需要的图形。
UProceduralMeshComponent并没有暴露给蓝图,因此需要在自己的Actor类里来创建出组件。
另外需要调用SetMaterial(0, GEngine->VertexColorMaterial)这个函数,顶点的颜色才能生效。
另外UProceduralMeshComponent提供了SetRelativeRotation了函数可以对组件进行旋转。