A DynamicAssetDB is a database of assets that can be added and removed at runtime. For late joiners, contents are serialized and deserialized using an IAssetSerializer. More...
Public Member Functions | |
DynamicAssetDB (DynamicAssetDB other) | |
Initializes a new instance of the DynamicAssetDB class with the same state as another DynamicAssetDB instance. More... | |
DynamicAssetDB (Native.Allocator allocator, bool isLegacyMode=false, AssetGuid? lastGuid=default) | |
Initializes a new instance of the DynamicAssetDB class. More... | |
AssetGuid | AddAsset (AssetObject asset) |
Adds an asset to the DynamicAssetDB and assigns it a new AssetGuid. More... | |
void | AddAsset (AssetObject asset, AssetGuid guid) |
Adds an asset to the DynamicAssetDB and assigns it a passed AssetGuid. More... | |
void | AddAssetWithValidDynamicGuid (AssetObject asset) |
Adds an asset to the DynamicAssetDB with a valid dynamic AssetGuid. Does not call AssetObject.Loaded More... | |
void | CopyFrom (DynamicAssetDB other) |
Copies the state of another DynamicAssetDB instance to this instance. More... | |
void | Deserialize (byte[] bytes, IAssetSerializer assetSerializer) |
Deserializes the DynamicAssetDB from a byte array using the specified assetSerializer and allocator. More... | |
void | Dispose () |
If IsLegacyModeEnabled is disabled, invokes AssetObject.Disposed on all assets. More... | |
bool | DisposeAsset (AssetGuid guid) |
Disposes the asset with the specified AssetGuid from the DynamicAssetDB. More... | |
AssetObject | FindAsset (AssetGuid guid) |
Finds an asset of type AssetObject with the specified AssetGuid. More... | |
AssetObject | FindAsset (string path) |
Finds an asset of type AssetObject with the specified path. More... | |
T | FindAsset< T > (AssetGuid guid) |
Finds an asset of type T with the specified AssetGuid. More... | |
T | FindAsset< T > (string path) |
Finds an asset of type T with the specified path. More... | |
AssetObjectState | GetAssetState (AssetGuid guid) |
Gets the state of the asset with the specified AssetGuid. More... | |
AssetObject | ReplaceAsset (AssetGuid guid, AssetObject asset) |
Replaces an asset with the specified AssetGuid with a new asset. More... | |
byte[] | Serialize (IAssetSerializer serializer) |
Serializes the DynamicAssetDB using the specified serializer and returns the serialized byte array. More... | |
void | Serialize (IAssetSerializer serializer, out byte[] header, out byte[] assets) |
Serializes the DynamicAssetDB using the specified serializer and assigns the serialized header and assets byte arrays. More... | |
Public Attributes | |
readonly Native.Allocator | Allocator |
The allocator to use when adding assets, for their AssetObject.Loaded callback. More... | |
AssetEnumerable | Assets => new AssetEnumerable(this) |
Gets all the assets in the DynamicAssetDB. More... | |
bool | IsEmpty => _head.ByGuid.Count == 0 |
Gets a value indicating whether the DynamicAssetDB is empty. More... | |
readonly bool | IsLegacyModeEnabled |
If true , the legacy dynamic DB behaviour will be used:
| |
AssetGuid | NextGuid => new AssetGuid(_lastGuid + 1, AssetGuidType.DynamicSequential) |
Gets the next available AssetGuid. More... | |
A DynamicAssetDB is a database of assets that can be added and removed at runtime. For late joiners, contents are serialized and deserialized using an IAssetSerializer.
All the DynamicAssetDB instances share ownership over assets due to DynamicAssetDB.CopyFrom sharing reference counts. AssetObject.Loaded is called when an asset is added or replaced, AssetObject.Disposed is called when assets' reference count reaches zero due to DynamicAssetDB.DisposeAsset, DynamicAssetDB.CopyFrom, DynamicAssetDB.ReplaceAsset or DynamicAssetDB.Dispose.
|
inline |
Initializes a new instance of the DynamicAssetDB class.
allocator | |
lastGuid | The lastGuid value to set. |
isLegacyMode |
|
inline |
Initializes a new instance of the DynamicAssetDB class with the same state as another DynamicAssetDB instance.
other | The DynamicAssetDB instance to copy from. |
|
inline |
Adds an asset to the DynamicAssetDB and assigns it a new AssetGuid.
asset | The asset to add. |
|
inline |
Adds an asset to the DynamicAssetDB and assigns it a passed AssetGuid.
asset | The asset to add. |
guid | The AssetGuid to be assigned to the added asset. Needs to be of AssetGuidType.DynamicExplicit type. |
|
inline |
Adds an asset to the DynamicAssetDB with a valid dynamic AssetGuid. Does not call AssetObject.Loaded
asset | The asset to add. |
|
inline |
Replaces an asset with the specified AssetGuid with a new asset.
guid | The AssetGuid of the asset to replace. |
asset | The new asset to replace with. |
null
, if there was no asset with guid
|
inline |
Disposes the asset with the specified AssetGuid from the DynamicAssetDB.
guid | The AssetGuid of the asset to dispose. |
true
if the asset was successfully disposed, false
otherwise.
|
inline |
Copies the state of another DynamicAssetDB instance to this instance.
other | The DynamicAssetDB instance to copy from. |
|
inline |
Deserializes the DynamicAssetDB from a byte array using the specified assetSerializer and allocator.
bytes | The byte array containing the serialized DynamicAssetDB. |
assetSerializer | The asset serializer to use for deserialization. |
|
inline |
Serializes the DynamicAssetDB using the specified serializer and returns the serialized byte array.
serializer | The serializer to use for serialization. |
|
inline |
Serializes the DynamicAssetDB using the specified serializer and assigns the serialized header and assets byte arrays.
serializer | The serializer to use for serialization. |
header | The serialized header byte array. |
assets | The serialized assets byte array. |
|
inline |
Finds an asset of type T with the specified AssetGuid.
T | The type of asset to find. |
guid | The AssetGuid of the asset to find. |
null
if not found.T | : | AssetObject |
AssetObject Quantum.DynamicAssetDB.FindAsset | ( | AssetGuid | guid | ) |
Finds an asset of type AssetObject with the specified AssetGuid.
guid | The AssetGuid of the asset to find. |
null
if not found.
|
inline |
Finds an asset of type T with the specified path.
T | The type of asset to find. |
path | The path of the asset to find. |
null
if not found.T | : | AssetObject |
AssetObject Quantum.DynamicAssetDB.FindAsset | ( | string | path | ) |
Finds an asset of type AssetObject with the specified path.
path | The path of the asset to find. |
null
if not found.
|
inline |
Gets the state of the asset with the specified AssetGuid.
guid | The AssetGuid of the asset to get the state of. |
|
inline |
If IsLegacyModeEnabled is disabled, invokes AssetObject.Disposed on all assets.
readonly Native.Allocator Quantum.DynamicAssetDB.Allocator |
The allocator to use when adding assets, for their AssetObject.Loaded callback.
readonly bool Quantum.DynamicAssetDB.IsLegacyModeEnabled |
If true
, the legacy dynamic DB behaviour will be used:
bool Quantum.DynamicAssetDB.IsEmpty => _head.ByGuid.Count == 0 |
Gets a value indicating whether the DynamicAssetDB is empty.
AssetGuid Quantum.DynamicAssetDB.NextGuid => new AssetGuid(_lastGuid + 1, AssetGuidType.DynamicSequential) |
Gets the next available AssetGuid.
AssetEnumerable Quantum.DynamicAssetDB.Assets => new AssetEnumerable(this) |
Gets all the assets in the DynamicAssetDB.