Skip to content

Instantly share code, notes, and snippets.

View SiarheiPilat's full-sized avatar
🍌
Working from home

spilat12 SiarheiPilat

🍌
Working from home
View GitHub Profile
@SiarheiPilat
SiarheiPilat / InspectorLockShortcut.cs
Last active March 10, 2022 12:25
Lets user lock the Inspector window using keyboard shortcut. Note: Does not work for multiple inspector windows!
// ----------------------------------------------------------------------------
// Author: Siarhei Pilat
// Site: https://www.suasor-ab.com/
// This gist: https://gist.github.com/SiarheiPilat/b1469fba1b4f5757b10c083e88dbedb2
// Updated: 24 Feb 2021
// ----------------------------------------------------------------------------
using UnityEditor;
/// <summary>
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
/// <summary>
///
/// Copies the pivot coordinates of a first slice of the spritesheet and applies them to the pivots of other slices in the same spritesheet.
/// This script only works for spritesheets that were sliced using the grid option.
/// How to: select your spritesheet in the project files and go to the menu item to run the command.
///
using UnityEngine;
using UnityEditor;
/// <summary>
/// Copies pivot from one sprite to another.
/// Adapted from: https://forum.unity.com/threads/copy-spritesheet-slices-and-pivots-solved.301340/
/// </summary>
[CanEditMultipleObjects]
public class SpritePivotCopier : EditorWindow
using UnityEngine;
/// <summary>
/// The following script converts camera viewport corners' coordinates from viewport to world space.
/// </summary>
public class ScreenCornersToWorld : MonoBehaviour
{
public Camera Camera;
public Vector3 BottomLeftCorner, TopLeftCorner, TopRightCorner, BottomRightCorner;
@SiarheiPilat
SiarheiPilat / RemoveEventFromAnimator.cs
Last active November 23, 2019 20:19
Unity animation events or AnimationUtility API does not contain methods for deleting animation clip events at runtime. The following code makes it possible.
/// <summary>
/// Unity animation events or AnimationUtility API does not contain methods for deleting animation clip events at runtime.The following code makes it possible.
/// Taken from (with a minor bug fix): https://forum.unity.com/threads/remove-animation-event.78957/
/// </summary>
public static void RemoveEventFromAnimator(string functionName, Animator animator)
{
AnimatorClipInfo animationClipInfo = animator.GetCurrentAnimatorClipInfo(0)[0];
AnimationClip animationClip = animationClipInfo.clip;
@SiarheiPilat
SiarheiPilat / OpenEditorWindowsTracker.cs
Last active February 27, 2024 19:46
Get all currently open editor windows in Unity.
using UnityEngine;
using UnityEditor;
public class InternalEditorWindowsTracker : MonoBehaviour
{
/// <summary>
/// Get all currently open editor windows including default Unity windows, custom editors and windows that are tabbed.
/// Found here: https://answers.unity.com/questions/1237463/how-do-i-get-a-reference-to-the-default-editor-win.html?_ga=2.133529742.1822843399.1574452927-44739247.1572947128
/// </summary>
public static EditorWindow[] GetAllOpenEditorWindows()
using UnityEngine;
using UnityEditor;
using System.Reflection;
public class InternalEditorWindowsChecker : MonoBehaviour
{
/// <summary>
/// Most built-in editor windows in Unity are internal classes, so we can't access them directly.
/// However, we can work around that using Reflection.
/// The following code returns all editor window types, including internal classes (default Unity editor windows) and custom editor windows that are found in loaded assemblies.
using UnityEngine;
using UnityEditor;
using System.Reflection;
public class ActiveEditorWindowValidator : MonoBehaviour
{
/// <summary>
/// Checks whether an active window is a window that you require, for example: ValidateEditorWindow("UnityEditor.AnimationWindow");
/// </summary>
bool ValidateEditorWindow(string EditorWindowType)
@SiarheiPilat
SiarheiPilat / ScriptableObjectUtility.cs
Created November 23, 2019 22:20
Create a ScriptableObject from script.
using UnityEngine;
using UnityEditor;
using System.IO;
public static class ScriptableObjectUtility
{
/// <summary>
/// Create, name and place unique new ScriptableObject asset files.
/// Taken from: https://wiki.unity3d.com/index.php/CreateScriptableObjectAsset
/// </summary>
@SiarheiPilat
SiarheiPilat / EditorSceneAutosave.cs
Created November 25, 2019 22:55
This tiny class will Autosave your project whenever you play your scene!
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
// Credit goes to Comp-3 Interactive, thanks for sharing the script!
// This tiny class will Autosave your project whenever you play your scene!
[InitializeOnLoad]
public class Autosave
{