UEC++ 创建自定义类型案例

发布时间:2026/11/14 13:47:55

UEC++ 创建自定义类型案例 一子弹类型// .h文件 #include CoreMinimal.h #include GameFramework/Actor.h #include Components/SphereComponent.h #include GameFrameWork/ProjectileMovementComponent.h #include MyActor.generated.h // ... UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUStaticMeshComponent Sphere; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUSphereComponent SphereCollision; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUProjectileMovementComponent ProjectileMovement;// .cpp文件 AMyActor::AMyActor() { PrimaryActorTick.bCanEverTick true; Sphere CreateDefaultSubobjectUStaticMeshComponent(TEXT(Sphere)); SphereCollision CreateDefaultSubobjectUSphereComponent(TEXT(SphereCollision)); ProjectileMovement CreateDefaultSubobjectUProjectileMovementComponent(TEXT(ProjectileMovement)); static ConstructorHelpers::FObjectFinderUStaticMesh StaticSphereMesh(TEXT(/Engine/BasicShapes/Sphere.Sphere)); RootComponent Sphere; SphereCollision-SetupAttachment(RootComponent); ProjectileMovement-SetUpdatedComponent(RootComponent); Sphere-SetStaticMesh(StaticSphereMesh.Object); ProjectileMovement-InitialSpeed 500.0; ProjectileMovement-MaxSpeed 2000.0; }二带有增强输入的角色类型// .h文件 #include CoreMinimal.h #include InputActionValue.h #include EnhancedInputComponent.h #include EnhancedInputSubsystems.h #include GameFramework/Controller.h #include GameFramework/SpringArmComponent.h #include Camera/CameraComponent.h #include GameFramework/Character.h #include GameFramework/CharacterMovementComponent.h #include MyCharacter.generated.h class UInputAction; class UInputMappingContext; // ... public: UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUSpringArmComponent SpringArm; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUCameraComponent Camera; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUInputMappingContext DefaultMappingContext; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUInputAction MoveAction; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUInputAction LookAction; public: void Move(const FInputActionValue value); void Look(const FInputActionValue value); // ...// .cpp文件 AMyCharacter::AMyCharacter() { PrimaryActorTick.bCanEverTick true; SpringArm CreateDefaultSubobjectUSpringArmComponent(TEXT(SpringArm)); Camera CreateDefaultSubobjectUCameraComponent(TEXT(Camera)); SpringArm-TargetArmLength 400.0f; SpringArm-bUsePawnControlRotation true; SpringArm-SetupAttachment(RootComponent); Camera-SetupAttachment(SpringArm); //控制器只影响相机不影响角色 bUseControllerRotationPitch false; bUseControllerRotationRoll false; bUseControllerRotationYaw false; GetCharacterMovement()-bOrientRotationToMovement true; } void AMyCharacter::BeginPlay() { Super::BeginPlay(); if (auto PlayerController CastAPlayerController(Controller)) if (auto Subsystem ULocalPlayer::GetSubsystemUEnhancedInputLocalPlayerSubsystem(PlayerController-GetLocalPlayer())) Subsystem-AddMappingContext(DefaultMappingContext, 0); } void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); if (auto EnhancedInputComponent CastCheckedUEnhancedInputComponent(PlayerInputComponent)) { EnhancedInputComponent-BindAction(MoveAction, ETriggerEvent::Triggered, this, AMyCharacter::Move); EnhancedInputComponent-BindAction(LookAction, ETriggerEvent::Triggered, this, AMyCharacter::Look); } } void AMyCharacter::Move(const FInputActionValue value) { FVector2D MovementVector value.GetFVector2D(); if (Controller) { const FRotator Rotation Controller-GetControlRotation(); const FRotator YawRotation(0, Rotation.Yaw, 0); const FVector FowardDirection FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); const FVector RightDirection FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); AddMovementInput(FowardDirection, MovementVector.Y); AddMovementInput(RightDirection, MovementVector.X); } } // 5.7使用IMC_Default 和 IMC_MouseLook 将按键和鼠标操作分开 // IMC_Default → 按键操作移动、跳跃、冲刺、交互等 // IMC_MouseLook → 鼠标操作视角旋转 void AMyCharacter::Look(const FInputActionValue value) { FVector2D LookAxisVector value.GetFVector2D(); if (Controller) { AddControllerYawInput(LookAxisVector.X); AddControllerPitchInput(LookAxisVector.Y); } }
延伸阅读

更多相关文章

2026/11/14 13:47:52

智谱 GLM Coding Plan 2026年7月31日套餐变动分析报告

智谱 GLM Coding Plan 2026年7月31日套餐变动分析报告分析日期:2026年8月2日 数据来源:智谱官方文档 (docs.bigmodel.cn)、IT之家、新浪财经、CreditsPlan.cn、CSDN一、背景概述 2026年7月30日,智谱正式将 GLM Coding Plan 套餐改版升级&…

2026/11/9 15:53:46

