zoukankan      html  css  js  c++  java
  • Unreal Engine 4 C++ 为编辑器中Actor创建自己定义图标

    有时候我们创建场景的时候,特定的Actor我们想给它一个特定的图标,便于观察。比方这样:


    实现起来也非常easy。须要编写C++代码:

    我们创建一个Actor,叫AMyActor。它包括一个Sprite(精灵),这个精灵负责显示自己定义图标:代码例如以下

    #pragma once
    
    #include "GameFramework/Actor.h"
    #include "Components/BillboardComponent.h"
    #include "MyActor.generated.h"
    
    /**
     * 
     */
    UCLASS()
    class NANTOPDOWN_API AMyActor : public AActor
    {
    	GENERATED_UCLASS_BODY()
    
    	//virtual void BeginPlay() OVERRIDE;
    
    	UPROPERTY()
    	TSubobjectPtr<UBillboardComponent> SpriteComponent;
    
    	UTexture2D* SpriteTexture;
    	
    };

    #include "NanTopDown.h"
    #include "MyActor.h"
    
    
    AMyActor::AMyActor(const class FPostConstructInitializeProperties& PCIP)
    	: Super(PCIP)
    {
    	struct FConstructorStatics
    	{
    		ConstructorHelpers::FObjectFinderOptional<UTexture2D> NoteTextureObject;
    
    		FName ID_Notes;
    		FText Name_Notes;
    
    		FConstructorStatics()
    			: NoteTextureObject(TEXT("Texture2D'/Game/Textures/MyIcon.MyIcon'"))
    			, ID_Notes(TEXT("Notes"))
    			, Name_Notes(NSLOCTEXT("SpriteCategory", "Notes", "Notes"))
    		{
    		}
    	};
    	
    		static FConstructorStatics Cs;
    		TSubobjectPtr<USceneComponent> SceneComponent = PCIP.CreateDefaultSubobject<USceneComponent>(
    			this, TEXT("SceneComp"));
    		RootComponent = SceneComponent;
    		RootComponent->Mobility = EComponentMobility::Static;
    
    #if WITH_EDITORONLY_DATA
    		SpriteComponent = PCIP.CreateEditorOnlyDefaultSubobject<UBillboardComponent>(this, TEXT("Sprite"));
    		if (SpriteComponent)
    		{
    			SpriteComponent->Sprite = Cs.NoteTextureObject.Get();
    			SpriteComponent->SpriteInfo.Category = Cs.ID_Notes;
    			SpriteComponent->SpriteInfo.DisplayName = Cs.Name_Notes;
    			SpriteComponent->AttachParent = RootComponent;
    			SpriteComponent->Mobility = EComponentMobility::Static;
    		}
    #endif
    }
    
    

    AMyActor仅仅有一个UBillboardComponent组件。增加场景就能够看到自己定义的图片了。


    參考文章:https://wiki.unrealengine.com/Add_in_editor_Icon_to_your_Custom_Actor

  • 相关阅读:
    (转)Golang reflect.DeepEqual函数:判断两个值是否一致
    Kubernetes字段Finalizers
    校园电子屏无人值守模式探索
    史上最全测试开发工具推荐(含自动化、性能、稳定性、抓包)
    Java 将Word转为HTML的方法
    C# 在PPT中添加数学公式
    C# 将PPT转为OFD/DPT/DPS/ODP/POTX/UOP
    C# 将Excel转为OFD、UOS
    Java 扫描识别条形码图片
    C# 加载Word的3种方法
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/7068580.html
Copyright © 2011-2022 走看看