From 57a8e385e4a2f39d1021f6e6c86780dea3773566 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 8 Mar 2023 20:58:21 +0800 Subject: [PATCH] Added editor field for Animation Controller of the Animator component in the inspector --- SHADE_Engine/src/Assets/SHAssetMacros.h | 4 ++ .../Inspector/SHEditorComponentView.hpp | 65 +++++++++++++++---- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/SHADE_Engine/src/Assets/SHAssetMacros.h b/SHADE_Engine/src/Assets/SHAssetMacros.h index b6ee240e..4784560b 100644 --- a/SHADE_Engine/src/Assets/SHAssetMacros.h +++ b/SHADE_Engine/src/Assets/SHAssetMacros.h @@ -60,6 +60,7 @@ enum class AssetType : AssetTypeMeta AUDIO_BANK, ANIM_CONTAINER, ANIM_CLIP, + ANIM_CONTROLLER, MAX_COUNT }; constexpr size_t TYPE_COUNT{ static_cast(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 MATERIAL_FOLDER{ "/Materials/" }; constexpr std::string_view ANIM_CLIP_FOLDER{ "/Animations/" }; +constexpr std::string_view ANIM_CONTROLLER_FOLDER{ "/Animation Controllers/" }; // ASSET EXTENSIONS @@ -99,6 +101,7 @@ constexpr std::string_view MATERIAL_EXTENSION {".shmat"}; constexpr std::string_view TEXTURE_EXTENSION {".shtex"}; constexpr std::string_view MODEL_EXTENSION{ ".shmodel" }; 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 EXTENSIONS[] = { @@ -115,6 +118,7 @@ constexpr std::string_view EXTENSIONS[] = { FONT_EXTENSION, AUDIO_BANK_EXTENSION, ANIM_CONTAINER_EXTENSION, + ANIM_CONTROLLER_EXTENSION, FILLER_EXTENSION }; diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index b037d4d9..91c304e0 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -640,23 +640,29 @@ namespace SHADE if (ImGui::CollapsingHeader(componentType.get_name().data())) { DrawContextMenu(component); + + /* Animation Rig */ Handle const& rig = component->GetRig(); const auto RIG_NAME = rig ? SHResourceManager::GetAssetName(rig).value_or("") : ""; - SHEditorWidgets::DragDropReadOnlyField("Rig", RIG_NAME, [component]() - { - Handle const& rig = component->GetRig(); - return SHResourceManager::GetAssetID(rig).value_or(0); - }, - [component](AssetID const& id) - { - if (SHAssetManager::GetType(id) != AssetType::MODEL) + SHEditorWidgets::DragDropReadOnlyField + ( + "Rig", RIG_NAME, [component]() { - SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!") - return; - } - component->SetRig(SHResourceManager::LoadOrGet(id)); - SHResourceManager::FinaliseChanges(); - }, SHDragDrop::DRAG_RESOURCE); + Handle const& rig = component->GetRig(); + return SHResourceManager::GetAssetID(rig).value_or(0); + }, + [component](AssetID const& id) + { + if (SHAssetManager::GetType(id) != AssetType::MODEL) + { + SHLOG_WARNING("Attempted to assign non mesh rig asset to Animator Rig property!") + return; + } + component->SetRig(SHResourceManager::LoadOrGet(id)); + SHResourceManager::FinaliseChanges(); + }, + SHDragDrop::DRAG_RESOURCE + ); if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { if (Handle const& rig = component->GetRig()) @@ -665,6 +671,37 @@ namespace SHADE SHEditorWindowManager::GetEditorWindow()->SetScrollTo(assetID); } } + + /* Animation Controller */ + Handle animController = component->GetAnimationController(); + const auto AC_NAME = animController ? SHResourceManager::GetAssetName(animController).value_or("") : ""; + SHEditorWidgets::DragDropReadOnlyField + ( + "Animation Controller", AC_NAME, [component]() + { + Handle ac = component->GetAnimationController(); + return SHResourceManager::GetAssetID(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(id)); + SHResourceManager::FinaliseChanges(); + }, + SHDragDrop::DRAG_RESOURCE + ); + if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) + { + if (Handle ac = component->GetAnimationController()) + { + AssetID assetID = SHResourceManager::GetAssetID(ac).value_or(0); + SHEditorWindowManager::GetEditorWindow()->SetScrollTo(assetID); + } + } } else {