Photon Quantum 3.0.0

Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Properties | Events | List of all members
Quantum.QuantumUnityDB Class Reference

At runtime, servers as the default implementation of IResourceManager for Unity. During edit time, it collects and keeps track of all the AssetObject assets in the project. Collected assets are stored as IQuantumAssetObjectSource references, avoiding forming hard-references to the actual assets (if possible). More...

Inheritance diagram for Quantum.QuantumUnityDB:
Quantum.QuantumGlobalScriptableObject< QuantumUnityDB > Quantum.IResourceManager

Classes

class  Entry
 Internal representation of an asset in the DB. Serialized data remains immutable, while the runtime data is mutable. More...
 

Public Member Functions

void AddAsset (AssetObject asset)
 Registers a static asset. This is equivalent to calling AddSource with a QuantumAssetObjectSourceStatic. More...
 
void AddSource (IQuantumAssetObjectSource source, AssetGuid guid, string path=null)
 Registers a source for the asset with the given guid and an optional path . More...
 
void DisposeAllAssetsImmediate ()
 Disposes all the assets that have been loaded by the DB. More...
 
bool DisposeAsset (AssetGuid guid, bool immediate=false)
 Disposes the asset with the given guid . If immediate is true, the asset is disposed immediately, otherwise it's scheduled for disposal during the next update. More...
 
bool FindNextAssetGuid (ref AssetObjectQuery query, out AssetGuid guid)
 Finds the next asset GUID based on the provided query.
 
AssetObject GetAsset (AssetGuid guid)
 Loads the asset with the given guid synchronously. More...
 
AssetGuid GetAssetGuid (string path)
 Converts a Quantum asset path to a Quantum asset guid. More...
 
string GetAssetPath (AssetGuid assetGuid)
 Returns path for the asset with the given assetGuid . Asset does not get loaded in the process. More...
 
IQuantumAssetObjectSource GetAssetSource (AssetGuid assetGuid)
 Returns the asset source with the given assetGuid . Asset does not get loaded in the process. More...
 
IQuantumAssetObjectSource GetAssetSource (string assetPath)
 Returns the asset source with the given assetPath . Asset does not get loaded in the process. More...
 
AssetObjectState GetAssetState (AssetGuid guid)
 Gets the state of an asset.
 
Type GetAssetType (AssetGuid guid)
 Returns the type of the asset with the given guid . More...
 
bool LoadAssetAsync (AssetGuid guid)
 Loads the asset with the given guid asynchronously. More...
 
bool RemoveSource (AssetGuid guid)
 Removes the source for the asset with the given guid . More...
 
bool RemoveSource (AssetGuid guid, out(IQuantumAssetObjectSource source, bool isAcquired) result)
 Removes the source for the asset with the given guid . More...
 

Static Public Member Functions

static AssetGuid CreateRuntimeDeterministicGuid (AssetObject assetObject)
 Returns a deterministic AssetGuid for the given assetObject . Used for adding static assets at runtime to the DB. More...
 
static AssetGuid CreateRuntimeDeterministicGuid (string assetName, Type assetType)
 Creates a deterministic guid based on the asset name and type. More...
 
static AssetGuid CreateRuntimeDeterministicGuid (string path)
 Creates a deterministic GUID based and the provided path. More...
 
static AssetGuid CreateRuntimeDeterministicGuid< T > (ReadOnlySpan< T > data, long initialHash=0)
 Creates a deterministic GUID based and the provided data. More...
 
static bool DisposeGlobalAsset (AssetGuid assetGuid, bool immediate=false)
 
static AssetGuid FindGlobalAssetGuid (AssetObjectQuery query)
 Finds the asset GUID based on the provided query. More...
 
static List< AssetGuidFindGlobalAssetGuids (AssetObjectQuery query)
 Finds the asset GUIDs based on the provided query. More...
 
static void FindGlobalAssetGuids (AssetObjectQuery query, List< AssetGuid > result)
 Finds the asset GUIDs based on the provided query. More...
 
static AssetObject GetGlobalAsset (AssetRef assetRef)
 
static AssetObject GetGlobalAsset (string assetPath)
 Gets an asset based on its path. More...
 
static T GetGlobalAsset< T > (AssetRef< T > assetRef)
 
static AssetGuid GetGlobalAssetGuid (string path)
 
