Added editor field for Animation Controller of the Animator component in the inspector

This commit is contained in:
Kah Wei 2023-03-08 20:58:21 +08:00
parent 7ab1ee6fec
commit 57a8e385e4
2 changed files with 55 additions and 14 deletions

View File

@ -60,6 +60,7 @@ enum class AssetType : AssetTypeMeta
AUDIO_BANK, AUDIO_BANK,
ANIM_CONTAINER, ANIM_CONTAINER,
ANIM_CLIP, ANIM_CLIP,
ANIM_CONTROLLER,
MAX_COUNT MAX_COUNT
}; };
constexpr size_t TYPE_COUNT{ static_cast<size_t>(AssetType::MAX_COUNT) }; constexpr size_t TYPE_COUNT{ static_cast<size_t>(AssetType::MAX_COUNT) };
@ -82,6 +83,7 @@ constexpr std::string_view SCENE_FOLDER{ "/Scenes/" };
constexpr std::string_view PREFAB_FOLDER{ "/Prefabs/" }; constexpr std::string_view PREFAB_FOLDER{ "/Prefabs/" };
constexpr std::string_view MATERIAL_FOLDER{ "/Materials/" }; constexpr std::string_view MATERIAL_FOLDER{ "/Materials/" };
constexpr std::string_view ANIM_CLIP_FOLDER{ "/Animations/" }; constexpr std::string_view ANIM_CLIP_FOLDER{ "/Animations/" };
constexpr std::string_view ANIM_CONTROLLER_FOLDER{ "/Animation Controllers/" };
// ASSET EXTENSIONS // ASSET EXTENSIONS
@ -99,6 +101,7 @@ constexpr std::string_view MATERIAL_EXTENSION {".shmat"};
constexpr std::string_view TEXTURE_EXTENSION {".shtex"}; constexpr std::string_view TEXTURE_EXTENSION {".shtex"};
constexpr std::string_view MODEL_EXTENSION{ ".shmodel" }; constexpr std::string_view MODEL_EXTENSION{ ".shmodel" };
constexpr std::string_view ANIM_CONTAINER_EXTENSION{ ".shanimcontainer" }; constexpr std::string_view ANIM_CONTAINER_EXTENSION{ ".shanimcontainer" };
constexpr std::string_view ANIM_CONTROLLER_EXTENSION{ ".shanimcontroller" };
constexpr std::string_view FILLER_EXTENSION{"dummy"}; constexpr std::string_view FILLER_EXTENSION{"dummy"};
constexpr std::string_view EXTENSIONS[] = { constexpr std::string_view EXTENSIONS[] = {
@ -115,6 +118,7 @@ constexpr std::string_view EXTENSIONS[] = {
FONT_EXTENSION, FONT_EXTENSION,
AUDIO_BANK_EXTENSION, AUDIO_BANK_EXTENSION,
ANIM_CONTAINER_EXTENSION, ANIM_CONTAINER_EXTENSION,
ANIM_CONTROLLER_EXTENSION,
FILLER_EXTENSION FILLER_EXTENSION
}; };

View File

@ -640,23 +640,29 @@ namespace SHADE
if (ImGui::CollapsingHeader(componentType.get_name().data())) if (ImGui::CollapsingHeader(componentType.get_name().data()))
{ {
DrawContextMenu(component); DrawContextMenu(component);
/* Animation Rig */
Handle<SHRig> const& rig = component->GetRig(); Handle<SHRig> const& rig = component->GetRig();
const auto RIG_NAME = rig ? SHResourceManager::GetAssetName<SHRig>(rig).value_or("") : ""; const auto RIG_NAME = rig ? SHResourceManager::GetAssetName<SHRig>(rig).value_or("") : "";
SHEditorWidgets::DragDropReadOnlyField<AssetID>("Rig", RIG_NAME, [component]() SHEditorWidgets::DragDropReadOnlyField<AssetID>
{ (
Handle<SHRig> const& rig = component->GetRig(); "Rig", RIG_NAME, [component]()
return SHResourceManager::GetAssetID<SHRig>(rig).value_or(0);
},
[component](AssetID const& id)
{
if (SHAssetManager::GetType(id) != AssetType::MODEL)
{ {
SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!") Handle<SHRig> const& rig = component->GetRig();
return; return SHResourceManager::GetAssetID<SHRig>(rig).value_or(0);
} },
component->SetRig(SHResourceManager::LoadOrGet<SHRig>(id)); [component](AssetID const& id)
SHResourceManager::FinaliseChanges(); {
}, SHDragDrop::DRAG_RESOURCE); if (SHAssetManager::GetType(id) != AssetType::MODEL)
{
SHLOG_WARNING("Attempted to assign non mesh rig asset to Animator Rig property!")
return;
}
component->SetRig(SHResourceManager::LoadOrGet<SHRig>(id));
SHResourceManager::FinaliseChanges();
},
SHDragDrop::DRAG_RESOURCE
);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{ {
if (Handle<SHRig> const& rig = component->GetRig()) if (Handle<SHRig> const& rig = component->GetRig())
@ -665,6 +671,37 @@ namespace SHADE
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID); SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
} }
} }
/* Animation Controller */
Handle<SHAnimationController> animController = component->GetAnimationController();
const auto AC_NAME = animController ? SHResourceManager::GetAssetName<SHAnimationController>(animController).value_or("") : "";
SHEditorWidgets::DragDropReadOnlyField<AssetID>
(
"Animation Controller", AC_NAME, [component]()
{
Handle<SHAnimationController> ac = component->GetAnimationController();
return SHResourceManager::GetAssetID<SHAnimationController>(ac).value_or(0);
},
[component](AssetID const& id)
{
if (SHAssetManager::GetType(id) != AssetType::ANIM_CONTROLLER)
{
SHLOG_WARNING("Attempted to assign non animation controller asset to Animator Animation Controller property!")
return;
}
component->SetAnimationController(SHResourceManager::LoadOrGet<SHAnimationController>(id));
SHResourceManager::FinaliseChanges();
},
SHDragDrop::DRAG_RESOURCE
);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
if (Handle<SHAnimationController> ac = component->GetAnimationController())
{
AssetID assetID = SHResourceManager::GetAssetID<SHAnimationController>(ac).value_or(0);
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
}
}
} }
else else
{ {