将编辑器的图标添加到你自定义的Actor中【UE4】【C++】

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "UObject/UObjectGlobals.h"
#include "MyActor.generated.h"

UCLASS()
class UIDEMO_API AMyActor : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AMyActor(const FObjectInitializer& ObjectInitializer);

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

	UPROPERTY()
	UBillboardComponent* SpriteComponent;
	UTexture2D* SpriteTexture;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

};
// Fill out your copyright notice in the Description page of Project Settings.


#include "MyActor.h"
#include "ConstructorHelpers.h"
#include "Components/BillboardComponent.h"

// Sets default values
AMyActor::AMyActor(const FObjectInitializer& ObjectInitializer)
	:Super(ObjectInitializer)
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	struct FConstructorStatics
	{
		//在资源中查找UTexture2D对象
		ConstructorHelpers::FObjectFinderOptional NoteTextureObject;
		FName ID_Notes;
		FText NAME_Notes;

		FConstructorStatics()
			:NoteTextureObject(TEXT("/Engine/EditorResources/S_Note")) //路径
			,ID_Notes(TEXT("Notes"))
			,NAME_Notes(NSLOCTEXT("SpriteCategory", "Notes", "Notes"))
		{
		}
	};
	static FConstructorStatics ConstructorStatics;
	USceneComponent* SceneComponent = ObjectInitializer.CreateDefaultSubobject(this, TEXT("SceneComp"));
	RootComponent = SceneComponent;
	RootComponent->Mobility = EComponentMobility::Static;

#if WITH_EDITORONLY_DATA
	SpriteComponent = ObjectInitializer.CreateEditorOnlyDefaultSubobject(this, TEXT("Sprite"));
	if (SpriteComponent)
	{
		SpriteComponent->Sprite = ConstructorStatics.NoteTextureObject.Get();
		SpriteComponent->SpriteInfo.Category = ConstructorStatics.ID_Notes;
		SpriteComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
		SpriteComponent->Mobility = EComponentMobility::Static;
	}
#endif
}

// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AMyActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

将编辑器的图标添加到你自定义的Actor中【UE4】【C++】_第1张图片

你可能感兴趣的:(将编辑器的图标添加到你自定义的Actor中【UE4】【C++】)