Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public static string GetSerializationPath(string name)
{
return string.Format("{0}/{1}.bin", Application.streamingAssetsPath, name);
}
public static unsafe BlobAssetReference<Collider> DeserializeCollider(string filename, int bytes)
{
string path = GetSerializationPath(filename);
using (StreamBinaryReader reader = new StreamBinaryReader(path, bytes))
{
int length = reader.ReadInt();
Collider* collider = (Collider*)UnsafeUtility.Malloc(length, 16, Allocator.Temp);
reader.ReadBytes(collider, length);
var blob = BlobAssetReference<Collider>.Create(collider, length);
UnsafeUtility.Free(collider, Allocator.Temp);
return blob;
}
}
public static unsafe int SerializeCollider(Collider* collider, string filename)
{
string path = GetSerializationPath(filename);
int bytes = collider->MemorySize + sizeof(int);
using (StreamBinaryWriter writer = new StreamBinaryWriter(path, bytes))
{
writer.Write(collider->MemorySize);
writer.WriteBytes(collider, collider->MemorySize);
}
return bytes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.