Gameplay Classes
每个虚幻游戏类都是一个.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()宏必须放在类的开始。
类说明符:
说明符可以控制类与引擎以及编辑器的各方面的行为。
类构造函数:
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::CreateComponent和ConstructorHelpers::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的更多相关文章
- 从Unity引擎过度到Unreal4引擎(最终版)
原文地址:http://demo.netfoucs.com/u011707076/article/details/44036839 前言 寒假回家到现在已经有十多天了,这些天回家不是睡就是吃....哎 ...
- [Unity3D] C# Basic : Gameplay Scripting
教程:https://unity3d.com/cn/learn/tutorials/s/scripting 补充:http://www.runoob.com/csharp/csharp-inherit ...
- 代码的坏味道(9)——异曲同工的类(Alternative Classes with Different Interfaces)
坏味道--异曲同工的类(Alternative Classes with Different Interfaces) 特征 两个类中有着不同的函数,却在做着同一件事. 问题原因 这种情况往往是因为:创 ...
- eclipse中的classes文件夹同步问题
问题: 在同步项目时,由于误操作将classes文件夹加入到了同步版本中,这样会导致每次更新程序编译后,会有很多class文件显示在同步清单中. 解决方案: 将classes文件不设置为同步. 1. ...
- Introduction of OpenCascade Foundation Classes
Introduction of OpenCascade Foundation Classes Open CASCADE基础类简介 eryar@163.com 一.简介 1. 基础类概述 Foundat ...
- 6.Configure Domain Classes(配置领域类)【EF Code-First 系列】
在前面的部分中,我们学习了Code-First默认约定,Code-First使用默认的约定,根据你的领域类,然后生成概念模型. Code-First模式,发起了一种编程模式:约定大于配置.这也就是说, ...
- app:clean classes Exception
Error:Execution failed for task ':app:clean'.> Unable to delete directory: C:\Users\LiuZhen\Deskt ...
- Android framework编译出来的jar包classes.jar的位置
在源码环境下编译 Android framework编译出来的jar包classes.jar的位置 out/target/common/obj/JAVA_LIBRARIES/framework_in ...
- 《InsideUE4》GamePlay架构(十)总结
世界那么大,我想去看看 引言 通过对前九篇的介绍,至此我们已经了解了UE里的游戏世界组织方式和游戏业务逻辑的控制.行百里者半九十,前述的篇章里我们的目光往往专注在于特定一个类或者对象,一方面固然可以让 ...
随机推荐
- P1111 修复公路(并查集)
题目背景 AA地区在地震过后,连接所有村庄的公路都造成了损坏而无法通车.政府派人修复这些公路. 题目描述 给出A地区的村庄数NN,和公路数MM,公路是双向的.并告诉你每条公路的连着哪两个村庄,并告诉你 ...
- java——利用生产者消费者模式思想实现简易版handler机制
参考教程:http://www.sohu.com/a/237792762_659256 首先说一下这里面涉及到的线程: 1.mainLooper: 这个线程可以理解为消费者线程,里面运行了一个死循环, ...
- redis初步学习 0
2.1 Redis是什么 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统.Redis提供了一些丰富的数据 ...
- centos7.3 安装cuda8.0的 坑
1. 安装依赖 yum -y install gcc-c++yum -y install epel-releaseyum -y install --enablerepo=epel dkmsyum -y ...
- OpenStack Weekly Rank 2015.07.27
Module Reviews Drafted Blueprints Completed Blueprints Filed Bugs Resolved Bugs Cinder 7 1 1 7 10 Sw ...
- SUN巡检命令
# hostname (主机名)# hostid# uname -X# uname -a # w (进程)# who# last# ps -eaf# /usr/ucb/ps -aux# prstat ...
- c++隐式类型转换和explicit
什么是隐式转换? 众所周知,C++的基本类型中并非完全的对立,部分数据类型之间是可以进行隐式转换的. 所谓隐式转换,是指不需要用户干预,编译器私下进行的类型转换行为.很多时候用户可能都不知道进行了哪些 ...
- Oauth服务端协议开发
授权流程图 AS : Authorization Server (权限服务器) RS : Resource Server (资源服务器) Client :Client RS(资源服务器)流程图 以上仅 ...
- 前端性能优化-keep-alive
什么是Keep-Alive Keep-Alive是浏览器端和服务器端约定的一种提高传输效率的协议.我先举个例子吧,我现在搬家,有10个箱子,如果我自己来搬的话,每次只能带一个箱子,那么搬到目的地,需要 ...
- centos6.3 配置防火墙,开启80端口、3306端口
vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火 ...