static string GetGlobalAssetPath (AssetGuid assetGuid)
 
static IQuantumAssetObjectSource GetGlobalAssetSource (AssetGuid assetGuid)
 
static IQuantumAssetObjectSource GetGlobalAssetSource (string assetPath)
 
static AssetObjectState GetGlobalAssetState (AssetGuid guid)
 
static Type GetGlobalAssetType (AssetGuid guid)
 
static bool TryGetGlobalAsset< T > (AssetGuid assetGuid, out T result)
 Tries to get an asset of type T from the global DB. Note that if type T is not the same as the asset type, the asset will remain loaded in the memory until it is disposed. More...
 
static bool TryGetGlobalAsset< T > (AssetRef assetRef, out T result)
 
static bool TryGetGlobalAsset< T > (AssetRef< T > assetRef, out T result)
 
static bool TryGetGlobalAsset< T > (string assetPath, out T result)
 Tries to get an asset of type T from the global DB. Note that if type T is not the same as the asset type, the asset will remain loaded in the memory until it is disposed. More...
 
static bool UnloadGlobal ()
 Unloads Global, if already loaded and unloads any asset that has been loaded. Next call to Global will load the DB again. More...
 
static void UpdateGlobal ()
 Updates Global DB, if loaded. Must be called from the main thread. Call periodically, if assets are loaded/unloaded without the simulation running. More...
 

Public Attributes

IReadOnlyList< EntryEntries => _entries
 Exposes the list of entries in the DB. Can be used to iterate asset sources at both runtime and edit time. More...
 
uint Version => _version
 A version number that is increased every time an asset is added or removed. More...
 

Static Public Attributes

const string DefaultPath = "Assets/QuantumUser/Resources/QuantumUnityDB.qunitydb"
 The default location of the DB asset. More...
 
const char NestedPathSeparator = '|'
 Character used to separate nested assets names from their parents path. More...
 

Protected Member Functions

override void OnDisable ()
 Disposes all the assets that have been loaded by the DB. More...
 
void OnEnable ()
 Initializes the DB with asset sources collected from the project. More...
 
override void OnUnloadedAsGlobal (bool destroyed)
 Unloads all the assets that have been loaded by the Global DB. More...
 

Properties

static new QuantumUnityDB Global [get, set]
 Returns the global DB. If the DB is not loaded, it will be loaded. More...
 

Events

AssetObjectDisposingDelegate AssetObjectDisposing
 Raised when an asset is unloaded. More...
 
- Events inherited from Quantum.IResourceManager
AssetObjectDisposingDelegate AssetObjectDisposing
 Invoked before AssetObject.Disposed. Exposed as an event, because assets may be disposed externally. Any code using any form of asset caching needs to be aware of that happening. More...
 

Detailed Description

At runtime, servers as the default implementation of IResourceManager for Unity. During edit time, it collects and keeps track of all the AssetObject assets in the project. Collected assets are stored as IQuantumAssetObjectSource references, avoiding forming hard-references to the actual assets (if possible).

Member Function Documentation

◆ OnEnable()

void Quantum.QuantumUnityDB.OnEnable ( )
inlineprotected

Initializes the DB with asset sources collected from the project.

◆ OnDisable()

override void Quantum.QuantumUnityDB.OnDisable ( )
inlineprotected

Disposes all the assets that have been loaded by the DB.

◆ UpdateGlobal()

static void Quantum.QuantumUnityDB.UpdateGlobal ( )
inlinestatic

Updates Global DB, if loaded. Must be called from the main thread. Call periodically, if assets are loaded/unloaded without the simulation running.

◆ UnloadGlobal()

static bool Quantum.QuantumUnityDB.UnloadGlobal ( )
inlinestatic

Unloads Global, if already loaded and unloads any asset that has been loaded. Next call to Global will load the DB again.

◆ OnUnloadedAsGlobal()

override void Quantum.QuantumUnityDB.OnUnloadedAsGlobal ( bool  destroyed)
inlineprotected

Unloads all the assets that have been loaded by the Global DB.

Parameters
destroyed

◆ CreateRuntimeDeterministicGuid() [1/3]

static AssetGuid Quantum.QuantumUnityDB.CreateRuntimeDeterministicGuid ( AssetObject  assetObject)
inlinestatic

