• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

UE4部分

武飞扬头像
wb175208
帮助1

1. 日志打印到屏幕上

#include "Engine/Engine.h"
FString Print = FString::Printf(TEXT("DeltaTime: %f"),DeltaTime);
GEngine->AddOnScreenDebugMessage(1, 1.5f, FColor::Cyan,Print, false);

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "123789!!!!");

GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("Result:%d, %d,%f"), bVal ? 1:0, intVal, floatVal));
#include "Kismet/KismetSystemLibrary.h"
UKismetSystemLibrary::PrintString(this, TEXT("1234646"));

2. 重新开始关卡游戏

GetWorld()->GetFirstPlayerController()->ConsoleCommand(TEXT("RestartLevel"));

相当于在游戏窗口输入命令:RestartLevel
学新通

3. 弹出菜单

void AFlyingPawn::popMenu() {
    FMenuBuilder MenuBuilder(true, nullptr);
    MenuBuilder.BeginSection("PathFolderMoveCopy", FText::FromString(TEXT("Game")));
	{
	/**
	* 事件到弹出菜单,重新开始游戏
	*/
		MenuBuilder.AddMenuEntry(
			FText::FromString(TEXT("Time Out")),
			FText::FromString(TEXT("DeleteItem")),
			FSlateIcon(),
			FUIAction(FExecuteAction::CreateLambda([this]() {
				DeleteThisData();
				}))
		);
	}
	MenuBuilder.EndSection();

	TSharedPtr< SWindow > Parent = FSlateApplication::Get().GetActiveTopLevelWindow();
	if (Parent.IsValid()) {
		FSlateApplication::Get().PushMenu(
			Parent.ToSharedRef(),
			FWidgetPath(),
			MenuBuilder.MakeWidget(),
			FSlateApplication::Get().GetCursorPos(),
			FPopupTransitionEffect(FPopupTransitionEffect::ContextMenu)
		);
	}
}

void AFlyingPawn::DeleteThisData() {
	//重新开始游戏
	GetWorld()->GetFirstPlayerController()->ConsoleCommand(TEXT("RestartLevel"));
}
学新通

4.显示鼠标

 		//设置游戏和界面都可以使用鼠标
        APlayerController* controller = GetWorld()-> GetFirstPlayerController();
        controller->bShowMouseCursor = true;//显示鼠标

5.游戏暂停/继续

//true - 暂停 false - 继续
UGameplayStatics::SetGamePaused(GetWorld(), true);

6.获取游戏时间(秒)

 float time = UGameplayStatics::GetTimeSeconds(GetWorld());

7.获取所有的粒子系统

 //获取所有的粒子系统,烟雾粒子和爆炸粒子系统
	TArray<UParticleSystemComponent*> Jets;
	GetComponents(Jets, true); // true表示获取子Actor的组件
	for (int32 i = 0; i < Jets.Num(); i  ) {
        FString name = Jets[i]->GetName();
        if (name == TEXT("SmokeParticleSystem")) {
            smokeParticle = Jets[i];
            //关闭特效
            smokeParticle->Activate(false);
            smokeParticle->bAutoActivate = false;
            smokeParticle->SetVisibility(false);
		} else if (name == TEXT("ExplodePartcileSystem")) {
            explodePartcileComponent = Jets[i];
            explodePartcileComponent->Activate(false);
            explodePartcileComponent->bAutoActivate = false;
		}
	}
学新通

8.获取所有的组件

//获取所有组件 aaa
	TArray<UStaticMeshComponent*> meshComps;
	GetComponents(meshComps, true); // true表示获取子Actor的组件
	for (int32 i = 0; i < meshComps.Num(); i  ) {
		FString name = meshComps[i]->GetName();
		if (name == TEXT("BodyMesh")) {
            uavBody = meshComps[i];
		} 
	}

9.播放声音cue文件

USoundCue* overlapSound;
UGameplayStatics::PlaySound2D(this, overlapSound);

10.浮点数转字符串

UE4只会打印小数点后面6位,超过的位数会四舍五入

	float num = 3.14159267;
	FString numStr = FString::SanitizeFloat(num);
	UKismetSystemLibrary::PrintString(this, numStr);

界面上会打印出来:3.141593

11.bool转字符串

	bool b = false;
	FString boolStr = UKismetStringLibrary::Conv_BoolToString(b);
	UKismetSystemLibrary::PrintString(this, boolStr);

界面打印:false
aaa

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgjcggh
系列文章
更多 icon
同类精品
更多 icon
继续加载