-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathRegeneratePrecompiledLayouts.cs
More file actions
54 lines (49 loc) · 1.84 KB
/
RegeneratePrecompiledLayouts.cs
File metadata and controls
54 lines (49 loc) · 1.84 KB
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
45
46
47
48
49
50
51
52
53
54
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Editor;
namespace Editor
{
internal static class RegeneratePrecompiledLayouts
{
private static void GeneratePrecompiledLayout(string path, string layoutName)
{
var filePath = Path.Combine(path, "Fast" + layoutName + ".cs");
if (!File.Exists(filePath))
{
Debug.Log($"Cannot generate precompiled layout for: '{filePath}', only existing files may be updated.");
return;
}
var code = InputLayoutCodeGenerator.GenerateCodeFileForDeviceLayout(layoutName, filePath, prefix: "Fast");
var existingContent = File.ReadAllText(filePath);
if (string.Compare(existingContent, code, StringComparison.InvariantCulture) == 0)
{
Debug.Log($"Skipped updating precompiled layout: '{filePath}'. No difference.");
return;
}
try
{
File.WriteAllText(filePath, code);
}
catch (Exception e)
{
Debug.LogException(e);
return;
}
Debug.Log($"Updated precompiled layout: '{filePath}'.");
}
private static void GeneratePrecompiledLayouts(string path)
{
GeneratePrecompiledLayout(path, nameof(Keyboard));
GeneratePrecompiledLayout(path, nameof(Mouse));
GeneratePrecompiledLayout(path, nameof(Touchscreen));
}
[MenuItem("QA Tools/Regenerate Precompiled Layouts", priority = 20)]
private static void GeneratePrecompiledLayouts()
{
GeneratePrecompiledLayouts("Packages/com.unity.inputsystem/InputSystem/Runtime/Devices/Precompiled");
}
}
}