Asset.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include <Atomic/Core/Object.h>
  3. #include "AssetImporter.h"
  4. using namespace Atomic;
  5. namespace ToolCore
  6. {
  7. #define ASSET_VERSION 1
  8. class Asset : public Object
  9. {
  10. friend class AssetDatabase;
  11. OBJECT(Asset);
  12. public:
  13. /// Construct.
  14. Asset(Context* context);
  15. virtual ~Asset();
  16. bool Import();
  17. bool Preload();
  18. // the .fbx, .png, etc path, attempts to load .asset, creates missing .asset
  19. bool SetPath(const String& path);
  20. const String& GetGUID() const { return guid_; }
  21. const String& GetName() const { return name_; }
  22. const String& GetPath() const { return path_; }
  23. String GetExtension() const;
  24. /// Get the path relative to project
  25. String GetRelativePath();
  26. String GetCachePath() const;
  27. const StringHash GetImporterType() { return importer_.Null() ? String::EMPTY : importer_->GetType(); }
  28. const String& GetImporterTypeName() { return importer_.Null() ? String::EMPTY : importer_->GetTypeName(); }
  29. AssetImporter* GetImporter() { return importer_; }
  30. void PostImportError(const String& message);
  31. Asset* GetParent();
  32. void SetDirty(bool dirty) { dirty_ = dirty; }
  33. bool IsDirty() const { return dirty_; }
  34. /// Get the last timestamp as seen by the AssetDatabase
  35. unsigned GetFileTimestamp() { return fileTimestamp_; }
  36. /// Sets the time stamp to the asset files current time
  37. void UpdateFileTimestamp();
  38. // get the .asset filename
  39. String GetDotAssetFilename();
  40. bool IsFolder() const { return isFolder_; }
  41. // load .asset
  42. bool Load();
  43. // save .asset
  44. bool Save();
  45. private:
  46. bool CreateImporter();
  47. bool CheckCacheFile();
  48. String guid_;
  49. // can change
  50. String path_;
  51. String name_;
  52. bool dirty_;
  53. bool isFolder_;
  54. // the current timestamp of the asset as seen by the asset database
  55. // used to catch when the asset needs to be marked dirty when notified
  56. // that the file has changed (the resource system will send a changed file
  57. // event when the resource is first added)
  58. unsigned fileTimestamp_;
  59. SharedPtr<JSONFile> json_;
  60. SharedPtr<AssetImporter> importer_;
  61. };
  62. }