Returns a deterministic AssetGuid for the given assetObject . Used for adding static assets at runtime to the DB.

Parameters
assetObjectThe AssetObject generate the AssetGuid for.
Returns
The generated AssetGuid.

◆ CreateRuntimeDeterministicGuid() [2/3]

static AssetGuid Quantum.QuantumUnityDB.CreateRuntimeDeterministicGuid ( string  assetName,
Type  assetType 
)
inlinestatic

Creates a deterministic guid based on the asset name and type.

Parameters
assetName
assetType
Returns

◆ AddSource()

void Quantum.QuantumUnityDB.AddSource ( IQuantumAssetObjectSource  source,
AssetGuid  guid,
string  path = null 
)
inline

Registers a source for the asset with the given guid and an optional path .

Parameters
source
guid
path

◆ AddAsset()

void Quantum.QuantumUnityDB.AddAsset ( AssetObject  asset)
inline

Registers a static asset. This is equivalent to calling AddSource with a QuantumAssetObjectSourceStatic.

Parameters
asset

◆ RemoveSource() [1/2]

bool Quantum.QuantumUnityDB.RemoveSource ( AssetGuid  guid,
out(IQuantumAssetObjectSource source, bool isAcquired)  result 
)
inline

Removes the source for the asset with the given guid .

Parameters
guid
result
Returns
true if there was a matching source to remove

◆ RemoveSource() [2/2]

bool Quantum.QuantumUnityDB.RemoveSource ( AssetGuid  guid)
inline

Removes the source for the asset with the given guid .

Parameters
guid
Returns
true if there was a matching source to remove

◆ CreateRuntimeDeterministicGuid() [3/3]

static AssetGuid Quantum.QuantumUnityDB.CreateRuntimeDeterministicGuid ( string  path)
inlinestatic

Creates a deterministic GUID based and the provided path.

◆ CreateRuntimeDeterministicGuid< T >()

static AssetGuid Quantum.QuantumUnityDB.CreateRuntimeDeterministicGuid< T > ( ReadOnlySpan< T >  data,
long  initialHash = 0 
)
inlinestatic

Creates a deterministic GUID based and the provided data.

T.GetHashCode() must be deterministic.

Type Constraints
T :unmanaged 

◆ FindGlobalAssetGuid()

static AssetGuid Quantum.QuantumUnityDB.FindGlobalAssetGuid ( AssetObjectQuery  query)
inlinestatic

Finds the asset GUID based on the provided query.

Parameters
queryThe query to filter the assets.
Returns
The asset GUID.

◆ FindGlobalAssetGuids() [1/2]

static void Quantum.QuantumUnityDB.FindGlobalAssetGuids ( AssetObjectQuery  query,
List< AssetGuid result 
)
inlinestatic

Finds the asset GUIDs based on the provided query.

Parameters
queryThe query to filter the assets.
resultThe list to store results.

◆ FindGlobalAssetGuids() [2/2]

static List<AssetGuid> Quantum.QuantumUnityDB.FindGlobalAssetGuids ( AssetObjectQuery  query)
inlinestatic

Finds the asset GUIDs based on the provided query.

Parameters
queryThe query to filter the assets.
Returns
The list of asset GUIDs.

◆ GetGlobalAsset< T >()

static T Quantum.QuantumUnityDB.GetGlobalAsset< T > ( AssetRef< T >  assetRef)
inlinestatic
Returns
The loaded asset object or null, if not found or its type does not match T .
Type Constraints
T :AssetObject 

◆ GetGlobalAsset()

static AssetObject Quantum.QuantumUnityDB.GetGlobalAsset ( string  assetPath)
inlinestatic

Gets an asset based on its path.

Parameters
assetPathThe path of the asset.
Returns
The asset object.

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

static bool Quantum.QuantumUnityDB.TryGetGlobalAsset< T > ( AssetGuid  assetGuid,
out T  result 
)
inlinestatic

Tries to get an asset of type T from the global DB. Note that if type T is not the same as the asset type, the asset will remain loaded in the memory until it is disposed.

Parameters
assetGuidThe guid of the asset.
resultThe result asset object.
Returns
true if the asset of type T exists.
Type Constraints
T :AssetObject 

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

