From 1b57a0b7dfed929b81e6d03e45254dcdf7867b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Tue, 22 Apr 2025 16:47:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E8=BE=93=E5=87=BAcs?= =?UTF-8?q?project=E5=B7=A5=E7=A8=8B=E6=96=87=E4=BB=B6=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E4=B8=BAUTF16=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/Assembly/MacroProcessor.cs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Assets/YooAsset/Editor/Assembly/MacroProcessor.cs b/Assets/YooAsset/Editor/Assembly/MacroProcessor.cs index 265fc1e6..989030ec 100644 --- a/Assets/YooAsset/Editor/Assembly/MacroProcessor.cs +++ b/Assets/YooAsset/Editor/Assembly/MacroProcessor.cs @@ -22,13 +22,22 @@ namespace YooAsset.Editor return content; // 将修改后的XML结构重新输出为文本 - var stringWriter = new StringWriter(); - var writerSettings = new XmlWriterSettings(); - writerSettings.Indent = true; - var xmlWriter = XmlWriter.Create(stringWriter, writerSettings); - xmlDoc.WriteTo(xmlWriter); - xmlWriter.Flush(); - return stringWriter.ToString(); + using (var memoryStream = new MemoryStream()) + { + var writerSettings = new XmlWriterSettings + { + Indent = true, + Encoding = Encoding.UTF8, + OmitXmlDeclaration = false + }; + + using (var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8)) + using (var xmlWriter = XmlWriter.Create(streamWriter, writerSettings)) + { + xmlDoc.Save(xmlWriter); + } + return Encoding.UTF8.GetString(memoryStream.ToArray()); + } } ///