BsPrefabImporter.cpp 1.2 KB

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