Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / AndroidWirelessDebuggingAutoConnect.cs
Last active May 15, 2026 21:33
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 / 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 / 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 / TiledImageWithOffset.cs
Created February 8, 2026 13:54
Adding randomized offset to each row/column of tiled Image in Unity
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.Sprites;
using UnityEngine.U2D;
using UnityEngine.UI;
using Random = System.Random;