Skip to content

Commit 205e3ad

Browse files
committed
Strip comments and whitespace from assembly export
1 parent f2de786 commit 205e3ad

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Assets/UdonSharp/Editor/UdonSharpEditorUtility.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using System.Reflection;
8+
using System.Text;
89
using UdonSharp;
910
using UdonSharp.Serialization;
1011
using UnityEditor;
@@ -42,6 +43,25 @@ public static UdonAssemblyProgramAsset UdonSharpProgramToAssemblyProgram(UdonSha
4243

4344
string programAssembly = UdonSharpEditorCache.Instance.GetUASMStr(udonSharpProgramAsset);
4445

46+
// Strip comments/inline code
47+
StringBuilder asmBuilder = new StringBuilder();
48+
49+
using (StringReader reader = new StringReader(programAssembly))
50+
{
51+
string line = reader.ReadLine();
52+
53+
while (line != null)
54+
{
55+
if (!string.IsNullOrWhiteSpace(line) &&
56+
!line.TrimStart().StartsWith("#", System.StringComparison.Ordinal))
57+
asmBuilder.AppendFormat("{0}\n", line);
58+
59+
line = reader.ReadLine();
60+
}
61+
}
62+
63+
programAssembly = asmBuilder.ToString();
64+
4565
FieldInfo assemblyField = typeof(UdonAssemblyProgramAsset).GetField("udonAssembly", BindingFlags.NonPublic | BindingFlags.Instance);
4666
assemblyField.SetValue(newProgramAsset, programAssembly);
4767

0 commit comments

Comments
 (0)