static bool Quantum.QuantumUnityDB.TryGetGlobalAsset< T > ( string  assetPath,
out T  result 
)
inlinestatic

Tries to get an asset of type T from the global DB. Note that if type T is not the same as the asset type, the asset will remain loaded in the memory until it is disposed.

Parameters
assetPathThe path of the asset.
resultThe result asset object.
Returns
true if the asset of type T exists.
Type Constraints
T :AssetObject 

◆ GetAssetSource() [1/2]

IQuantumAssetObjectSource Quantum.QuantumUnityDB.GetAssetSource ( AssetGuid  assetGuid)
inline

Returns the asset source with the given assetGuid . Asset does not get loaded in the process.

Parameters
assetGuid
Returns
Asset source or null if the asset is not found

◆ GetAssetSource() [2/2]

IQuantumAssetObjectSource Quantum.QuantumUnityDB.GetAssetSource ( string  assetPath)
inline

Returns the asset source with the given assetPath . Asset does not get loaded in the process.

Parameters
assetPath
Returns
Asset source or null if the asset is not found

◆ GetAssetGuid()

AssetGuid Quantum.QuantumUnityDB.GetAssetGuid ( string  path)
inline

Converts a Quantum asset path to a Quantum asset guid.

Parameters
path
Returns

Implements Quantum.IResourceManager.

◆ GetAssetPath()

string Quantum.QuantumUnityDB.GetAssetPath ( AssetGuid  assetGuid)
inline

Returns path for the asset with the given assetGuid . Asset does not get loaded in the process.

Parameters
assetGuid
Returns
Asset path or an empty string, if not found

◆ DisposeAsset()

bool Quantum.QuantumUnityDB.DisposeAsset ( AssetGuid  guid,
bool  immediate = false 
)
inline

Disposes the asset with the given guid . If immediate is true, the asset is disposed immediately, otherwise it's scheduled for disposal during the next update.

Parameters
guid
immediate
Returns
false if the asset is not found
Exceptions
InvalidOperationExceptionIf called from non-main thread

◆ DisposeAllAssetsImmediate()

void Quantum.QuantumUnityDB.DisposeAllAssetsImmediate ( )
inline

Disposes all the assets that have been loaded by the DB.

Exceptions
InvalidOperationExceptionIf called from non-main thread

◆ GetAsset()

AssetObject Quantum.QuantumUnityDB.GetAsset ( AssetGuid  guid)
inline

Loads the asset with the given guid synchronously.

Parameters
guidGuid of the asset to load
Returns
Asset reference or null if the asset is not found

Implements Quantum.IResourceManager.

◆ LoadAssetAsync()

bool Quantum.QuantumUnityDB.LoadAssetAsync ( AssetGuid  guid)
inline

Loads the asset with the given guid asynchronously.

Parameters
guidGuid of the asset to load
Returns
false if the asset is not found, true otherwise

Implements Quantum.IResourceManager.

◆ GetAssetType()

Type Quantum.QuantumUnityDB.GetAssetType ( AssetGuid  guid)
inline

Returns the type of the asset with the given guid .

Parameters
guidGuid of the asset to find
Returns
null if the asset is not found or its source does not have type info, type instance otherwise.

Implements Quantum.IResourceManager.

Member Data Documentation

◆ DefaultPath

const string Quantum.QuantumUnityDB.DefaultPath = "Assets/QuantumUser/Resources/QuantumUnityDB.qunitydb"
static

The default location of the DB asset.

◆ NestedPathSeparator

const char Quantum.QuantumUnityDB.NestedPathSeparator = '|'
static

Character used to separate nested assets names from their parents path.

◆ Entries

IReadOnlyList<Entry> Quantum.QuantumUnityDB.Entries => _entries

Exposes the list of entries in the DB. Can be used to iterate asset sources at both runtime and edit time.

◆ Version

uint Quantum.QuantumUnityDB.Version => _version

A version number that is increased every time an asset is added or removed.

Property Documentation

◆ Global

new QuantumUnityDB Quantum.QuantumUnityDB.Global
staticgetset

Returns the global DB. If the DB is not loaded, it will be loaded.

Event Documentation

◆ AssetObjectDisposing

AssetObjectDisposingDelegate Quantum.QuantumUnityDB.AssetObjectDisposing

Raised when an asset is unloaded.