Asset.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /// Get the path relative to project
  24. String GetRelativePath();
  25. String GetCachePath() const;
  26. const StringHash GetImporterType() { return importer_.Null() ? String::EMPTY : importer_->GetType(); }
  27. const String& GetImporterTypeName() { return importer_.Null() ? String::EMPTY : importer_->GetTypeName(); }
  28. AssetImporter* GetImporter() { return importer_; }
  29. void PostImportError(const String& message);
  30. Asset* GetParent();
  31. void SetDirty(bool dirty) { dirty_ = dirty; }
  32. bool IsDirty() const { return dirty_; }
  33. /// Get the last timestamp as seen by the AssetDatabase
  34. unsigned GetFileTimestamp() { return fileTimestamp_; }
  35. /// Sets the time stamp to the asset files current time
  36. void UpdateFileTimestamp();
  37. // get the .asset filename
  38. String GetDotAssetFilename();
  39. bool IsFolder() const { return isFolder_; }
  40. // load .asset
  41. bool Load();
  42. // save .asset
  43. bool Save();
  44. private:
  45. bool CreateImporter();
  46. bool CheckCacheFile();
  47. String guid_;
  48. // can change
  49. String path_;
  50. String name_;
  51. bool dirty_;
  52. bool isFolder_;
  53. // the current timestamp of the asset as seen by the asset database
  54. // used to catch when the asset needs to be marked dirty when notified
  55. // that the file has changed (the resource system will send a changed file
  56. // event when the resource is first added)
  57. unsigned fileTimestamp_;
  58. SharedPtr<JSONFile> json_;
  59. SharedPtr<AssetImporter> importer_;
  60. };
  61. }