Photon Quantum 3.0.0

Public Member Functions | Public Attributes | List of all members
Quantum.DynamicAssetDB Class Reference

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 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...
 
FindAsset< T > (AssetGuid guid)
 Finds an asset of type T with the specified AssetGuid. More...
 
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:

More...
 
AssetGuid NextGuid => new AssetGuid((_lastGuid + 1) | AssetGuid.DynamicBit)
 Gets the next available AssetGuid. More...
 

Detailed Description

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.

See also
IsLegacyModeEnabled

Constructor & Destructor Documentation

◆ DynamicAssetDB() [1/2]

Quantum.DynamicAssetDB.DynamicAssetDB ( Native.Allocator  allocator,
bool  isLegacyMode = false,
AssetGuid lastGuid = default 
)
inline

Initializes a new instance of the DynamicAssetDB class.

Parameters
allocator
lastGuidThe lastGuid value to set.
isLegacyMode

◆ DynamicAssetDB() [2/2]

Quantum.DynamicAssetDB.DynamicAssetDB ( DynamicAssetDB  other)
inline

Initializes a new instance of the DynamicAssetDB class with the same state as another DynamicAssetDB instance.

Parameters
otherThe DynamicAssetDB instance to copy from.

Member Function Documentation

◆ AddAsset()

AssetGuid Quantum.DynamicAssetDB.AddAsset ( AssetObject  asset)
inline

Adds an asset to the DynamicAssetDB and assigns it a new AssetGuid.

Parameters
assetThe asset to add.
Returns
The AssetGuid assigned to the added asset.

◆ AddAssetWithValidDynamicGuid()

void Quantum.DynamicAssetDB.AddAssetWithValidDynamicGuid ( AssetObject  asset)
inline

Adds an asset to the DynamicAssetDB with a valid dynamic AssetGuid. Does not call AssetObject.Loaded

Parameters
assetThe asset to add.

◆ ReplaceAsset()

AssetObject Quantum.DynamicAssetDB.ReplaceAsset ( AssetGuid  guid,
AssetObject  asset 
)
inline

Replaces an asset with the specified AssetGuid with a new asset.

Parameters
guidThe AssetGuid of the asset to replace.
assetThe new asset to replace with.
Returns
Replaced asset or null, if there was no asset with guid

◆ DisposeAsset()

bool Quantum.DynamicAssetDB.DisposeAsset ( AssetGuid  guid)
inline

Disposes the asset with the specified AssetGuid from the DynamicAssetDB.

Parameters
guidThe AssetGuid of the asset to dispose.
Returns
true if the asset was successfully disposed, false otherwise.

◆ CopyFrom()

void Quantum.DynamicAssetDB.CopyFrom ( DynamicAssetDB  other)
inline

Copies the state of another DynamicAssetDB instance to this instance.

Parameters
otherThe DynamicAssetDB instance to copy from.

◆ Deserialize()

void Quantum.DynamicAssetDB.Deserialize ( byte[]  bytes,
IAssetSerializer  assetSerializer 
)
inline

Deserializes the DynamicAssetDB from a byte array using the specified assetSerializer and allocator.

Parameters
bytesThe byte array containing the serialized DynamicAssetDB.
assetSerializerThe asset serializer to use for deserialization.

◆ Serialize() [1/2]

byte [] Quantum.DynamicAssetDB.Serialize ( IAssetSerializer  serializer)
inline

Serializes the DynamicAssetDB using the specified serializer and returns the serialized byte array.

Parameters
serializerThe serializer to use for serialization.
Returns
The serialized byte array.

◆ Serialize() [2/2]

void Quantum.DynamicAssetDB.Serialize ( IAssetSerializer  serializer,
out byte[]  header,
out byte[]  assets 
)
inline

Serializes the DynamicAssetDB using the specified serializer and assigns the serialized header and assets byte arrays.

Parameters
serializerThe serializer to use for serialization.
headerThe serialized header byte array.
assetsThe serialized assets byte array.

◆ FindAsset< T >() [1/2]

Finds an asset of type T with the specified AssetGuid.

Template Parameters
TThe type of asset to find.
Parameters
guidThe AssetGuid of the asset to find.
Returns
The asset of type T with the specified AssetGuid, or null if not found.
Type Constraints
T :AssetObject 

◆ FindAsset() [1/2]

AssetObject Quantum.DynamicAssetDB.FindAsset ( AssetGuid  guid)

Finds an asset of type AssetObject with the specified AssetGuid.

Parameters
guidThe AssetGuid of the asset to find.
Returns
The asset of type AssetObject with the specified AssetGuid, or null if not found.

◆ FindAsset< T >() [2/2]

T Quantum.DynamicAssetDB.FindAsset< T > ( string  path)
inline

Finds an asset of type T with the specified path.

Template Parameters
TThe type of asset to find.
Parameters
pathThe path of the asset to find.
Returns
The asset of type T with the specified path, or null if not found.
Type Constraints
T :AssetObject 

◆ FindAsset() [2/2]

AssetObject Quantum.DynamicAssetDB.FindAsset ( string  path)

Finds an asset of type AssetObject with the specified path.

Parameters
pathThe path of the asset to find.
Returns
The asset of type AssetObject with the specified path, or null if not found.

◆ GetAssetState()

AssetObjectState Quantum.DynamicAssetDB.GetAssetState ( AssetGuid  guid)
inline

Gets the state of the asset with the specified AssetGuid.

Parameters
guidThe AssetGuid of the asset to get the state of.
Returns
The state of the asset with the specified AssetGuid.

◆ Dispose()

void Quantum.DynamicAssetDB.Dispose ( )
inline

If IsLegacyModeEnabled is disabled, invokes AssetObject.Disposed on all assets.

Member Data Documentation

◆ Allocator

readonly Native.Allocator Quantum.DynamicAssetDB.Allocator

The allocator to use when adding assets, for their AssetObject.Loaded callback.

◆ IsLegacyModeEnabled

readonly bool Quantum.DynamicAssetDB.IsLegacyModeEnabled

◆ IsEmpty

bool Quantum.DynamicAssetDB.IsEmpty => _head.ByGuid.Count == 0

Gets a value indicating whether the DynamicAssetDB is empty.

◆ NextGuid

AssetGuid Quantum.DynamicAssetDB.NextGuid => new AssetGuid((_lastGuid + 1) | AssetGuid.DynamicBit)

Gets the next available AssetGuid.

◆ Assets

AssetEnumerable Quantum.DynamicAssetDB.Assets => new AssetEnumerable(this)

Gets all the assets in the DynamicAssetDB.