Created
February 18, 2021 18:17
-
-
Save benbenmushi/0dd60839384908ce2d9b3d188df2c9ce to your computer and use it in GitHub Desktop.
Put this script in a Editor/ folder somewhere...
This file contains 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.Collections; | |
using UnityEngine; | |
using UnityEditor; | |
using System.Reflection; | |
using System; | |
using System.IO; | |
using System.Diagnostics; | |
[InitializeOnLoad] | |
public static class ShortcutFixForUnity2019 | |
{ | |
static bool FirstCallThisSession | |
{ | |
get | |
{ | |
// returns true once then false other times... | |
// reset each time you relaunch unity | |
string tempFolder = Application.dataPath.Replace("/Assets", "/Temp"); | |
string tempFile = tempFolder + "/fixShortcut"; | |
bool customTempFileExists = File.Exists(tempFile); | |
if (!customTempFileExists) | |
File.Create(tempFile); | |
return !customTempFileExists; | |
} | |
} | |
static ShortcutFixForUnity2019() | |
{ | |
if (FirstCallThisSession) | |
{ | |
// If this is the first call to InitializeOnLoad (unity was just openned) | |
// Then we need to wait a bit before calling the FixShortcut function | |
EditorApplication.update += Update; | |
routine = FixShortcutAfterDelay(); | |
} | |
else | |
FixShortcut(); | |
} | |
static void FixShortcut() | |
{ | |
Type ShortcutManagerWindowType = null; | |
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) | |
{ | |
// Find UnityEditor Assembly | |
if (asm.FullName.StartsWith("UnityEditor,")) | |
ShortcutManagerWindowType = asm.GetType("UnityEditor.ShortcutManagement.ShortcutManagerWindow"); | |
} | |
if (ShortcutManagerWindowType == null) | |
{ | |
UnityEngine.Debug.LogWarning("Cant fix shortcut... type 'UnityEditor.ShortcutManagement.ShortcutManagerWindow' not found"); | |
return; | |
} | |
var GetWindowDontShowMethod = typeof(EditorWindow).GetMethod("GetWindowDontShow", BindingFlags.Static | BindingFlags.NonPublic); | |
GetWindowDontShowMethod.MakeGenericMethod(ShortcutManagerWindowType).Invoke(null, null); | |
} | |
// Coroutine stuff ========================================== | |
static IEnumerator routine; | |
static void Update() | |
{ | |
if (!routine.MoveNext()) | |
{ | |
routine = null; | |
EditorApplication.update -= Update; | |
} | |
} | |
static IEnumerator FixShortcutAfterDelay() | |
{ | |
Stopwatch stopwatch = new Stopwatch(); | |
stopwatch.Start(); | |
int secondsToWait = 2; | |
UnityEngine.Debug.Log("Wait " + secondsToWait + " seconds before fixing shortcuts"); | |
while (stopwatch.ElapsedMilliseconds < secondsToWait * 1000) | |
yield return null; | |
UnityEngine.Debug.Log("Fix shortcut"); | |
FixShortcut(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment