当前位置: 首页 > news >正文

虚幻C++基础 day4

虚幻中的UI

  • 虚幻中的比较常用的UI:Widget Blueprint又称UMG
  • 虚幻中的两种布局:
    • 网格布局
    • 锚布局
  • 创建Widget Blueprint
    在这里插入图片描述

网格布局

  • 有点类似Qt中的网格布局,将UI面板进行行列切分
  • Horizontal Box:水平分布
  • Vertical Box:垂直分布
  • 这里的size是采用分布制,填充满值为1,一个为0.2,一个0.8就会使两个Vertical布局分为20%,80%站位
    在这里插入图片描述
    在这里插入图片描述

锚布局

  • Canvas Panel:添加一个画布组
  • Progress Bar:进度条控件时一个简单条状物,可以进行多风格进行填充,满足不同使用需求
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

将用户创建的UI放置到主UI上

在这里插入图片描述

创建金币计数UI放置到主UI

在这里插入图片描述
在这里插入图片描述

为代码工程添加UMG模块显示到视口

  • 在GameMode中去管理UMG,在游戏开始的时候,显示主UI
  • 添加UI到模块中
    在这里插入图片描述
  • 思路:新建两个变量一个用来选择UMG类型(模版类),一个用来实例化(类指针),重写BeginPlay函数来添加UMG到视口

Level1GameMode.h

// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "UEGameGameModeBase.h"
#include "Level1GameMode.generated.h"/*** */
UCLASS()
class UEGAME_API ALevel1GameMode : public AUEGameGameModeBase
{GENERATED_BODY()
public://模版类UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UI Widgets")TSubclassOf<class UUserWidget> MainUiclass;UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "UI Widgets")UUserWidget* MainUI;
protected:virtual void BeginPlay() override;
};

Level1GameMode.cpp

  • CreateWidget:创建Widget,头文件#include "Blueprint/UserWidget.h"
  • UGameplayStatics:UGameplayStatics是一个很实用的静态类,我们不需要拥有指向此类的任何实例的指针,并且可以直接从任何地方调用函数。头文件#include "Kismet/GameplayStatics.h"
  • MainUI = CreateWidget<UUserWidget>(UGameplayStatics::GetPlayerController(this, 0), MainUiclass);
    • UGameplayStatics::GetPlayerController(this, 0):获取角色的控制器,因为是单机只有一个玩家第二个参数就是0
  • AddToViewport:添加视口
// Fill out your copyright notice in the Description page of Project Settings.#include "Level1GameMode.h"
#include "Blueprint/UserWidget.h"
#include "Kismet/GameplayStatics.h"
void ALevel1GameMode::BeginPlay()
{if (MainUiclass){MainUI = CreateWidget<UUserWidget>(UGameplayStatics::GetPlayerController(this, 0), MainUiclass);if (MainUI){MainUI->AddToViewport();}}
}
http://www.lryc.cn/news/225905.html

相关文章:

  • 【Vue】【uni-app】工单管理页面实现
  • 【系统架构设计】架构核心知识: 2.1 软件过程模型
  • 数据管理系统-week1-文件系统、数据库和数据库管理系统
  • 探索OpenCV中直方图的神奇之处:应用与实现
  • MapReduce编程——矩阵乘法(Python版本)
  • nature日报:为什么印度德里现在的空气污染如此严重?
  • ChatGPT、GPT-4 Turbo接口调用
  • IDEA中常用的调试快捷键
  • 需要设计易清洗的口琴
  • 贝锐蒲公英智慧运维方案:实现远程网络监控、管理、维护工业设备
  • Intel oneAPI笔记(4)--jupyter官方文档(Unified Shared Memory)学习笔记
  • dRep-基因组质控、去冗余及物种界定
  • 截图贴图软件推荐 - 附下载链接 | Snipaste | Steuna
  • python调用chrome实现网页自动操作
  • FFMPEG库实现mp4/flv文件(H264+AAC)的封装与分离
  • 《红蓝攻防对抗实战》九.内网穿透之利用GRE协议进行隧道穿透
  • 大数据毕业设计选题推荐-智慧消防大数据平台-Hadoop-Spark-Hive
  • LeetCode 面试题 16.20. T9键盘
  • systemctl enable docker.service报错“Failed to execute operation: Bad message“
  • 向量的范数、矩阵的范数
  • C# OpenCvSharp 玉米粒计数
  • 前端缓存机制——强缓存、弱缓存、启发式缓存
  • 对称密钥加密与非对称密钥加密:原理与应用
  • 商品小类管理实现B
  • Unity--视觉组件(Raw Image,Mask)||Unity--视觉组件(Text,Image)
  • 在Node.js中,什么是事件发射器(EventEmitter)?
  • STM32——NVIC中断优先级管理分析
  • YOLOV5----修改损失函数-SimAM
  • MongoDB单实例安装(windows)
  • Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: