Unreal Engine添加UGameInstanceSubsystem子类

  1. 点击C++类文件夹,在右边的区域点击鼠标右键,在弹出的菜单中选择“新建C++类”
  2. 在弹出的菜单中选中“显示所有类”,选择GameInstanceSubsystem作为父类, 点击“下一步”按钮
  3. 输入子类名称“UVRVIUOnlineGameSubsystem”,选择插件作为新类的目标模块,点击“公共”选择器
  4. 打开C++工程,找到".Build.cs"文件,在“PublicDependencyModuleNames”下,添加"MultiPlayerPlugin"

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    public class LandMaster : ModuleRules

    {

        public LandMaster(ReadOnlyTargetRules Target) : base(Target)

        {

            PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

      

            PublicDependencyModuleNames.AddRange(new string[] { "Core""CoreUObject""Engine""InputCore""UMG""Http""Json""JsonUtilities""Sockets""Networking""OnlineSubsystem""OnlineSubsystemUtils""MultiPlayerPlugin" });

      

            PrivateDependencyModuleNames.AddRange(new string[] { "Slate""SlateCore" });

        }

    }

  5. 设置“MultiPlayerPlugin.uplugin”文件

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    {

        "FileVersion": 3,

        "Version": 1,

        "VersionName""1.0",

        "FriendlyName""MultiPlayerPlugin",

        "Description""plugin for multi player ",

        "Category""Other",

        "CreatedBy""VRVIU_Jacky",

        "CreatedByURL""",

        "DocsURL""",

        "MarketplaceURL""",

        "SupportURL""",

        "EngineVersion""4.26.0",

        "CanContainContent"true,

        "Installed"true,

        "Modules": [

            {

                "Name""MultiPlayerPlugin",

                "Type""Runtime",

                "LoadingPhase""Default",

                "WhitelistPlatforms": [

                    "Win32",

                    "Win64"

                ]

            }

        ]

    }

  6. 设置插件“.Build.cs”文件,添加需要引用的模块

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    // Copyright Epic Games, Inc. All Rights Reserved.

      

    using UnrealBuildTool;

      

    public class MultiPlayerPlugin : ModuleRules

    {

        public MultiPlayerPlugin(ReadOnlyTargetRules Target) : base(Target)

        {

            bEnableUndefinedIdentifierWarnings = false;

            PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

            //bUsePrecompiled = true;

            PublicIncludePaths.AddRange(

                new string[] {

                    "MultiPlayerPlugin/Public"

                }

                );

                      

              

            PrivateIncludePaths.AddRange(

                new string[] {

                      

                }

                );

                  

              

            PublicDependencyModuleNames.AddRange(

                new string[]

                {

                    "Core"

                    // ... add other public dependencies that you statically link with here ...

                }

                );

                  

              

            PrivateDependencyModuleNames.AddRange(

                new string[]

                {

                    "CoreUObject",

                    "Engine",

                    "Slate",

                    "SlateCore""UMG""Http""Json""JsonUtilities""Sockets""Networking"

                    // ... add private dependencies that you statically link with here ... 

                }

                );

              

              

            DynamicallyLoadedModuleNames.AddRange(

                new string[]

                {

                    // ... add any modules that your module loads dynamically here ...

                }

                );

        }

    }

  7. 获取本机IP地址

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    FString UVRVIUOnlineGameSubsystem::GetIpAddress(bool bHasPort /*= true*/)

    {

        FString IpAddr("NONE");

        bool canBind = false;

        TSharedRef<FInternetAddr>LocalIp = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLocalHostAddr(*GLog, canBind);

        if (LocalIp->IsValid())

        {

            IpAddr = LocalIp->ToString(bHasPort);

        }

        return IpAddr;

    }

  8. 创建会话

    1

    2

    3

    FString cmd = "open " + Map + "?listen";

    UGameplayStatics::GetPlayerController(GetWorld(), 0)->ConsoleCommand(cmd);

    m_ServerAddress = ServerAddress.Len() == 0 ? GetIpAddress(false):ServerAddress;

  9. 加入会话

    1

    2

    3

    4

    5

    UE_LOG(LogTemp, Warning, TEXT("UVRVIUOnlineGameSubsystem::ConnectServer %s"), *IntranetIP);

    FString cmd = "open " + IntranetIP;

    UGameplayStatics::GetPlayerController(GetWorld(), 0)->ConsoleCommand(cmd);

    m_ServerAddress = IntranetIP;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/651991.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

elasticsearch-8.1.0安装记录

