Unreal Engine ClassName Rule
Unreal
- 🎯 ClassName Rule
- **AActor 前缀规则**
- **SWidget 前缀规则**
- **UObject 前缀规则**
- 🔧 数据类型命名规则
- **布尔变量前缀规则**
- **结构体前缀规则**
- **枚举前缀规则**
- **模板类前缀规则**
- 📝 通用命名规则
- **默认命名规则**
- 🎨 命名样式定义
- **PascalCase 样式**
- **前缀样式规则**
- 🎮 实际应用示例
🎯 ClassName Rule
AActor 前缀规则
cpp_naming_rule.aactor_prefixed.symbols = aactor_class
cpp_naming_rule.aactor_prefixed.style = aactor_style
含义:所有继承自 AActor
的类必须以字母 A
开头
示例:ACharacter
, APlayerController
, AWeapon
SWidget 前缀规则
cpp_naming_rule.swidget_prefixed.symbols = swidget_class
cpp_naming_rule.swidget_prefixed.style = swidget_style
含义:所有继承自 SWidget
的 Slate UI 类必须以字母 S
开头
示例:SButton
, STextBlock
, SScrollBox
UObject 前缀规则
cpp_naming_rule.uobject_prefixed.symbols = uobject_class
cpp_naming_rule.uobject_prefixed.style = uobject_style
含义:所有继承自 UObject
的类必须以字母 U
开头
示例:UGameInstance
, UAsset
, UComponent
🔧 数据类型命名规则
布尔变量前缀规则
cpp_naming_rule.booleans_prefixed.symbols = boolean_vars
cpp_naming_rule.booleans_prefixed.style = boolean_style
含义:所有 bool
类型的变量必须以 b
开头
示例:bIsVisible
, bHasWeapon
, bIsRunning
结构体前缀规则
cpp_naming_rule.structs_prefixed.symbols = structs
cpp_naming_rule.structs_prefixed.style = unreal_engine_structs
含义:所有结构体必须以字母 F
开头
示例:FVector
, FRotator
, FTransform
枚举前缀规则
cpp_naming_rule.enums_prefixed.symbols = enums
cpp_naming_rule.enums_prefixed.style = unreal_engine_enums
含义:所有枚举类型必须以字母 E
开头
示例:EObjectType
, EWeaponType
, EPlayerState
模板类前缀规则
cpp_naming_rule.templates_prefixed.symbols = templates
cpp_naming_rule.templates_prefixed.style = unreal_engine_templates
含义:所有模板类必须以字母 T
开头
示例:TArray
, TMap
, TSet
📝 通用命名规则
默认命名规则
cpp_naming_rule.general_names.symbols = all_symbols
cpp_naming_rule.general_names.style = unreal_engine_default
含义:所有其他标识符使用 PascalCase(首字母大写)
示例:PlayerName
, HealthValue
, CalculateDamage()
🎨 命名样式定义
PascalCase 样式
cpp_naming_style.unreal_engine_default.capitalization = pascal_case
含义:每个单词首字母大写,无分隔符
示例:GameManager
, PlayerCharacter
前缀样式规则
E
+ PascalCase → 枚举:EWeaponType
T
+ PascalCase → 模板:TArray<int32>
F
+ PascalCase → 结构体:FVector
U
+ PascalCase → UObject 派生类:UGameInstance
A
+ PascalCase → Actor 派生类:ACharacter
S
+ PascalCase → Slate 控件:SButton
b
+ PascalCase → 布尔变量:bIsActive
🎮 实际应用示例
// ✅ 正确的 UE 命名
class AMyCharacter : public AActor {}; // A 前缀
class UMyComponent : public UObject {}; // U 前缀
struct FPlayerData { // F 前缀bool bIsAlive; // b 前缀(布尔)int32 Health; // PascalCase
};
enum EWeaponType { // E 前缀Sword,Gun
};
template<typename T>
class TMyContainer {}; // T 前缀// ❌ 错误的命名(会产生警告)
class MyCharacter : public AActor {}; // 缺少 A 前缀
struct PlayerData {}; // 缺少 F 前缀
bool IsAlive; // 缺少 b 前缀
这些规则确保了 Unreal Engine 代码库的一致性和可读性!