口腔出现白色斑块不痛不痒,需要警惕吗

口腔出现白色斑块不痛不痒,需要警惕吗口腔黏膜上突然出现一块白色斑块,不疼也不痒,很多人刚开始都容易忽略。我身边有个同事前阵子就遇到了,他老觉得嘴里有块东西,用舌头舔感觉粗糙,但饭照吃、觉照睡&#…

2026/11/14 13:44:49

高压电工证考试知识有,全国通用证书能帮你破局

高压电工证考试知识有,全国通用证书能帮你破局 学历不高怕报不上名?别担心,高压电工证考试知识有,而且全国通用,只要你符合条件,完全有机会进入电工行业。别被“学历门槛”吓退,很多一线电工都是从零基础起步,靠扎实的实操和证书打开职业道路。…

2026/11/14 13:44:49

学汽修要电工证嘛 这个证全国通用吗

学汽修要电工证嘛 这个证全国通用吗 实操考试心里没底怕挂科,特别是刚入行的汽修新手,面对电工证考试总是手足无措。其实电工证对于汽修行业来说并不是可有可无的,尤其在现代汽车维修中,涉及电路、电控系统、车载设备等内容,电工证已经成为一项硬性要求…

2026/11/14 13:44:49

工地电工证哪里报考?网上查询教你避开这些坑

工地电工证哪里报考?网上查询教你避开这些坑 工地太忙根本没时间复习考试,很多人心里都打鼓,想着“工地电工证哪里报考”这个问题,又怕自己一不小心走错路,耽误工期,还可能面临罚款甚至停工。别慌,我来给你讲明白,网上查询怎么用,怎么选机构,怎么把…

2026/11/14 13:44:49

电工证复审后照片多少钱 跨省转证全流程及费用解析

电工证复审后照片多少钱 跨省转证全流程及费用解析 之前考的证在外省能不能转过来?这几乎是每个想从事电工行业的人都会问的问题。尤其是在南阳卧龙区从事公路工程的你,很可能手里有外地的电工证,但又想在本地继续使用,这就涉及到跨省转证的问题。本文将…

2026/11/14 13:44:49

陕西建设厅特种工工种值不值得考?转岗者避坑指南来了

陕西建设厅特种工工种值不值得考?转岗者避坑指南来了 你是不是也遇到过这样的问题: 不知道去哪报名怕被中介坑 ?陕西建设厅特种工工种报名渠道五花八门,有些培训机构打着“包过”的旗号,实则收费高、培训内容空洞,甚至考不过还要加钱重报。特别是像郑…

2026/11/14 13:39:49

肇庆哪里考电工证真实经历揭秘:实操考试心里没底怕挂科怎么破?

肇庆哪里考电工证真实经历揭秘:实操考试心里没底怕挂科怎么破? 实操考试心里没底怕挂科?别慌,这是很多想考电工证的新手都会有的心理。作为三门峡市政公用工程的一线从业者,我也曾站在考场外手心冒汗,担心一不小心就挂科。今天我就结合 真实经历…

2026/11/13 22:33:32

电工证丢失还能补吗?千万别踩坑,丢了证等于失业

电工证丢失还能补吗?千万别踩坑,丢了证等于失业 你正在找工作,但手里的电工证突然丢了,这下怎么办?别急,先别慌, 电工证丢失还能补吗 ?答案是肯定的,但 千万别踩坑 ,补办流程如果不了解,可能会耽误你上岗、甚至影响到你的收入。…

2026/11/14 0:06:39

土木特种工考证官方报名入口怎么找 之前考的证在外省能不能转过来

土木特种工考证官方报名入口怎么找 之前考的证在外省能不能转过来 之前考的证在外省能不能转过来?这个问题我太熟悉了,作为一名干了十几年的特种作业证书办理从业者,每年都会遇到不少像你一样在外地考了证,回来却发现无法直接使用的学员。别急,今天我就…

2026/11/14 0:06:39

电工证要多久多钱保姆级教程:工地太忙根本没时间复习考试

电工证要多久多钱保姆级教程:工地太忙根本没时间复习考试 工地太忙根本没时间复习考试,你不是一个人。在信阳浉河区,很多刚进入工地的电工都面临这样的困境:工作强度大,时间碎片化,根本没有系统复习考试的机会。但电工证是上岗的硬门槛,…

2026/11/13 22:32:11

面向复杂光照与角度的宠物面部识别鲁棒性增强策略

在智慧养宠时代,基于视觉的宠物身份识别技术正逐步从实验室走向家庭应用。然而,与配合度高的人类不同,宠物是典型的“非合作生物识别对象”——它们不会主动配合摄像头调整姿态,更无法控制光照环境。实际应用中,我们常…

2026/11/13 12:14:39

SSM电子书店源码全解析:结构、原理、部署与排错实战

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

还想了解更多?直接咨询顾问

免费诊断 + 免费方案 + 透明报价。

全国咨询热线400-8866-253
免费获取方案
☎咨询二维码 ☎ ↑