Added serialization for animation assets for scripts

This commit is contained in:
Kah Wei 2023-03-08 20:34:11 +08:00
parent 69ac4d1219
commit 7ab1ee6fec
2 changed files with 85 additions and 37 deletions

View File

@ -18,6 +18,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Editor/Editor.hxx" #include "Editor/Editor.hxx"
// STL Includes // STL Includes
#include <memory> #include <memory>
#include <string>
// Project Headers // Project Headers
#include "Components/Component.hxx" #include "Components/Component.hxx"
#include "Scripts/ScriptStore.hxx" #include "Scripts/ScriptStore.hxx"
@ -30,7 +31,9 @@ of DigiPen Institute of Technology is prohibited.
#include "RangeAttribute.hxx" #include "RangeAttribute.hxx"
#include "Math/Vector2.hxx" #include "Math/Vector2.hxx"
#include "Math/Vector3.hxx" #include "Math/Vector3.hxx"
#include <string> #include "Assets/AnimationClipAsset.hxx"
#include "Assets/AnimationControllerAsset.hxx"
#include "Assets/AnimationRigAsset.hxx"
// Using Directives // Using Directives
using namespace System; using namespace System;
@ -180,7 +183,10 @@ namespace SHADE
renderSpecificField<int , System::Enum >(field, object, nullptr , &isHovered) || renderSpecificField<int , System::Enum >(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , FontAsset >(field, object, nullptr , &isHovered) || renderSpecificField<AssetID , FontAsset >(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , MeshAsset >(field, object, nullptr , &isHovered) || renderSpecificField<AssetID , MeshAsset >(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , MaterialAsset >(field, object, nullptr , &isHovered); renderSpecificField<AssetID , MaterialAsset >(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , AnimationClipAsset >(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , AnimationControllerAsset>(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , AnimationRigAsset >(field, object, nullptr , &isHovered);
if (!MODIFIED_PRIMITIVE) if (!MODIFIED_PRIMITIVE)
{ {
@ -341,7 +347,10 @@ namespace SHADE
renderFieldEditor<int , System::Enum >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || renderFieldEditor<int , System::Enum >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , FontAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || renderFieldEditor<AssetID , FontAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , MeshAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || renderFieldEditor<AssetID , MeshAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , MaterialAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified); renderFieldEditor<AssetID , MaterialAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , AnimationClipAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , AnimationControllerAsset>(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , AnimationRigAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified);
return modified; return modified;
} }

View File

@ -23,6 +23,9 @@ of DigiPen Institute of Technology is prohibited.
#include "Assets/FontAsset.hxx" #include "Assets/FontAsset.hxx"
#include "Assets/MeshAsset.hxx" #include "Assets/MeshAsset.hxx"
#include "Assets/MaterialAsset.hxx" #include "Assets/MaterialAsset.hxx"
#include "Assets/AnimationClipAsset.hxx"
#include "Assets/AnimationControllerAsset.hxx"
#include "Assets/AnimationRigAsset.hxx"
namespace SHADE namespace SHADE
{ {
@ -237,6 +240,42 @@ namespace SHADE
return true; return true;
} }
return false;
}
template<>
bool Editor::renderFieldEditorInternal<AssetID, AnimationClipAsset>(const std::string& fieldName, interior_ptr<AnimationClipAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
{
uint32_t assetId = managedValPtr->NativeAssetID;
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::FONT, isHovered))
{
*managedValPtr = AnimationClipAsset(assetId);
return true;
}
return false;
}
template<>
bool Editor::renderFieldEditorInternal<AssetID, AnimationControllerAsset>(const std::string& fieldName, interior_ptr<AnimationControllerAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
{
uint32_t assetId = managedValPtr->NativeAssetID;
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MESH, isHovered))
{
*managedValPtr = AnimationControllerAsset(assetId);
return true;
}
return false;
}
template<>
bool Editor::renderFieldEditorInternal<AssetID, AnimationRigAsset>(const std::string& fieldName, interior_ptr<AnimationRigAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
{
uint32_t assetId = managedValPtr->NativeAssetID;
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MATERIAL, isHovered))
{
*managedValPtr = AnimationRigAsset(assetId);
return true;
}
return false; return false;
} }
} }