需要做的是三个内容
- 自定义的资产类:(继承UObject),作为自定义资产的数据模型类.
- 相应的Factory类:(继承UFactory),这个工厂类用于被UE4引擎识别,作为可以在ContentBrowser中创建资产(Asset)
- 相应的AssetTypeActions:指定了诸如Asset的名称,应属于的类别,颜色等内容,在模块中实现自定义资产的类型
注意
,在4.25版本之前,只需要1,2这两个内容就可以实现上图的效果(默认自定义资产分类在MisCellaneous下),
4.25版本之后必须要创建相应的AssetTypeActions才可以在编辑器中找到自定义的资产类。
相关链接:
https://answers.unrealengine.com/questions/966478/view.html
https://answers.unrealengine.com/questions/969157/view.html
插件模块
实现自定义资产,需要有Runtime模块和Editor模块。
推荐使用插件来创建这些模块,对于模块的维护和应用在其他UE项目更加有用。
先在引擎中创建一个空插件,我创建了一个“MyTest”的插件。
对于新创建的空插件,只有一个Runtime类型的模块,复制这个模块文件,把对应的文件夹名和源文件等都改成带有“Editor”,作为Editor模块。
//插件文件的目录结构如下
-MyTest
- Resource
- Source
- MyTest //Runtime module
- Private
- Public
- MyTest.Build.cs
- MyTestEditor //Editor module
- Private
- Public
- MyTestEditor.Build.cs
- MyTest.uplugin
对于Runtime
模块下的文件就不用修改了,修改Editor
模块。
注意:在Editor
模块的配置cs文件中要添加对Runtime
模块(我的是MyTest
)和UnrealEd
的依赖.
在插件的uplugin
中添加Editor
模块。
(下面的代码就做个参考,改一下很快的)
MyTestEditor.h
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"
class FMyTestEditorModule : public IModuleInterface
{
public:
……
};
MyTestEditor.cpp
// Copyright Epic Games, Inc. All Rights Reserved.
#include "MyTestEditor.h"
#define LOCTEXT_NAMESPACE "FMyTestEditorModule"
……
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FMyTestEditorModule, MyTestEditor)
MyTestEditor.Build.cs
// Copyright Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
public class MyTestEditor : ModuleRules
{
public MyTestEditor(ReadOnlyTargetRules Target) : base(Target)
{
PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"Slate"