-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBurstCompilerAdder.cs
44 lines (34 loc) · 1.36 KB
/
BurstCompilerAdder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
public class BurstCompilerAdder : MonoBehaviour
{
[MenuItem("Tools/Burst/Add Burst Attribute To All classes")]
public static void ConvertClasses()
{
ProcessDirectory(Application.dataPath + "/Scripts");
}
private static void ProcessDirectory(string directoryPath)
{
DirectoryInfo dirInfo = new DirectoryInfo(directoryPath);
FileInfo[] files = dirInfo.GetFiles("*.cs");
foreach (FileInfo file in files)
ProcessFile(file);
DirectoryInfo[] subDirectories = dirInfo.GetDirectories();
foreach (DirectoryInfo subDirectory in subDirectories)
ProcessDirectory(subDirectory.FullName);
}
private static void ProcessFile(FileInfo file)
{
string text = File.ReadAllText(file.FullName);
string[] lines = text.Split('\n');
bool hasBurstUsing = lines.Any(line => line.Contains("using Unity.Burst;"));
bool hasBurstCompile = lines.Any(line => line.Contains("[BurstCompile]"));
if (!hasBurstUsing) text = "using Unity.Burst;\n" + text;
if (!hasBurstCompile)
text = Regex.Replace(text, @"(public|private|abstract|sealed|partial)?\s*class\s+(\w+)", "[BurstCompile]\n$0");
File.WriteAllText(file.FullName, text);
}
}