Asset.h 2.2 KB

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