网站设计制造,WordPress论坛案例,小程序爱成毅的微博,seo的基础是什么创建新C类
在 虚幻编辑器 中#xff0c;点击 文件#xff08;File#xff09; 下拉菜单#xff0c;然后选择 新建C类...#xff08;New C Class...#xff09; 命令#xff1a; 此时将显示 选择父类#xff08;Choose Parent Class#xff09; 菜单。可以选择要扩展的…创建新C类
在 虚幻编辑器 中点击 文件File 下拉菜单然后选择 新建C类...New C Class... 命令 此时将显示 选择父类Choose Parent Class 菜单。可以选择要扩展的现有类将其功能添加到自己的类。选择 Actor因为其是可在场景中放置的最基本对象类型然后点击 下一步Next。 在 为新Actor命名Name Your New Actor 菜单中将Actor命名为 FloatingActor然后点击 创建类Create Class。 编辑C类
现在我们已创建C类将切换到Visual Studio并编辑代码。
在 Visual Studio 中找到默认情况下显示在窗口左侧的 解决方案浏览器然后用其找到 FloatingActor.h。在项目中它将位于 Games QuickStart Source QuickStart 下
#pragma once#include CoreMinimal.h
#include GameFramework/Actor.h
#include create_actor.generated.hUCLASS()
class SPAWNDESTROY_API Acreate_actor : public AActor
{GENERATED_BODY()public: // Sets default values for this actors propertiesAcreate_actor();protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;public: // Called every framevirtual void Tick(float DeltaTime) override;
public:// 静态网格体成员UPROPERTY(VisibleAnywhere)UStaticMeshComponent* visualmesh;UPROPERTY(EditAnywhere, BlueprintReadWrite, Category FloatingActor)float FloatSpeed 20.0f;UPROPERTY(EditAnywhere, BlueprintReadWrite, Category FloatingActor)float RotationSpeed 20.0f;};
#include create_actor.h// Sets default values
Acreate_actor::Acreate_actor()
{// Set this actor to call Tick() every frame. You can turn this off to improve performance if you dont need it.PrimaryActorTick.bCanEverTick true;// UStaticMeshComponent 类型的默认子对象。这个组件将用于处理该 Actor 的静态网格模型。visualmesh CreateDefaultSubobjectUStaticMeshComponent(TEXT(Mesh));// 将 visualmesh 组件附加到 Actor 的根组件RootComponent上这意味着它将与该 Actor 一起移动、旋转或缩放。visualmesh-SetupAttachment(RootComponent);// FObjectFinder 类在游戏资源中查找一个名为 Shape_Cube 的静态网格模型资源UStaticMeshstatic ConstructorHelpers::FObjectFinderUStaticMesh CubeVisualAsset(TEXT(/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube));if (CubeVisualAsset.Succeeded()){// 绑定对应的资源visualmesh-SetStaticMesh(CubeVisualAsset.Object);// 设置相对资源visualmesh-SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));}}// Called when the game starts or when spawned
void Acreate_actor::BeginPlay()
{Super::BeginPlay();}// Called every frame
void Acreate_actor::Tick(float DeltaTime)
{Super::Tick(DeltaTime);FVector NewLocation GetActorLocation();FRotator NewRotation GetActorRotation();float RunningTime GetGameTimeSinceCreation();float DeltaHeight (FMath::Sin(RunningTime DeltaTime) - FMath::Sin(RunningTime));NewLocation.Z DeltaHeight * FloatSpeed; //按FloatSpeed调整高度float DeltaRotation DeltaTime * RotationSpeed; //每秒旋转等于RotationSpeed的角度SetActorLocationAndRotation(NewLocation, NewRotation);}