目录 零、版本说明一、安装二、使用客户端访问 零、版本说明 centos [rootnode1 ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core)elasticsearch elasticsearch-8.1.0-linux-x86_64一、安装 systemctl stop firewalld.servicesystemctl disable firewal…

Magnet for Mac:高效窗口管理工具

Magnet for Mac是一款专为Mac用户设计的窗口管理工具&#xff0c;旨在帮助用户更高效地管理和布局多个应用程序窗口&#xff0c;提升工作效率。 Magnet for Mac v2.14.0中文免激活版下载 这款软件拥有直观易用的界面和丰富的功能&#xff0c;支持用户将屏幕分割成多个区域&…

ssm智能停车场管理系统

视频演示效果: SSMvue智能停车场 摘 要 本论文主要论述了如何使用JAVA语言开发一个智能停车场管理系统&#xff0c;本系统将严格按照软件开发流程进行各个阶段的工作&#xff0c;采用B/S架构&#xff0c;面向对象编程思想进行项目开发。在引言中&#xff0c;作者将论述智能停车…

WEB攻防-PHP特性-函数缺陷对比

目录 和 MD5函数 intval ​strpos in_array preg_match str_replace 和 使用 时&#xff0c;如果两个比较的操作数类型不同&#xff0c;PHP 会尝试将它们转换为相同的类型&#xff0c;然后再进行比较。 使用 进行比较时&#xff0c;不仅比较值&#xff0c;还比较变量…

Vuforia AR篇(四)— AR虚拟按钮

目录 前言一、创建虚拟按钮二、创建脚本三、效果 前言 在当今互联网和移动设备普及的背景下&#xff0c;**增强现实&#xff08;AR&#xff09;**技术正迅速成为连接现实世界与数字信息的重要桥梁。AR虚拟按钮作为这一技术的创新应用&#xff0c;不仅提供了一种全新的用户交互…

uniapp 微信小程序 分享海报的实现

主页面 <template><view class"page"><!-- 自定义导航栏--><Navbar title"我的海报"></Navbar><view class"container"><poster ref"poster" :imageUrl"image" :imageWidth"7…

基于STC12C5A60S2系列1T 8051单片机正常模式或移位模式控制数码管某位闪烁后单击长按增加或减少数值应用

基于STC12C5A60S2系列1T 8051单片机正常模式或移位模式控制数码管某位闪烁后单击长按增加或减少数值应用 STC12C5A60S2系列1T 8051单片机管脚图STC12C5A60S2系列1T 8051单片机I/O口各种不同工作模式及配置STC12C5A60S2系列1T 8051单片机I/O口各种不同工作模式介绍基于STC12C5A6…

数据结构与算法解题-20240426

这里写目录标题 面试题 08.04. 幂集367. 有效的完全平方数192. 统计词频747. 至少是其他数字两倍的最大数718. 最长重复子数组 面试题 08.04. 幂集 中等 幂集。编写一种方法&#xff0c;返回某集合的所有子集。集合中不包含重复的元素。 说明&#xff1a;解集不能包含重复的子…

React真的好难用

我发现React就像个宗教一样&#xff0c;网络上总有一群信徒。信徒&#xff1a;React天下第一&#xff0c;谁也不能说他不好。 网络上大佬对React的评价一般有几类&#xff1a; React跟Vue比就是手动档和自动档的区别&#xff0c;高手都开手动档。—— 就一个破打工的&#xf…

06.Cesium快速上手-Primitive图元的讲解

Primitive 结构图解&#xff1a; 图元表示 Scene 中的几何图形。几何图形可以来自单个 GeometryInstance 例子1&#xff1a; // Create the viewer. const viewer new Cesium.Viewer("cesiumContainer"); const scene viewer.scene;// Draw a red box and po…

SpringCloud系列(18)--将服务提供者Provider注册进Consul

前言&#xff1a;在上一章节中我们把服务消费者Consumer注册进了Zookeeper&#xff0c;并且成功通过服务消费者Consumer调用了服务提供者Provider&#xff0c;而本章节则是关于如何将服务提供者Provider注册进Consul里 准备环境&#xff1a; 先安装Consul&#xff0c;如果没有…

【系统架构师】-选择题(四)

1、“41”视图 ①逻辑视图(Logical View)&#xff0c;设计的对象模型(使用面向对象的设计方法时)。 ②过程视图(Process View)&#xff0c;捕捉设计的并发和同步特征。系统集成师 ③物理视图(Physical View)&#xff0c;描述了软件到硬件的映射&#xff0c;反映了分布式特性。系…