Skip to content

Instantly share code, notes, and snippets.

@yasirkula
yasirkula / FontAssetSaveDisabler.cs
Created August 21, 2024 18:50
Prevent dynamic TMP_FontAssets from constantly showing up in your source control
using System;
using TMPro;
using TMPro.EditorUtilities;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(TMP_FontAsset))]
public class FontAssetSaveDisabler : TMP_FontAssetEditor
{
private static bool FontAssetsLocked
@WhiteOlivierus
WhiteOlivierus / HierarchyMonitor.cs
Created July 10, 2024 08:16
A way for monitoring changes in the unity editor hierarchy
using UnityEditor;
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Linq;
using Object = UnityEngine.Object;
[InitializeOnLoad]
public static class HierarchyMonitor
{
@EricHu33
EricHu33 / gist:1020f1b36c0fcb646fb5d8931c31dd08
Last active July 3, 2024 21:34
Clean all missing scripts in Unity Gameobject, attached this script into the root of the gameobject. right click and call "RemoveMissingScript"
[ExecuteInEditMode]
public class YourComponent : MonoBehaviour
{
[ContextMenu("remove missing script")]
public void RemoveMissingScript()
{
var transforms = GetComponentsInChildren<Transform>(true);
foreach (var childTransform in transforms)
{
var components = childTransform.GetComponents<Component>();
@yasirkula
yasirkula / BenchmarkEnterPlayMode.cs
Last active October 7, 2024 12:27
Calculate the time it takes to enter/exit play mode in Unity editor
using UnityEditor;
using UnityEngine;
public class BenchmarkEnterPlayMode
{
[InitializeOnLoadMethod]
private static void Initialize()
{
void OnPlayModeStateChanged( PlayModeStateChange state )
{
@yasirkula
yasirkula / SceneViewUIObjectPickerContextWindow.cs
Last active June 1, 2025 14:46
Select the UI object under the cursor via right click in Unity's Scene window
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_2021_2_OR_NEWER
using PrefabStage = UnityEditor.SceneManagement.PrefabStage;
using PrefabStageUtility = UnityEditor.SceneManagement.PrefabStageUtility;
@SolarianZ
SolarianZ / CustomEditorToolbar.cs
Last active February 20, 2025 11:57
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, Toolbar, Custom, UI"} Add custom UI to the Unity Editor's main toolbar. This example adds a FloatField to the main toolbar to control the `Time.timeScale` . You can refer to this example to add other UI elements. It has been tested in Unity 2021.3.
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
[InitializeOnLoad]
public static class CustomEditorToolbar
{
#region TimeScale Slider
using UnityEngine;
using System.IO;
using System;
public static class RenderTextureExtensions
{
private static DefaultDictionary<RenderTexture, Texture2D> _cachedTextures = new DefaultDictionary<RenderTexture, Texture2D>();
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / FasterTests.cs
Created May 2, 2023 19:13
Speed up Unity TestRunner running tests
// This work is Public Domain (CC0) - "No Rights Reserved"
// License: https://creativecommons.org/publicdomain/zero/1.0/
using System.Reflection;
using UnityEditor;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;
namespace CodeSmile.Tests.Utilities
{
@adammyhre
adammyhre / InspectorLock.cs
Last active June 11, 2025 18:15
Lock Inspector Icon and Transform Constrain Proportion Icon in Unity
using System.Reflection;
using UnityEditor;
using UnityEngine;
/// <summary>
/// Toggles the Inspector lock state and the Constrain Proportions lock state.
/// </summary>
public static class LockInspector {
static readonly MethodInfo flipLocked;
static readonly PropertyInfo constrainProportions;
@Anthelmed
Anthelmed / UIToolkitAutoReferencesPostprocessor.cs
Last active May 12, 2023 19:20
Automatically generate for you a MonoBehavior script containing reference to all the VisualElements that have the "auto-reference" uss class, this is updating every time you add or remove an "auto-reference" uss class inside your UXML file. Code is under the MIT license: https://github.com/git/git-scm.com/blob/main/MIT-LICENSE.txt
#if UNITY_EDITOR
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine.UIElements;
namespace Postprocessors