Asset.h 2.4 KB

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