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"
相关推荐
漫游者Nova2 小时前
虚幻引擎Unreal Engine5恐怖游戏设计制作教程,从入门到精通从零开始完整项目开发实战详细讲解中英字幕
ue5·游戏引擎·虚幻·游戏开发完整教程·恐怖游戏开发
ue星空2 天前
UE5音频技术
ue5
帅_shuai_13 天前
UE5 游戏模板 —— FirstShootGame
游戏·ue5
吴梓穆14 天前
UE5 手动停止Delay定时器
ue5
AgilityBaby15 天前
UE5蓝图按键输入绑定学习笔记
笔记·学习·ue5·蓝图
涟涟涟涟15 天前
UE5错误 Linux离线状态下错误 请求失败libcurl错误:6无法解析主机名
linux·ue5
蛋卷卷-15 天前
【UE5】如何开发安卓项目的udp客户端
android·ue5·udp
异次元的归来17 天前
UE5反射系统分析(一)generated.h
ue5·游戏引擎·unreal engine
道之所在17 天前
UE5.6源码安卓打包报错
android·ue5
AgilityBaby17 天前
UE5创建蒙太奇动画并播放和在动画蒙太奇中创建动画通知状态
笔记·学习·ue5·游戏引擎·蓝图·蒙太奇动画