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"
相关推荐
AA陈超1 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P07-06 能力输入的回调
c++·游戏·ue5·游戏引擎·虚幻
AA陈超4 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-29 属性信息委托
c++·游戏·ue5·游戏引擎·虚幻
AA陈超4 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-31 映射标签到属性
c++·游戏·ue5·游戏引擎·虚幻
gshh__4 天前
SuperMap Hi-Fi 3D SDK for Unreal 使用蓝图接口加载多源数据
ue5·游戏引擎·supermap
zhangzhangkeji4 天前
cesium126,230331,Visualize Per-Feature Metadata - 1:官方教程
ue5
zhangzhangkeji5 天前
cesium126,230316,根据经纬度动态生成物体:主要使用了角色的 tag 属性,地球锚点也是有 tag 属性的
ue5
AA陈超5 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-28 构建属性菜单小部件控制器
c++·游戏·ue5·游戏引擎·虚幻
zhangzhangkeji5 天前
UE5 材质-17:水材质系列一 ,panner 平移节点,
ue5·材质
zhangzhangkeji8 天前
UE5 蓝图-24:主 mainUI界面蓝图,主菜单按钮事件定义,拆分按钮,color按钮,退出按钮
ue5
zhangzhangkeji9 天前
UE5 蓝图-11:本汽车蓝图的事件图表,汽车拆分事件,染色事件(绿蓝黄青)。
ue5·1024程序员节