Skip to content

Instantly share code, notes, and snippets.

@yasirkula
yasirkula / CommentComponent.cs
Created November 4, 2024 19:15
Adding comments to Inspector via a component in Unity
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
[AddComponentMenu("Comment")]
public class CommentComponent : MonoBehaviour
{
#if UNITY_EDITOR
[SerializeField]
@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
@yasirkula
yasirkula / AndroidWirelessDebuggingAutoConnect.cs
Last active June 24, 2024 09:03
Connect to an Android device with 'Wireless debugging' by scanning a QR code in .NET
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using QRCoder;
/// <summary>
@yasirkula
yasirkula / UnityQRCodeGenerator.cs
Created June 15, 2024 23:32
Generate QR codes inside Unity
/// = Sources =
/// https://github.com/codebude/QRCoder
/// https://github.com/codebude/QRCoder.Unity
///
/// = License =
/// The MIT License (MIT)
///
/// Copyright(c) 2013 - 2018 Raffael Herrmann
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of
@yasirkula
yasirkula / SnapRectTransformAnchorsToCorners.cs
Created May 28, 2024 18:20
Snap a RectTransform's anchors to its corner points in Unity
using UnityEditor;
using UnityEngine;
public class SnapRectTransformAnchorsToCorners : MonoBehaviour
{
[MenuItem("CONTEXT/RectTransform/Snap Anchors To Corners", priority = 50)]
private static void Execute(MenuCommand command)
{
RectTransform rectTransform = command.context as RectTransform;
RectTransform parent = rectTransform.parent as RectTransform;
@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 November 4, 2024 14:02
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;
@yasirkula
yasirkula / PaddingIgnoringImage.cs
Last active October 17, 2024 03:00
Modified version of Image component that ignores the sprite's padding in Unity
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Sprites;
using UnityEngine.UI;
#if UNITY_2017_4 || UNITY_2018_2_OR_NEWER
using UnityEngine.U2D;
#endif
#if UNITY_EDITOR
using UnityEditor;
@yasirkula
yasirkula / CustomMaxSizeSetter.cs
Created March 13, 2022 08:27
Set non-power-of-2 Max Size values for textures/sprites in Unity
using UnityEditor;
using UnityEngine;
public class CustomMaxSizeSetter : EditorWindow
{
private const int MINIMUM_MAX_SIZE = 32;
private const int MAXIMUM_MAX_SIZE = 2048;
private int initialMaxSize = -1;
private int currentMaxSize = -1;
@yasirkula
yasirkula / WavyImage.cs
Last active November 8, 2024 12:44
Create UI image with wave animation in Unity
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Sprites;
using UnityEngine.UI;
#if UNITY_2017_4 || UNITY_2018_2_OR_NEWER
using UnityEngine.U2D;
#endif
#if UNITY_EDITOR
using UnityEditor;