Skip to content

Commit 7122b64

Browse files
committed
Manually remove keywords at the end
1 parent 9cea629 commit 7122b64

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

Editor/ShaderGenerator.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,7 @@ public void GenerateShader()
426426

427427
PostGeneration?.Invoke(ShaderFile, this);
428428

429-
MatchCollection m = Regex.Matches(ShaderFile.ToString(), @"#K#.*$", RegexOptions.Multiline);
430-
for (int i = m.Count - 1; i >= 0; i--)
431-
ShaderFile.Replace(m[i].Value, "");
429+
RemoveKeywords();
432430

433431
ShaderFile.Replace("\r\n", "\n");
434432

@@ -539,7 +537,7 @@ private void WriteShaderSkeleton()
539537
}
540538
}
541539
}
542-
MatchCollection mkr = Regex.Matches(ShaderFile.ToString(), @"#KI#\S*", RegexOptions.Multiline);
540+
MatchCollection mkr = Regex.Matches(ShaderFile.ToString(), @"#KI#.*$", RegexOptions.Multiline);
543541
for (int i = mkr.Count - 1; i >= 0; i--)
544542
ShaderFile.Replace(mkr[i].Value, "");
545543
//}
@@ -654,7 +652,38 @@ private void WriteFunctionCallSequence(StringBuilder callSequence, string append
654652
}
655653
}
656654

657-
//check a line of the property block
655+
// Remove keywords from string
656+
private void RemoveKeywords()
657+
{
658+
int current = 0;
659+
660+
while (current < ShaderFile.Length)
661+
{
662+
if (ShaderFile.Length >= current + 3 && ShaderFile[current] == '#' && ShaderFile[current + 1] == 'K' &&
663+
ShaderFile[current + 2] == '#')
664+
{
665+
int end = current+3;
666+
bool stillToRemove = true;
667+
while (end < ShaderFile.Length)
668+
{
669+
if (char.IsWhiteSpace(ShaderFile[end]))
670+
{
671+
ShaderFile.Remove(current, end - current);
672+
stillToRemove = false;
673+
break;
674+
}
675+
676+
end++;
677+
}
678+
if(stillToRemove)
679+
ShaderFile.Remove(current, end - current);
680+
}
681+
682+
current++;
683+
}
684+
}
685+
686+
// Check a line of the property block
658687
private static bool CheckPropertyBlockLine(StringBuilder builder, StringReader reader, string line, ref int tabs, ref bool deleteEmptyLine)
659688
{
660689
string ln = null;

0 commit comments

Comments
 (0)