/// <summary> /// Create a clone of a BlobAssetReference /// </summary> /// <param name="source"></param> /// <returns></returns> public static unsafe BlobAssetReference <T> Clone <T>(this BlobAssetReference <T> source) where T : struct { if (source == BlobAssetReference <T> .Null) { return(BlobAssetReference <T> .Null); } var writer = new MemoryBinaryWriter(); writer.Write(source); var reader = new MemoryBinaryReader(writer.Data); var clone = reader.Read <T>(); writer.Dispose(); reader.Dispose(); return(clone); }
public static unsafe BlobAssetReference <NodeBlob> ToBlob(this TextAsset file) { var dataPtr = UnsafeUtility.PinGCArrayAndGetDataAddress(file.bytes, out var gcHandle); var reader = new MemoryBinaryReader((byte *)dataPtr); try { var storedVersion = reader.ReadInt(); if (storedVersion != NodeBlob.VERSION) { throw new FormatException("Version is not match."); } return(reader.Read <NodeBlob>()); } finally { reader.Dispose(); UnsafeUtility.ReleaseGCObject(gcHandle); } }