【UE4 C++】获取运行时间、设置时间流速、暂停游戏

66 篇文章 6 订阅

基于UGameplayStatics

获取运行时间

/** Returns the frame delta time in seconds, adjusted by time dilation. */
UFUNCTION(BlueprintPure, Category = "Utilities|Time", meta = (WorldContext="WorldContextObject"))
static float GetWorldDeltaSeconds(const UObject* WorldContextObject);

/** Returns time in seconds since world was brought up for play, adjusted by time dilation and IS stopped when game pauses */
UFUNCTION(BlueprintPure, Category="Utilities|Time", meta=(WorldContext="WorldContextObject"))
static float GetTimeSeconds(const UObject* WorldContextObject);

/** Returns time in seconds since world was brought up for play, adjusted by time dilation and IS NOT stopped when game pauses */
UFUNCTION(BlueprintPure, Category="Utilities|Time", meta=(WorldContext="WorldContextObject"))
static float GetUnpausedTimeSeconds(const UObject* WorldContextObject);

/** Returns time in seconds since world was brought up for play, does NOT stop when game pauses, NOT dilated/clamped */
UFUNCTION(BlueprintPure, Category="Utilities|Time", meta=(WorldContext="WorldContextObject"))
static float GetRealTimeSeconds(const UObject* WorldContextObject);

/** Returns time in seconds since world was brought up for play, IS stopped when game pauses, NOT dilated/clamped. */
UFUNCTION(BlueprintPure, Category="Utilities|Time", meta=(WorldContext="WorldContextObject"))
static float GetAudioTimeSeconds(const UObject* WorldContextObject);

/** Returns time in seconds since the application was started. Unlike the other time functions this is accurate to the exact time this function is called instead of set once per frame. */
UFUNCTION(BlueprintPure, Category="Utilities|Time", meta=(WorldContext="WorldContextObject"))
static void GetAccurateRealTime(const UObject* WorldContextObject, int32& Seconds, float& PartialSeconds);

设置时间流速

  • 设置全局时间流速

    static float GetGlobalTimeDilation(const UObject* WorldContextObject);
    
    static void SetGlobalTimeDilation(const UObject* WorldContextObject, float TimeDilation);
    
  • 设置指定Actor时间流速

    AActor* MyActor;
    MyActor->CustomTimeDilation = 0.5f;
    

暂停游戏

static bool SetGamePaused(const UObject* WorldContextObject, bool bPaused);
static bool IsGamePaused(const UObject* WorldContextObject);
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值