Hello, I have a few blob assets of simple ints and floats I want to make but I don't want to create so many boilerplate methods, so I attempted to use generics to help me out but currently I'm faced with a few challenges. Here is the code so far:
public interface IBlobAsset<T> where T : unmanaged
{
BlobArray<T> Array { get; set; }
}
public static class BlobHelper
{
public static BlobAssetReference<T> CreateBlobArray<T, T2>(T2[] values) where T2 : unmanaged where T : struct, IBlobAsset<T2>
{
using BlobBuilder blobBuilder = new(Allocator.Temp);
ref var valueBlob = ref blobBuilder.ConstructRoot<T>();
BlobBuilderArray<T2> valueBlobArray = blobBuilder.Allocate(ref valueBlob.Array, values.Length);
for (int i = 0; i < values.Length; i++) valueBlobArray[i] = values[i];
return blobBuilder.CreateBlobAssetReference<T>(Allocator.Persistent);
}
}
I'm making a helper method with the generic T being the BlobAssetReference and T2 being the value type of the blob array. At where it says
BlobBuilderArray<T2> valueBlobArray = blobBuilder.Allocate(ref valueBlob.Array, values.Length);
To get valueBlob.Array I had to implement an interface, but that means I can't use it as a ref, so is there a way to get access to the array without an interface? If anyone already knows of some helper methods to help me out, instead of me having to make my own, that'd be awesome.