当前位置: 首页 > java >正文

UE C++学习笔记之创建组件

UE.h头文件:


#pragma once#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Components/BoxComponent.h"
#include "Camera/CameraComponent.h"#include "SnakeHead.generated.h"UCLASS()
class SNAKEGAME_API ASnakeHead : public APawn
{GENERATED_BODY()public:// Sets default values for this pawn's propertiesASnakeHead();UPROPERTY(VisibleAnywhere)//添加到虚幻引擎中在任何地方可视UStaticMeshComponent* Mesh;//mesh组件UPROPERTY(VisibleAnywhere)//添加到虚幻引擎中在任何地方可视UBoxComponent* Collision; //碰撞组件UPROPERTY(VisibleAnywhere)//添加到虚幻引擎中在任何地方可视UCameraComponent* Camera;//摄像机组件protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;public:	// Called every framevirtual void Tick(float DeltaTime) override;// Called to bind functionality to inputvirtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;};

UE.cpp文件:

// Fill out your copyright notice in the Description page of Project Settings.#include "SnakeHead.h"// Sets default values
ASnakeHead::ASnakeHead()
{// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = true;Collision = CreateDefaultSubobject<UBoxComponent>(TEXT("Collision"));//创建碰撞物体名字是CollisionRootComponent = Collision;//为Actor根组件赋值Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));//创建mesh组件名字是MeshMesh->SetupAttachment(RootComponent);//把mesh的父亲设置为RootComponentCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera")); // 创建Camera组件名字是CameraCamera->SetupAttachment(RootComponent);//把Camera的父亲设置为RootComponent
}// Called when the game starts or when spawned
void ASnakeHead::BeginPlay()
{Super::BeginPlay();}// Called every frame
void ASnakeHead::Tick(float DeltaTime)
{Super::Tick(DeltaTime);}// Called to bind functionality to input
void ASnakeHead::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{Super::SetupPlayerInputComponent(PlayerInputComponent);}
http://www.xdnf.cn/news/8761.html

相关文章:

  • 精选19道SQL面试题:覆盖查询、概念与常见陷阱
  • 前端开发知识体系全景解析
  • GO 语言基础3 struct 结构体
  • GO 语言进阶之 Template 模板使用
  • 使用中文作为map的可以,需要注意什么
  • linux学习第15天(递归遍历目录实现-ls -R)
  • 【C语言练习】062. 使用位运算优化算法
  • Lua基础语法
  • Linux 内核学习(9) --- Linux sysfs 文件系统
  • 【Redis】浅谈分布式系统
  • libevent2-介绍
  • 深入理解 JavaScript 面向对象编程与 Class
  • EPD_2IN7_V2_Clear() 和 Paint_Clear(WHITE) 的区别
  • 深度解析视频剪辑SDK开发:从AI字幕提取到多端原生插件集成-优雅草卓伊凡
  • 小白的进阶之路系列之四----人工智能从初步到精通pytorch自定义数据集上
  • Hertz+Kitex快速上手开发
  • 学习日志12 java
  • 低功耗蓝牙BLE之LE Controller Package CRC校验
  • MySQL 定时逻辑备份
  • uni-app学习笔记十二-vue3中组件传值(属性传值)
  • 解决DeepSeek部署难题:提升效率与稳定性的关键策略
  • 《JavaScript 性能优化:从原理到实战的全面指南》
  • vue3中自定义指令使用
  • Vue3 watch 使用与注意事项
  • 在Mathematica中,使用鸟枪法求解在无穷远处的边值常微分方程
  • 动态规划算法:字符串类问题(2)公共串
  • 简单血条于小怪攻击模板
  • 【Linux】深刻理解OS管理
  • Java 8 Stream操作示例
  • 《仿盒马》app开发技术分享-- 原生地图展示(端云一体)