Struct BlobAssetComputationContext<TS, TB>
The BlobAssetComputationContext must be used during Authoring to ECS conversion process to detect which BlobAsset should be computed and to declare their association with a UnityObject
Namespace: Unity.Entities
Syntax
public struct BlobAssetComputationContext<TS, TB> : IDisposable where TS : struct where TB : struct
Type Parameters
Name | Description |
---|---|
TS | The type of the setting struct to be used to generate the BlobAsset |
TB | The type of the BlobAsset to generate |
Remarks
The context must typically be used in a three stages conversion process, for given type of BlobAsset to process. Multiple context can be used if multiple BlobAsset types are generated. Stages: 1) Each Authoring component to convert are evaluated> The user calls AssociateBlobAssetWithUnityObject(Hash128, Object) to declare the association between the UnityObject owning the Authoring component and the BlobAsset being processed. Then NeedToComputeBlobAsset(Hash128) is called to determine if the BlobAsset needs to be computed or if it's already in the store (or registered for computation). The user creates the setting object that contains the necessary information to create the BlobAsset later on and calls AddBlobAssetToCompute(Hash128, TS). 2) The user creates a job to compute all BlobAsset and calls GetSettings(Allocator) to feed the job with the settings of each BlobAsset to compute. During the job execution, the BlobAsset will be created and typically stored in a result array. After the job is done, the user must call AddComputedBlobAsset(Hash128, BlobAssetReference<TB>) to add the newly created BlobAsset to the context (and the Store) 3) The user create ECS Components and attaches the BlobAsset by callingGetBlobAsset(Hash128, out BlobAssetReference<TB>). When the context will be disposed (typically after the conversion process is done), the store will be updated with the new associations between the BlobAsset and the UnityObject(s) that use them. If a BlobAsset is no longer used by any UnityObject, it will be disposed. Thread-safety: main thread only.
Constructors
BlobAssetComputationContext(BlobAssetStore, Int32, Allocator)
Declaration
public BlobAssetComputationContext(BlobAssetStore blobAssetStore, int initialCapacity, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
BlobAssetStore | blobAssetStore | |
Int32 | initialCapacity | |
Allocator | allocator |
Properties
IsCreated
Declaration
public readonly bool IsCreated { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
AddBlobAssetToCompute(Hash128, TS)
Call this method to record a setting object that will be used to compute a BlobAsset
Declaration
public void AddBlobAssetToCompute(Hash128 hash, TS settings)
Parameters
Type | Name | Description |
---|---|---|
Hash128 | hash | The hash associated with the BlobAsset |
TS | settings | The setting object to store |
AddComputedBlobAsset(Hash128, BlobAssetReference<TB>)
Add a newly created BlobAsset in the context and its Store.
Declaration
public void AddComputedBlobAsset(Hash128 hash, BlobAssetReference<TB> blob)
Parameters
Type | Name | Description |
---|---|---|
Hash128 | hash | The hash associated to the BlobAsset |
BlobAssetReference<TB> | blob | The BlobAsset to add |
AssociateBlobAssetWithUnityObject(Hash128, Object)
Declare the BlobAsset being associated with the given UnityObject
Declaration
public void AssociateBlobAssetWithUnityObject(Hash128 hash, Object unityObject)
Parameters
Type | Name | Description |
---|---|---|
Hash128 | hash | The hash associated to the BlobAsset |
Object | unityObject | The UnityObject associated with the BlobAsset |
Remarks
One of the role of the BlobAssetComputationContext<TS, TB> is to track the new association between Authoring UnityObject and BlobAsset and report them to the BlobAssetStore to automatically track the life-time of the BlobAssetReference<T> and release the instances that are no longer used.
Dispose()
Dispose the Computation context, update the BlobAssetStore with the new BlobAsset/UnityObject associations
Declaration
public void Dispose()
Remarks
This method will calls UpdateBlobStore() to ensure the store is up to date.
GetBlobAsset(Hash128, out BlobAssetReference<TB>)
Get the blob asset for the corresponding hash
Declaration
public bool GetBlobAsset(Hash128 hash, out BlobAssetReference<TB> blob)
Parameters
Type | Name | Description |
---|---|---|
Hash128 | hash | The hash associated with the BlobAsset |
BlobAssetReference<TB> | blob | The BlobAsset corresponding to the given Hash |
Returns
Type | Description |
---|---|
Boolean | true if the blob asset was found, false otherwise |
GetSettings(Allocator)
Declaration
public NativeArray<TS> GetSettings(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator |
Returns
Type | Description |
---|---|
NativeArray<TS> |
NeedToComputeBlobAsset(Hash128)
During the conversion process, the user must call this method for each BlobAsset being processed, to determine if it requires to be computed
Declaration
public bool NeedToComputeBlobAsset(Hash128 hash)
Parameters
Type | Name | Description |
---|---|---|
Hash128 | hash | The hash associated to the BlobAsset |
Returns
Type | Description |
---|---|
Boolean | true if the BlobAsset must be computed, false if it's already in the store or the computing queue |
UpdateBlobStore()
Update the store with the recorded BlobAsset/UnityObject associations.
Declaration
public void UpdateBlobStore()
Remarks
User don't have to call this method because Dispose() will do it. This method can be called multiple times, on the first one will matter.