UE4-笔记-通用功能实现逻辑例子

记一些自己实现的通用化功能的例子.

Q.双击模拟(应用于二段跳/双击W加速跑等):

推荐用C++实现的,BP不好维护 搜索定位=_,=

BP:

宏实现:

C++实现:

---------- 割割割 -----------

.h文件:

UENUM(BlueprintType)
enum class EM_ClickType : uint8
{
    EM_FisrtClick    UMETA(DisplayName = "FisrtClick"),
    EM_DoubleClick    UMETA(DisplayName = "DoubleClick")
};

UCLASS()
class UBPLibrary_CommonDemonstrate : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()
public:
    UFUNCTION(BlueprintCallable, meta = (DeterminesOutputType = "actorClass"))
        static EM_ClickType DoubleClick();
};

cpp文件:

EM_ClickType UCppBPLibrary_CommonDemonstrate::DoubleClick()
{
    static bool bReadyOnce = false;
    if (bReadyOnce)
    {
        bReadyOnce = false;
        return  EM_ClickType::EM_DoubleClick;// double click
    }
    else
    {
        bReadyOnce = true;
        TFuture<void> future = Async<void>(EAsyncExecution::TaskGraph, [=]
        {
            FPlatformProcess::Sleep(0.25);
            if (bReadyOnce)
            {
                bReadyOnce = false;
                return;
            }
        });

        return  EM_ClickType::EM_FisrtClick; // first click
    }
}

使用:

猜你喜欢

转载自www.cnblogs.com/linqing/p/11226415.html