// 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<UTexture2D> 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<USceneComponent>(this, TEXT("SceneComp"));
RootComponent = SceneComponent;
RootComponent->Mobility = EComponentMobility::Static;
#if WITH_EDITORONLY_DATA
SpriteComponent = ObjectInitializer.CreateEditorOnlyDefaultSubobject<UBillboardComponent>(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);
}