BsEditorResourceLoader.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsEditorResourceLoader.h"
  4. #include "Library/BsProjectLibrary.h"
  5. #include "Resources/BsResources.h"
  6. #include "Library/BsProjectResourceMeta.h"
  7. #include "Debug/BsDebug.h"
  8. namespace bs
  9. {
  10. HResource EditorResourceLoader::load(const Path& path, ResourceLoadFlags flags, bool async) const
  11. {
  12. ProjectLibrary::LibraryEntry* entry = gProjectLibrary().findEntry(path).get();
  13. if (entry == nullptr || entry->type == ProjectLibrary::LibraryEntryType::Directory)
  14. return HResource();
  15. ProjectLibrary::FileEntry* resEntry = static_cast<ProjectLibrary::FileEntry*>(entry);
  16. if (resEntry->meta == nullptr)
  17. {
  18. BS_LOG(Warning, Editor, "Missing .meta file for resource at path: \"{0}\".", path);
  19. return HResource();
  20. }
  21. // Note: Calling both findEntry and findResourceMeta is a bit redundant since they do a lot of the same work, and
  22. // this could be optimized so only one of them is called.
  23. SPtr<ProjectResourceMeta> meta = gProjectLibrary().findResourceMeta(path);
  24. if (meta == nullptr)
  25. {
  26. BS_LOG(Warning, Editor, "Unable to load resource at path: \"{0}\". File not found. ", path);
  27. return HResource();
  28. }
  29. UUID resUUID = meta->getUUID();
  30. if (resEntry->meta->getIncludeInBuild())
  31. {
  32. BS_LOG(Warning, Editor, "Dynamically loading a resource at path: \"{0}\" but the resource isn't flagged to "
  33. "be included in the build. It may not be available outside of the editor.", path);
  34. }
  35. return gResources().loadFromUUID(resUUID, async, flags);
  36. }
  37. }