UE5 学习笔记(持续更新中~)

1.定时器使用

//定义TimerHandle
FTimerHandle AttackDelayTimerHandle;

//检查是否激活定时器,若没有激活则SetTimer,0.2s后运行SetCanAttack函数
if (!GetWorld()->GetTimerManager().IsTimerActive(AttackDelayTimerHandle))
	{
		GetWorld()->GetTimerManager().SetTimer(AttackDelayTimerHandle, this, &ARPGCharacter::SetCanAttack, 0.2f, false);
	}

//记得用完关闭TimerHandle
GetWorld()->GetTimerManager().ClearTimer(AttackDelayTimerHandle);

2.Timeline

//定义Curve(相当于你想要的Timeline曲线),记得在编辑器里设置默认值
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UCurveFloat* MeleeCurve;

//定义每个Tick执行的Timeline函数,CurveOut为曲线Curve每个时刻对应的纵坐标值
UFUNCTION()
void OnMeleeCamTimelineTick(float CurveOut);	// Timeline 更新时调用

//BeginPlay中
if (MeleeCurve)
	{
		FOnTimelineFloat OnTimelineFloatEvent;
		OnTimelineFloatEvent.BindDynamic(this, &ARPGCharacter::OnMeleeCamTimelineTick);#定义每个Tick执行的函数
		MeleeCamTimeline.AddInterpFloat(MeleeCurve, OnTimelineFloatEvent);#使用曲线MeleeCurve
		MeleeCamTimeline.SetTimelineLength(ETimelineLengthMode::TL_LastKeyFrame);#定义Timeline长度
	}


3.LineTraceSingle(射线检测)

//获得检测开始位置
FVector Start = FollowCamera->GetComponentLocation();
//获得检测结束位置
FVector End = FollowCamera->GetForwardVector() * 5000 + Start;
//定义需要忽略检测的Actor
TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Add(GetOwner());
ActorsToIgnore.Add(BowRef);
//定义检测到的结果
FHitResult OutHit;
#判断是否检测到Actor
if (UKismetSystemLibrary::LineTraceSingle(this, Start, End, TraceTypeQuery1, false, ActorsToIgnore, EDrawDebugTrace::None, OutHit, true))
{
    //检测到后执行
}

4.读取DataTable

//定义待读取的DataTable
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UDataTable* ItemInfoDataTable;

//首先在空间中寻找是否有想要的枚举类型
const UEnum* EnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT("EItemNames"), true);
static const FString ContextString(TEXT("Find FMyTableTest"));
//判断是否找到枚举类型
if (EnumPtr)
{
    //将ItemName对应的枚举类型转为String
	FString str = EnumPtr->GetNameStringByIndex(static_cast<int32>(ItemName));
	if (ItemInfoDataTable)
	{
        //在DataTable中寻找是否有名为str的数据,并将数据赋予ItemData
		FItemInfo* ItemData = ItemInfoDataTable->FindRow<FItemInfo>(FName(str), ContextString, true);
		if (ItemData)
		{
			ItemInfo = *ItemData;
		}
	}
	else
	{
		UKismetSystemLibrary::PrintString(this, "error");
	}
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值