UE5 根据数据库播放字幕 和 C++碰撞产生爆照特效

一.播放弹幕,使用了数据库来一 一 对应。

之前使用,ScollBox变为horizontal (水平的),但只能做到字幕滑动播放,如下。

后来使用,数据表选择播放代替。首先创建结构体World

以这个结构体,创建数据表DataTable. ALLWORLD

创了个插件,写了个Actor来管理UI

蓝图静态库函数,用来把int 转换为 对应的FName。进而方便实现访问数据表

cpp 复制代码
	UFUNCTION(BlueprintCallable, meta = (DisplayName = "Execute Send RowName", Keywords = "HMSUI sample test testing"), Category = "HMSUITesting")
	static FName HMSUISendRowName(int index);
cpp 复制代码
FName UHMSUIBPLibrary::HMSUISendRowName(int index)
{
	FString TempString = FString::FromInt(index);
	FName ConvertedFString = FName(*TempString);
	return ConvertedFString;
}

创建一个UISystemActor,使用BlueprintImplementableEvent,让蓝图实现切换表里的内容体现在UI上。

cpp 复制代码
UCLASS()
class HMSUI_API AHMSUISystem : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AHMSUISystem();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;
	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = "UI")
	void setIndex(int i);
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MHSUI")
	int index;
};

首先实现BlueprintImplementableEvent函数,使用插件里的蓝图静态库函数转换为FName,再读取表里的结构体。

将这个结构体,传入RunText,加入到视口一段时间后,又消失。

这里如何传入WORLD,使用Expose on Spawn,产生时暴露出来。

这样在C++里也可以,切换UI字幕

二.如何碰撞,产生爆照特效

1.碰撞,这些回调函数。一定要在继承AActor,APawn这样的类上使用,而且一定包含了继承的头文件。我就遇到过我没包含头文件,编译居然没报错。但是你死活用不了里面的碰撞回调函数。后来发现加个头文件,就行了。

只是OverLap的话,还算蛮简单的。头文件,碰撞和回调函数都声明了。

cpp 复制代码
#include "Components/SphereComponent.h"
cpp 复制代码
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "MySceneComponent")
USphereComponent* MySphereCollision;
//碰撞开始的回调函数
UFUNCTION()
void BeginOverlapFunction(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

2.构造函数里写,碰撞大小等

cpp 复制代码
AHMSTarget::AHMSTarget() : AActorBase() {
	MySphereCollision = CreateDefaultSubobject<USphereComponent>(TEXT("MySphereCollision"));
	MySphereCollision->InitSphereRadius(3000.0f);
	RootComponent = MySphereCollision;
}

碰撞后,在回调函数里将 特效生成即可

cpp 复制代码
void AHMSTarget::BeginOverlapFunction(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	UObject* ExplodeNiagara = LoadObject<UObject>(nullptr, TEXT("/Script/Niagara.NiagaraSystem'/Game/Explosions_Niagara/Particles/P_Explosion08.P_Explosion08'"));
	UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, Cast<UNiagaraSystem>(ExplodeNiagara), GetActorLocation(), FRotator::ZeroRotator,FVector(2.f));
}

但要将 NigaraFunctionLibrary的头文件加上,SpawnSystemAtLocation里的参数,也可以不用默认参数。然后就能实现 ,相同类的不同子类 ,碰撞后爆炸的效果。

cpp 复制代码
#include "NiagaraFunctionLibrary.h"
相关推荐
ue星空3 天前
UE5配置MRQ编解码器输出MP4视频
ue5·音视频
吴梓穆9 天前
UE5 图片9宫格切割
ue5
Kingsdesigner10 天前
游戏开发流程革命:我用Substance插件,在UE5内实现材质的实时“创世纪”
游戏·adobe·ue5·游戏引擎·游戏开发·设计师·substance 3d
幻雨様12 天前
UE5多人MOBA+GAS 37、库存系统(四)
ue5
DoomGT12 天前
Physics Simulation - UE中Projectile相关事项
ue5·游戏引擎·虚幻·虚幻引擎·unreal engine
右弦GISer14 天前
【UE5医学影像可视化】读取本地Dicom生成VolumeTexture,实现2D显示和自动翻页
ue5·dicom·医学图像
小梦白14 天前
RPG增容3:尝试使用MVC结构搭建玩家升级UI(一)
游戏·ui·ue5·mvc
AgilityBaby14 天前
解决「CPU Virtualization Technology 未开启或被占用」弹窗问题
ue5·游戏引擎·无畏契约·cpu 虚拟化技术
幻雨様16 天前
UE5多人MOBA+GAS 番外篇:同时造成多种类型伤害
ue5
幻雨様16 天前
UE5多人MOBA+GAS 番外篇:同时造成多种类型伤害,以各种属性值的百分比来应用伤害(版本二)
java·前端·ue5