-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorials Asset Engine Storage and Folder
Home ▸ Tutorials ▸ Asset Engine ▸ Storage and Folder
Imagine a big box that contains another small boxes, this is how storages and folders can be described. A storage is a big box and a folder a small box. This is how asset engine organizes asset containers.
Storage doesn't store assets itself, this is the role of folders to store assets. A storage can contains one or more folders.
A folder represents a path in a content project. The path can be the root of a content project or a more deeper path. Loading assets from a folder will depend on the path used by the folder.
A storage can have multiple folders linked to different content project.
Here is an example of how storage can be used :
// A content project
- Content \\ Root of the content project
- Mesh
- Texture
- Sounds
- Music
- Effect
// Another content project
- OtherContent \\ Root of the content project
- GUI
- Texture
- Sounds
// First storage example
// It contains folders link to the root of content projects
- MyStorage
- Content
- OtherContent
// Second storage example
// It contains four folders link to each first directory of the content project
- MyStorage
- Content\Mesh
- Content\Texture
- Content\Sounds
- OtherContent\GUI
// Third storage example
// It contains two folders link to Mesh and Texture directory
// And two folders link to sub-directory of Sounds directory
// And one folder link to the sub-directory Texture of GUI directory
- MyStorage
- Content\Mesh
- Content\Texture
- Content\Sounds\Music
- Content\Sounds\Effect
- OtherContent\GUI\Texture
You aren't limited on how you have to organize your content projects and storages, you can do what you want.
A storage is represented by Storage class.
You can create a storage from an AssetEngine instance :
Storage myStorage = assetEngine.CreateStorage("MyStorage");
You can create as much storages as needed.
You can destroy a storage from an AssetEngine instance :
assetEngine.DestroyStorage("MyStorage").
Be careful when you destroy a storage. This action will destroy all folders and assets inside the storage.
You can get a storage from an AssetEngine instance :
Storage myStorage = assetEngine.GetStorage("MyStorage");
// or
Storage myStorage = assetEngine["MyStorage"];
A folder is represented by the AssetFolder class.
You can add folder in a storage this way :
Storage myStorage = assetEngine.CreateStorage("MyStorage");
myStorage.AddFolder("Content");
You can remove a folder in a storage :
myStorage.RemoveFolder("Content");
When you remove a folder, all assets stored inside are destroyed.
You can get a folder from a storage :
AssetFolder folder = myStorage.GetFolder("Content");
// or
AssetFolder folder = myStorage["Content"];
AssetEngine class has a property named GlobalStorage.
This storage is created when a new AssetEngine instance is created and is destroyed only when the AssetEngine instance is destroyed.
This storage can be used to stored assets that live during the whole lifetime of the game.
Accessing the global storage is easy :
Storage globalStorage = assetEngine.GlobalStorage;