每个虚幻游戏类都是一个.h和一个.cpp组成。

类在虚幻中有便准的命名模式。

前缀:

A
继承于可量产的游戏性类。他们都是Actor,可以直接在游戏中生成。

U
继承于所有游戏性对象。不能在游戏中直接生成,必须属于一个Actor。一般都是 Components.

在编辑器中使用C++ Class Wizard添加一个类,这样可以自动的更新游戏模块。生成的文件将会自动包含类声明和构造函数定义以及UCLACC()宏(以便引擎知道这个类的存在)。

每个游戏类都有各自的头文件。命名就是类名减去前缀。Actor.h的头文件是AActor

头文件使用标准c++语法加上一些宏来简化类、函数、变量的定义。

每个游戏类的开头应该包含生成头文件:#include "ClassName.generated.h"

UCLASS([specifier, specifier, ...], [meta(key=value, key=value, ...)])
class ClassName : ParentName
{
GENERATED_UCLASS_BODY()
}

GENERATED_UCLASS_BODY()宏必须放在类的开始。

类说明符:

说明符可以控制类与引擎以及编辑器的各方面的行为。

  • Abstract

  • AdvancedClassDisplay

  • AssetRegistrySearchable

  • AssetRegistrySearchable

  • AutoExpandCategories

  • Blueprintable

  • BlueprintType

  • ClassGroup

  • CollapseCategories

  • Config

  • Const

  • ConversionRoot

  • CustomConstructor

  • DefaultToInstanced

  • DependsOn

  • Deprecated

  • DontAutoCollapseCategories

  • DontCollapseCategories

  • EditInlineNew

  • HeaderGroup

  • HideCategories

  • HideDropdown

  • HideFunctions

  • Intrinsic

  • MinimalAPI

  • NoExport

  • NonTranisent

  • NotBlueprintable

  • NotPlaceable

  • PerObjectConfig

  • Placeable

  • ShowCategories

  • ShowFunctions

  • Transient

  • Within

  • 类构造函数:

    UObjects 使用构造函数来设置属性默认值和其他的变量,以及其他必要的初始化。

    可以直接在头文件中定义构造函数,但是必须把UCLASS指定为CustomConstructor,以防止自动生成器在头文件中生成一个构造函数声明。

    AMyClass::AMyClass(const FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
    {
    }
    参数:FPostConstructInitializeProperties结构对象用来对未初始化的属性进行初始化,这些初始化值来自原型和CDO(class default object)。
     
    对象属性的一次性构造:
    ATimelineTestActor::ATimelineTestActor(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
    {
    // Structure to hold one-time initialization
    struct FConstructorStatics
    {
    ConstructorHelpers::FObjectFinder<UStaticMesh> Object0;
    FConstructorStatics()
    : Object0(TEXT("StaticMesh'/Game/UT3/Pickups/Pickups/Health_Large/Mesh/S_Pickups_Base_Health_Large.S_Pickups_Base_Health_Large'"))
    {
    }
    };
    static FConstructorStatics ConstructorStatics; // Property initialization StaticMesh = ConstructorStatics.Object0.Object;
    }
    struct FConstructorStatics是一个一次性构造机构体,在构造函数中声明,且被定义为静态。这意味着构造函数中处于结构体内部的初始化工作仅仅只会在第一次构造的时候进行一次,以后的对象创建仅仅使用此静态对象即可。
    ConstructorHelpers是一个名字空间(其实是一个结构体)专门提供构造工具(这些工具也全部都是结构体或者结构体模板)。比如FObjectFinder<>。
    注意这里面的静态结构体是一种通用技巧,并不是仅仅在虚幻中有效。
     
    Asset引用:
    ATimelineTestActor::ATimelineTestActor(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
    {
    // Structure to hold one-time initialization
    struct FConstructorStatics
    {
    ConstructorHelpers::FObjectFinder<UStaticMesh> Object0;
    FConstructorStatics()
    : Object0(TEXT("StaticMesh'/Game/UT3/Pickups/Pickups/Health_Large/Mesh/S_Pickups_Base_Health_Large.S_Pickups_Base_Health_Large'"))
    {
    }
    };
    static FConstructorStatics ConstructorStatics; // Property initialization StaticMesh = ConstructorStatics.Object0.Object;
    }
    类引用:
    APylon::APylon(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
    {
    // Structure to hold one-time initialization
    struct FConstructorStatics
    {
    ConstructorHelpers::FClassFinder<UNavigationMeshBase> Class0;
    FConstructorStatics()
    : Class0(TEXT("class'Engine.NavigationMeshBase'"))
    {
    }
    };
    static FConstructorStatics ConstructorStatics; NavMeshClass = ConstructorStatics.Class0.Class;
    }
    指向一个UClass。
    大多数情况下,可以直接使用USomeClass::StaticClass()来避免使用ClassFinder的复杂性。
    NavMeshClass = UNavigationMeshBase::StaticClass();
    对于跨模块引用,使用ClassFinder更好。
     
    名称:
    APylon::APylon(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
    {
    // Structure to hold one-time initialization
    struct FConstructorStatics
    {
    FName NAME_Navigation;
    FConstructorStatics()
    : NAME_Navigation(TEXT("Navigation"))
    {
    }
    };
    static FConstructorStatics ConstructorStatics; SpriteCategoryName = ConstructorStatics.NAME_Navigation;
    }
     
    组件和子物体
    ConstructorHelpers::CreateComponentConstructorHelpers::FindComponent被用来创建和获取一个模块。
    AWindPointSource::AWindPointSource(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
    {
    // Structure to hold one-time initialization
    struct FConstructorStatics
    {
    FName NAME_Wind;
    FConstructorStatics()
    : NAME_Wind(TEXT("Wind"))
    {
    }
    };
    static FConstructorStatics ConstructorStatics; // Property initialization //Create a new component
    UWindPointSourceComponent* NewComponent0 = ConstructorHelpers::CreateComponent<UWindPointSourceComponent>(this, TEXT("WindPointSourceComponent0")); NewComponent0->PreviewRadiusComponent = NewComponent1;
    Component = NewComponent0;
    RootComponent = NewComponent0; //Create a new component
    UDrawSphereComponent* NewComponent1 = ConstructorHelpers::CreateComponent<UDrawSphereComponent>(this, TEXT("DrawSphereComponent0")); NewComponent1->ShapeColor.R = 173;
    NewComponent1->ShapeColor.G = 239;
    NewComponent1->ShapeColor.B = 231;
    NewComponent1->ShapeColor.A = 255; NewComponent1->AlwaysLoadOnClient = false;
    NewComponent1->AlwaysLoadOnServer = false;
    NewComponent1->bAbsoluteScale = true;
    NewComponent1->AttachParent = NewComponent0; //Find a component on the parent
    USpriteComponent* NewComponent2 = ConstructorHelpers::FindComponent<USpriteComponent>(this, TEXT("Sprite")); NewComponent2->SpriteCategoryName = ConstructorStatics.NAME_Wind;
    NewComponent2->AttachParent = NewComponent0; bNoDelete = true;
    }
    查找一个父类的组件一般是不必要的。因为父类的组件都已经被赋值到其属性上,所以直接使用属性就可以访问。如果不在属性中,推荐更改父类的构造函数,而不是使用FindComponet(),这个方法仅仅是用在标准方法无法满足要求的的情况下的。
     
    数组操作
    常规方法:
    Components.Add(NewComponent0);
    添加一个新元素到数组中。
    int32 NewArrayIndex1 = ConstructorHelpers::AddArrayElement(Components);
    Components(NewArrayIndex1) = NewComponent0;

Gameplay Classes的更多相关文章

  1. 从Unity引擎过度到Unreal4引擎(最终版)

    原文地址:http://demo.netfoucs.com/u011707076/article/details/44036839 前言 寒假回家到现在已经有十多天了,这些天回家不是睡就是吃....哎 ...

  2. [Unity3D] C# Basic : Gameplay Scripting

    教程:https://unity3d.com/cn/learn/tutorials/s/scripting 补充:http://www.runoob.com/csharp/csharp-inherit ...

  3. 代码的坏味道(9)——异曲同工的类(Alternative Classes with Different Interfaces)

    坏味道--异曲同工的类(Alternative Classes with Different Interfaces) 特征 两个类中有着不同的函数,却在做着同一件事. 问题原因 这种情况往往是因为:创 ...

  4. eclipse中的classes文件夹同步问题

    问题: 在同步项目时,由于误操作将classes文件夹加入到了同步版本中,这样会导致每次更新程序编译后,会有很多class文件显示在同步清单中. 解决方案: 将classes文件不设置为同步. 1. ...

  5. Introduction of OpenCascade Foundation Classes

    Introduction of OpenCascade Foundation Classes Open CASCADE基础类简介 eryar@163.com 一.简介 1. 基础类概述 Foundat ...

  6. 6.Configure Domain Classes(配置领域类)【EF Code-First 系列】

    在前面的部分中,我们学习了Code-First默认约定,Code-First使用默认的约定,根据你的领域类,然后生成概念模型. Code-First模式,发起了一种编程模式:约定大于配置.这也就是说, ...

  7. app:clean classes Exception

    Error:Execution failed for task ':app:clean'.> Unable to delete directory: C:\Users\LiuZhen\Deskt ...

  8. Android framework编译出来的jar包classes.jar的位置

    在源码环境下编译 Android framework编译出来的jar包classes.jar的位置  out/target/common/obj/JAVA_LIBRARIES/framework_in ...

  9. 《InsideUE4》GamePlay架构(十)总结

    世界那么大,我想去看看 引言 通过对前九篇的介绍,至此我们已经了解了UE里的游戏世界组织方式和游戏业务逻辑的控制.行百里者半九十,前述的篇章里我们的目光往往专注在于特定一个类或者对象,一方面固然可以让 ...

随机推荐

  1. Jenkins自动化CI CD流水线之5--pipeline

    一.概览 二.安装 在对jenkins进行初始化安装时,默认已经安装了jenkins的相关插件,如下图所示: 三.实操 新建任务: 编写pipeline脚本: 我们可以借助流水线语法去做. test流 ...

  2. python3 发送QQ邮件

    from email.header import Headerfrom email.mime.text import MIMETextfrom smtplib import SMTP_SSL emai ...

  3. Wireshark抓取TCP包分析

    介绍 本篇文章是使用wireshrak对某个https请求的tcp包进行分析. 目的 通过抓包实际分析了解tcp包. 准备工作 在我自己机子上安装的是wireshark2.2.6版本,随机查找了某个T ...

  4. UML箭头

    继承(泛化):用实线空心三角箭头表示 实现(接口):用虚线空心三角形箭头标示 依赖:虚线箭头,类A指向类B 方法参数需要传入另一个类的对象,就表示依赖这个类 关联:实线箭头,类A指向类B 一个类的全局 ...

  5. 对称加密中的ECB模式&CBC模式

    ECB模式: CBC模式: 所有的迭代模式:

  6. Git钩子设置自动构建Jenkins

    打开Git仓库,找到对应的项目,点击“仓库设置”,左侧点击“管理Git钩子”,如下图所示: 因为是push之后触发自动构建的,选择“post-receive”进行编辑 #!/bin/bash #提取分 ...

  7. Kubernetes中的nodePort,targetPort,port的区别和意义

    1. nodePort 外部机器可访问的端口. 比如一个Web应用需要被其他用户访问,那么需要配置type=NodePort,而且配置nodePort=30001,那么其他机器就可以通过浏览器访问sc ...

  8. IOS Intro - Property Synthesis

    http://www.thecodecrate.com/ios/objective-c/objective-c-property-synthesize/ 01. atomic              ...

  9. Magnum基本介绍

    Magnum is an OpenStack API service developed by the OpenStack Containers Team making container orche ...

  10. (转)Linux curl命令详解

    命令:curl在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具.它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具. ...