This document is about: QUANTUM 3
SWITCH TO

This page has been upgraded to Quantum 3.0.

Extending Assets for Unity


Available in the Gaming Circle and Industries Circle
Circle

Overview

Quantum assets can be extended with Unity-specific data not relevant for the simulation like data for the UI (colors, texts, icons...).

Changes in 3.0

In Quantum 3, you no longer need to define your asset as partial and import it in a DSL file.

Instead, you should derive directly from AssetObject and add your desired information.

Example

Let's take the CharacterSpec asset as an example.

C#

public class CharacterSpec : AssetObject {
#if QUANTUM_UNITY
  [Header("Unity")]
  public Sprite Icon;
  public Color Color;
  public string DisplayName;
#endif
}
These fields should only be accessed in the View (Unity) and should NEVER be accessed or used in the simulation (Quantum). To ensure that doesn't happen, it's good practice to wrap any unity only references (sound, icons, etc) in an #if QUANTUM_UNITY block.

Access at Runtime

To access the extra fields at runtime, use the QuantumUnityDB.GetGlobalAsset<T>() method.

C#

CharacterSpec characterSpec = QuantumUnityDB.GetGlobalAsset<CharacterSpecAsset>(assetRef);
Debug.Log(characterSpec.DisplayName);

Both of the approaches will result in the asset being loaded into Quantum's AssetDB using the appropriate method, as discussed here: Resources and Addressables.

Access at Edit-time

To load an asset using its path while in the Unity Editor, the UnityEditor.AssetDataBase.LoadAssetAtPath<T>() method can be used.

C#

CharacterSpecAsset characterSpecAsset = UnityEditor.AssetDatabase.LoadAssetAtPath<CharacterSpecAsset>(path);
Debug.Log(characterSpecAsset.DisplayName);

Alternatively, the asset can be loaded using its AssetGuid via the QuantumUnityDB.GetGlobalAssetEditorInstance() method and casting the result to the correct type.

C#

CharacterSpec characterSpec = QuantumUnityDB.GetGlobalAssetEditorInstance(guid) as CharacterSpec;
Debug.Log(characterSpec.DisplayName);
Back to top