Skip to content

Instantly share code, notes, and snippets.

@kraj0t
kraj0t / CustomImageEditor.cs
Last active March 27, 2022 15:32
Extend Unity's Image editor with custom inspector GUI
using UnityEditor;
using UnityEditor.UI;
using UnityEngine;
using UnityEngine.UI;
[CustomEditor(typeof(Image))]
public class CustomImageEditor : ImageEditor
{
public override void OnInspectorGUI()
{
@kraj0t
kraj0t / CustomParticleSystemEditor.cs
Last active November 9, 2023 16:29
Extend ParticleSystem editor with custom inspector GUI
using System.Reflection;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(ParticleSystem))]
public class CustomParticleSystemEditor : Editor
{
private Editor _builtInEditor;
private void OnEnable()
@kraj0t
kraj0t / OrbitParentTool.cs
Last active February 26, 2022 20:29
OrbitParentTool - a Unity EditorTool to orbit selected objects around their parents (my first test with EditorTools)
using UnityEngine;
using UnityEditor;
using UnityEditor.EditorTools;
[EditorTool("Orbit Parent Tool", typeof(Transform))]
class OrbitParentTool : EditorTool
{
[SerializeField]
private Texture2D _toolIcon;
@kraj0t
kraj0t / .Display keyboard shortcuts.gif
Last active April 28, 2022 22:08
DisplayKeyboardShortcuts - a Unity editor tool that shows the keys and shortcuts that the user is pressing
.Display keyboard shortcuts.gif
@kraj0t
kraj0t / .AnimatedGUI preview.gif
Last active October 19, 2023 14:52
AnimatedGUI - a Unity editor convenience class for drawing temporary GUI with animated fade-in & fade-out
.AnimatedGUI preview.gif
@kraj0t
kraj0t / GUIBackgroundColorScope.cs
Last active February 14, 2022 23:38
GUIBackgroundColorScope - quickly set color of your GUI (buttons, panels...) same as EditorGUI.DisabledScope and others
using System;
using System.Collections.Generic;
using UnityEngine;
public struct GUIBackgroundColorScope : IDisposable
{
private static readonly Stack<Color> _colorStack = new Stack<Color>();
public GUIBackgroundColorScope(Color color)
{
@kraj0t
kraj0t / HasFrameBounds.cs
Last active February 14, 2022 02:26
Unity Editor: undocumented callbacks in Editor class to define bounds for focus
/// <summary>
/// Undocumented Unity callback. More info here:
/// https://forum.unity.com/threads/editor-how-do-i-set-the-bounds-of-an-empty-gameobject-for-focus-f-key.427093/
/// </summary>
/// <returns></returns>
public bool HasFrameBounds()
{
return true;
}
@kraj0t
kraj0t / DrawDottedLines.cs
Last active February 14, 2022 02:26
Editor GUI; draw dotted lines using Handles
// Somewhere in your OnSceneGUI() ...
// Draw dotted lines.
var handlesColorBkp = Handles.color;
Handles.color = new Color(0f, 0f, 0.5f);
for (int i = 0; i < points.Length - 1; i++)
{
Handles.DrawDottedLine(points[i], points[i + 1], DOTTED_LINE_SIZE);
}
@kraj0t
kraj0t / CopyGameScreenshotToClipboard.cs
Created December 12, 2019 01:33
Unity Tool - copy Game window to system clipboard
/*
* @brief Editor menu item and shortcut for capturing the game view into the system clipboard.
*
* @setup The System.Drawing and System.Windows.Forms Mono DLLs need to be referenced. See the documentation for
* CopyTextureToClipboard below.
*
* @usage Access from the menu item or use the shortcut. Both are defined below as attribute of GameViewToClipboard(),
* defaults to Shift+S
*
* @author Aurelio Provedo
@kraj0t
kraj0t / RebasePrefab.cs
Last active November 1, 2022 02:50
RebasePrefab - Unity editor tool to convert a prefab into a variant of a new empty prefab
/*
* @brief Editor menu item for turning a prefab into a variant of a new empty prefab.
*
* @usage Access from the MenuItem defined in the code. As right-click or from the menu bar.
*
* @author Aurelio Provedo
* Contact: [email protected]
*
*/