public static void WriteCollision(this BinaryWriter writer, LEGOPrimitiveCollision collision) { writer.Write(collision.Items.Length); foreach (object obj in collision.Items) { if (obj is LEGOPrimitiveCollisionBox) { writer.Write(0); writer.WriteCollisionBox(obj as LEGOPrimitiveCollisionBox); } if (obj is LEGOPrimitiveCollisionSphere) { writer.Write(1); writer.WriteCollisionSphere(obj as LEGOPrimitiveCollisionSphere); } if (obj is LEGOPrimitiveCollisionTube) { writer.Write(2); writer.WriteCollisionTube(obj as LEGOPrimitiveCollisionTube); } } }
public static LEGOPrimitiveCollision ReadCollision(this BinaryReader reader) { LEGOPrimitiveCollision primitiveCollision = new LEGOPrimitiveCollision(); int length = reader.ReadInt32(); primitiveCollision.Items = new object[length]; for (int index = 0; index < primitiveCollision.Items.Length; ++index) { int num = reader.ReadInt32(); if (num == 0) { primitiveCollision.Items[index] = (object)new LEGOPrimitiveCollisionBox() { angle = reader.ReadSingle(), ax = reader.ReadSingle(), ay = reader.ReadSingle(), az = reader.ReadSingle(), sX = reader.ReadSingle(), sY = reader.ReadSingle(), sZ = reader.ReadSingle(), tx = reader.ReadSingle(), ty = reader.ReadSingle(), tz = reader.ReadSingle() } } ; if (num == 1) { primitiveCollision.Items[index] = (object)new LEGOPrimitiveCollisionSphere() { radius = reader.ReadSingle(), angle = reader.ReadSingle(), ax = reader.ReadSingle(), ay = reader.ReadSingle(), az = reader.ReadSingle(), tx = reader.ReadSingle(), ty = reader.ReadSingle(), tz = reader.ReadSingle() } } ; if (num == 2) { primitiveCollision.Items[index] = (object)new LEGOPrimitiveCollisionTube() { angle = reader.ReadSingle(), ax = reader.ReadSingle(), ay = reader.ReadSingle(), az = reader.ReadSingle(), tx = reader.ReadSingle(), ty = reader.ReadSingle(), tz = reader.ReadSingle(), length = reader.ReadSingle(), innerRadius = reader.ReadSingle(), outerRadius = reader.ReadSingle() } } ; } return(primitiveCollision); }