Created
March 25, 2025 13:41
-
-
Save Pholith/25b992906abad8b060468d3dddfa5e76 to your computer and use it in GitHub Desktop.
Unity Regedit Cache Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using UnityEngine; | |
using UnityEngine.UIElements; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
public class UnityRegeditCacheHelper : EditorWindow | |
{ | |
[MenuItem("Tools/Unity Regedit Cache Helper")] | |
public static void ShowMyEditor() | |
{ | |
EditorWindow wnd = GetWindow<UnityRegeditCacheHelper>(); | |
wnd.titleContent = new GUIContent("Unity Regedit Cache Helper"); | |
wnd.minSize = new Vector2(100, 200); | |
wnd.maxSize = new Vector2(300, 600); | |
} | |
public void CreateGUI() | |
{ | |
Label description = new Label(); | |
description.style.marginTop = 5; | |
description.style.marginLeft = 2; | |
description.style.marginRight = 2; | |
description.style.marginBottom = 5; | |
description.style.paddingBottom = 2; | |
description.style.paddingLeft = 2; | |
description.style.paddingRight = 2; | |
description.style.paddingTop = 2; | |
description.style.backgroundColor = new Color(0.15f, 0.15f, 0.15f); | |
description.style.whiteSpace = WhiteSpace.Normal; | |
description.text = "Unity saves some screens options in the Windows Registry, so when you build, if the screens parameters are different, " + | |
"you will not be able to see it.\nTo reset the options, delete the registries at this place."; | |
rootVisualElement.Add(description); | |
Button bttRegedit1 = new Button(); | |
bttRegedit1.text = "Open Regedit at Screen Size Location"; | |
bttRegedit1.clicked += () => | |
{ | |
ExecuteCommand("reg", "add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit\" /f /v \"LastKey\" /d HKCU\\Software"); | |
ExecuteCommand("regedit"); | |
}; | |
rootVisualElement.Add(bttRegedit1); | |
Button bttRegedit2 = new Button(); | |
bttRegedit2.text = "Open Regedit at PlayerPref Location"; | |
bttRegedit2.clicked += () => | |
{ | |
ExecuteCommand("reg", "add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit\" /f /v \"LastKey\" /d HKCU\\Software\\Unity\\UnityEditor"); | |
ExecuteCommand("regedit"); | |
}; | |
rootVisualElement.Add(bttRegedit2); | |
} | |
public static void ExecuteCommand(string commandName, string args = "") | |
{ | |
var processInfo = new ProcessStartInfo("cmd.exe", $"/c {commandName} {args}"); | |
processInfo.CreateNoWindow = true; | |
processInfo.UseShellExecute = false; | |
processInfo.RedirectStandardError = true; | |
processInfo.RedirectStandardOutput = true; | |
var process = Process.Start(processInfo); | |
process.WaitForExit(); | |
process.Close(); | |
//string error = process.StandardError.ReadToEnd(); | |
//if (string.IsNullOrWhiteSpace(error)) { UnityEngine.Debug.LogError(error); } | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment