Unreal Engine添加UGameInstanceSubsystem子类

embedded/2024/9/24 13:43:16/
  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.ppmy.cn/embedded/18573.html

相关文章

Visual Studio C++ 示例

Visual Studio C 示例 项目2023/06/163 个参与者 反馈 本文内容 GitHub 上的存档 C 示例ATL 示例CLR 和语言示例 - Windows 窗体COM 事件示例 显示另外 13 个 Visual Studio C 示例可在 Web 上找到。 Microsoft 已生成许多 C 示例&#xff0c;这些示例演示了跨多种技术的…

Vue入门篇:生命周期,钩子函数,工程化开发Vue(脚手架安装),组件化开发(全局注册,局部注册)

目录 1.Vue生命周期和生命周期的四个阶段2.Vue生命周期函数&#xff08;钩子函数)3.工程化开发&脚手架Vue CLI1.在powershell管理员权限下打开命令行安装脚手架&#xff1a;2.查看vue版本&#xff1a;3.创建项目架子4.运行项目 4.组件化开发&根组件1.App.vue文件&#…

SpringBoot中多数据源灵活切换解决方案

本篇内容介绍了“SpringBoot中如何使用Dynamic Datasource配置多数据源”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成! 源码地址/文档说明 功能特性: 支持 数据源分组…

Xcode for Mac:强大易用的集成开发环境

Xcode for Mac是一款专为苹果开发者打造的集成开发环境&#xff08;IDE&#xff09;&#xff0c;它集成了代码编辑器、编译器、调试器等一系列开发工具&#xff0c;让开发者能够在同一界面内完成应用的开发、测试和调试工作。 Xcode for Mac v15.2正式版下载 Xcode支持多种编程…

【TensorFlow深度学习】数据统计在深度学习中的重要性

数据统计在深度学习中的重要性 1. 数据统计的基础概念2. 数据统计在TensorFlow中的实现2.1 张量范数2.2 归约操作2.2.1 计算最大值和最小值2.2.2 计算均值和总和 2.3 损失函数的统计2.3.1 均方误差 2.4 模型性能的统计2.4.1 准确率 3. 数据统计在模型训练中的应用3.1 学习率调整…

8.4.3 使用3:配置单臂路由实现VLAN间路由

1、实验目的 通过本实验可以掌握&#xff1a; 路由器以太网接口上的子接口配置和调试方法。单臂路由实现 VLAN间路由的配置和调试方法。 2、实验拓扑 实验拓扑如下图所示。 3、实验步骤 &#xff08;1&#xff09;配置交换机S1 S1(config)#vlan 2 S1(config-vlan)#exit S…

鸿蒙OpenHarmony【轻量系统 编译】 (基于Hi3861开发板)

编译 OpenHarmony支持hb和build.sh两种编译方式。此处介绍hb方式&#xff0c;build.sh脚本编译方式请参考[使用build.sh脚本编译源码]。 使用build.sh脚本编译源码 进入源码根目录&#xff0c;执行如下命令进行版本编译。 ./build.sh --product-name name --ccache 说明&…

快手面试算法真题

按照html中的标签层数遍历节点名。 例如&#xff1a;html代码如下&#xff1a;(上面的数字表示层数) <!-- 1 --><div class"div1"><!-- 2 --><span class"span1"></span><!-- 2 --><p class"p1"><…