public void Write(UnityBinaryWriter writer) { // Skip Header since MetadataSize and DataOffset are unknown int header_pos = writer.Position; writer.Position += Header.CalcSize(); // Write Metadata writeMetadata(writer); // Write Objects byte[] body = writeObjects(writer); // Write Scripts writeScripts(writer); // Write Externals writeExternals(writer); // Write UserInformation writer.WriteStringToNull(UserInformation); Header.MetadataSize = writer.Position - Header.CalcSize(); // Align body if (writer.Position < 0x1000) { writer.Position = 0x1000; } else { writer.Align(16); } Header.DataOffset = writer.Position; // Write body writer.WriteBytes(body); // Write Header Header.FileSize = writer.Position; writer.Position = header_pos; Header.Write(writer); }
private byte[] writeObjects(UnityBinaryWriter writer) { writer.WriteInt(Objects.Length); UnityBinaryWriter objectwriter = new UnityBinaryWriter(); for (int i = 0; i < Objects.Length; i++) { // objects alignment is 8byte writer.Align(4); writer.WriteLong(Objects[i].PathID); objectwriter.Align(8); writer.WriteInt(objectwriter.Position); writer.WriteInt(Objects[i].Data.Length); writer.WriteInt(Objects[i].TypeID); objectwriter.WriteBytes(Objects[i].Data); } // return body return(objectwriter.ToBytes()); }
public static void WriteAlignedString(this UnityBinaryWriter writer, string str) { writer.WriteString(str); writer.Align(4); }
public void Write(UnityBinaryWriter writer) { writer.WriteInt(Index); writer.Align(4); writer.WriteLong(Identifier); }