JetBrains / JetBrains/resharper-unity
An action to restart the game in Unity
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 142
- PR merge metrics
- No merged PRs in 30d
Description
Something that can be mapped to a shortcut. Here is how I implemented in Unity using a short editor script..
public static class ReplayGameMenuItem
{
private static bool isDisabled;
[MenuItem("Tools/Re-play Game _F5")]
public static void MenuItem()
{
if (isDisabled)
return;
if (EditorApplication.isPlaying)
{
EditorApplication.isPlaying = false;
EditorApplication.playModeStateChanged += StateChanged;
} else
{
EditorApplication.isPlaying = true;
}
isDisabled = true;
}
private static void StateChanged(PlayModeStateChange change)
{
if (change == PlayModeStateChange.EnteredEditMode)
{
EditorApplication.isPlaying = true;
isDisabled = false;
EditorApplication.playModeStateChanged -= StateChanged;
}
}
}
Contributor guide
Assessment
This issue has not been assessed yet.