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

UE5运行时创建slate窗口

加入"Slate","SlateCore"模块

Actor.cpp

// Fill out your copyright notice in the Description page of Project Settings.#include "MyWindowClass.h"// Sets default values
AMyWindowClass::AMyWindowClass()
{// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = true;
}// Called when the game starts or when spawned
void AMyWindowClass::BeginPlay()
{Super::BeginPlay();// Create a new SWindowTSharedRef<SWindow> NewWindow = SNew(SWindow).AutoCenter(EAutoCenter::PreferredWorkArea).SupportsMaximize(false).SupportsMinimize(false).SizingRule(ESizingRule::Autosized).CreateTitleBar(true)[// Add content to the window (for example, a vertical box with text)SNew(SVerticalBox)+ SVerticalBox::Slot().HAlign(HAlign_Center).VAlign(VAlign_Fill)[SNew(STextBlock).Text(FText::FromString("Hello, this is a new window!"))]];// Add the window to the Slate applicationFSlateApplication::Get().AddWindow(NewWindow);
}// Called every frame
void AMyWindowClass::Tick(float DeltaTime)
{Super::Tick(DeltaTime);
}

运行时创建scolorpicer窗口

加入"AppFramework","Slate","SlateCore"模块

// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActorClass.generated.h"UCLASS()
class MYCOLORPICERT_API AMyActorClass : public AActor
{GENERATED_BODY()public:// Sets default values for this actor's propertiesAMyActorClass();protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;public:// Called every framevirtual void Tick(float DeltaTime) override;TSharedPtr<SWindow> ColorPickerWindow;
};
// Fill out your copyright notice in the Description page of Project Settings.#include "MyActorClass.h"#include "Widgets/Colors/SColorPicker.h"// Sets default values
AMyActorClass::AMyActorClass()
{// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = true;
}// Called when the game starts or when spawned
void AMyActorClass::BeginPlay()
{Super::BeginPlay();// 创建一个新的 Slate 窗口ColorPickerWindow = SNew(SWindow).Title(FText::FromString("Color Picker"))//.ClientSize(FVector2D(400, 300)) // 设置窗口尺寸.IsTopmostWindow(true) // 保持在最前面.SizingRule(ESizingRule::Autosized)[SNew(SColorPicker)];// 将窗口添加到 UI 层FSlateApplication::Get().AddWindow(ColorPickerWindow.ToSharedRef());}void AMyActorClass::EndPlay(const EEndPlayReason::Type EndPlayReason)
{Super::EndPlay(EndPlayReason);if (ColorPickerWindow){FSlateApplication::Get().RequestDestroyWindow(ColorPickerWindow.ToSharedRef());}
}// Called every frame
void AMyActorClass::Tick(float DeltaTime)
{Super::Tick(DeltaTime);
}

http://www.lryc.cn/news/484237.html

相关文章:

  • 浅谈C#之单线程流式适配器
  • 【更新中】《硬件架构的艺术》笔记(三):处理多个时钟
  • 【matlab】数据类型01-数值型变量(整数、浮点数、复数、二进制和十六进制)
  • 引入第三方jar包部署服务器后找不到jar处理方法
  • neo4j desktop基本入门
  • 前端系统设计面试题(二)Javascript\Vue
  • 军工行业运维:监控易引领自主可控新潮流
  • unity3d————接口基础知识点
  • 蓝队基础5 -- 安全策略与防护技术
  • 【Bluedroid】A2dp初始化流程源码分析
  • Redis简介、数据结构、高性能读写、持久化机制、分布式架构
  • 鸿蒙自定义UI组件导出使用
  • python os.path.join 详解
  • JavaScript高效处理CSV文件的操作指南
  • Go开发指南- Goroutine
  • Dubbo 3.x源码(24)—Dubbo服务引用源码(7)接口级服务发现订阅refreshInterfaceInvoker
  • 高级java每日一道面试题-2024年11月04日-Redis篇-Redis如何做内存优化?
  • 数据结构 -二叉搜索树
  • Ubuntu配置阿里云docker apt源
  • 【React】状态管理之Redux
  • 3195. 有趣的数-13年12月CCF计算机软件能力认证(组合数)
  • 基于 Python 的 Bilibili 评论分析与可视化
  • 大语言模型理论基础
  • 【 LLM论文日更|检索增强:大型语言模型是强大的零样本检索器 】
  • 【基于轻量型架构的WEB开发】课程 作业3 Spring框架
  • 14.最长公共前缀-力扣(LeetCode)
  • 客户案例|智能进化:通过大模型重塑企业智能客服体验
  • Flink Job更新和恢复
  • 读多写少业务中,MySQL如何优化数据查询方案?
  • Bugku CTF_Web——点login咋没反应