BsResourceImporter.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "BsResourceImporter.h"
  2. #include "BsPath.h"
  3. #include "BsFileSerializer.h"
  4. #include "BsResource.h"
  5. namespace BansheeEngine
  6. {
  7. const WString ResourceImporter::DEFAULT_EXTENSION = L"asset";
  8. ResourceImporter::ResourceImporter()
  9. :SpecificImporter()
  10. {
  11. }
  12. ResourceImporter::~ResourceImporter()
  13. {
  14. }
  15. bool ResourceImporter::isExtensionSupported(const WString& ext) const
  16. {
  17. WString lowerCaseExt = ext;
  18. StringUtil::toLowerCase(lowerCaseExt);
  19. return lowerCaseExt == DEFAULT_EXTENSION;
  20. }
  21. bool ResourceImporter::isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const
  22. {
  23. return true; // No magic number of asset files, they must always rely on extension
  24. }
  25. ResourcePtr ResourceImporter::import(const Path& filePath, ConstImportOptionsPtr importOptions)
  26. {
  27. FileSerializer fs;
  28. std::shared_ptr<IReflectable> loadedData = fs.decode(filePath);
  29. if (loadedData == nullptr)
  30. BS_EXCEPT(InternalErrorException, "Unable to import resource.");
  31. if (!loadedData->isDerivedFrom(Resource::getRTTIStatic()))
  32. BS_EXCEPT(InternalErrorException, "Imported object doesn't derive from Resource.");
  33. ResourcePtr resource = std::static_pointer_cast<Resource>(loadedData);
  34. return resource;
  35. }
  36. }