Skip to content

Instantly share code, notes, and snippets.

@8chan-co
Last active August 20, 2024 19:52
Show Gist options
  • Save 8chan-co/d19a25d01b16c80024f707fc60f9a26f to your computer and use it in GitHub Desktop.
Save 8chan-co/d19a25d01b16c80024f707fc60f9a26f to your computer and use it in GitHub Desktop.
// from: https://gist.github.com/noisecrime/3cb57c2618c7ade9d4398fe7f3835e34
using UnityEditor;
using UnityEngine;
/// <summary>
/// NoiseCrimeStudio OneShots are single scripts that provide specific functionality.
/// </summary>
namespace NoiseCrimeStudios.OneShot.Editor
{
/// <summary>
/// Exposes the native Unity 'ScreenShotting' methods to Unity Menu & Shortcut keys.
/// </summary>
/// <remarks>
/// Once imported you can find the menu in either Window/Analysis/Screenshot or Window/Internal/Screenshot.
/// <see href="https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/GUI/ScreenShotting.cs">
/// UnityCsReference\Editor\Mono\GUI\ScreenShotting.cs
/// </see>
/// Hotkey: % (ctrl on Windows, cmd on macOS), # (shift), & (alt).
/// </remarks>
public static class InternalScreenShotting
{
private readonly static System.Type s_screenShotsType = Unsupported.GetTypeFromFullName("UnityEditor.ScreenShots");
private const string MenuItemName =
#if UNITY_2018_2_OR_NEWER
"Window/Analysis/Screenshot/";
#else
"Window/Internal/Screenshot/";
#endif
/// <summary>Sets the entire Unity Window to 762x600.</summary>
[MenuItem(MenuItemName + "SetMainWindowSize (762x600 px)", false, 115)]
public static void SetMainWindowSizeSmall() => s_screenShotsType.GetMethod("SetMainWindowSizeSmall")?.Invoke(null, null);
/// <summary>Sets the entire Unity Window to 1024x768.</summary>
[MenuItem(MenuItemName + "SetMainWindowSize (1024x768 px)", false, 115)]
public static void SetMainWindowSize() => s_screenShotsType.GetMethod("SetMainWindowSize")?.Invoke(null, null);
/// <summary>Screenshots the Game View Window.</summary>
[MenuItem(MenuItemName + "Snap Game View Content %&g", false, 115)]
public static void ScreenGameViewContent()
{
Debug.Log("Snap Game View Content");
s_screenShotsType.GetMethod("ScreenGameViewContent")?.Invoke(null, null);
}
/// <summary>Screenshots the active Window.</summary>
[MenuItem(MenuItemName + "Snap Active Window %&h", false, 115)]
public static void Screenshot()
{
Debug.Log("Snap Active Window");
s_screenShotsType.GetMethod("Screenshot")?.Invoke(null, null);
}
/// <summary>Screenshots the active Window and the rest of the screen to the right. For example SceneView & Inspector.</summary>
[MenuItem(MenuItemName + "Snap Active Window Extended Right %&j", false, 115)]
public static void ScreenshotExtendedRight()
{
Debug.Log("Snap Active Window Extended Right");
s_screenShotsType.GetMethod("ScreenshotExtendedRight")?.Invoke(null, null);
}
/// <summary>Screenshots the active window toolbar. Bit unreliable.</summary>
[MenuItem(MenuItemName + "Snap Active Toolbar %&k", false, 115)]
public static void ScreenshotToolbar()
{
Debug.Log("Screenshot Active Toolbar");
s_screenShotsType.GetMethod("ScreenshotToolbar")?.Invoke(null, null);
}
/// <summary>Screenshots the Component you rollover next. Bit unreliable.</summary>
[MenuItem(MenuItemName + "Snap Component on Rollover %&l", false, 115)]
public static void ScreenShotComponent()
{
Debug.Log("Snap Component - Waiting for rollover on target component");
s_screenShotsType.GetMethod("ScreenShotComponent", System.Type.EmptyTypes)?.Invoke(null, null);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment