Skip to content

Instantly share code, notes, and snippets.

@yasirkula
yasirkula / CameraFollow.cs
Created September 21, 2019 16:40
A camera follow script with numerous parameters for Unity
using UnityEngine;
[ExecuteInEditMode]
public class CameraFollow : MonoBehaviour
{
[Tooltip( "Object to follow" )]
public Transform Target;
[Tooltip( "Target distance to the followed object" )]
public Vector3 DistanceToTarget = new Vector3( 0f, 3f, -5f );
@yasirkula
yasirkula / EditorCameraZoomWithScrollWheel.cs
Last active September 21, 2019 16:42
"Right mouse button+Scroll wheel" will continue to zoom in/zoom out the Scene View instead of changing the camera speed on Unity 2019+
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class EditorCameraZoomWithScrollWheel
{
private const float CAMERA_SPEED = -0.25f;
private static bool rmbDown = false;
@yasirkula
yasirkula / TMP_IntegerText.cs
Last active March 11, 2025 14:51
Show numbers (int, float etc.) on TextMesh Pro texts without any GC allocations
//#define TMP_ROUND_DECIMALS // When defined, float and double values are rounded using Math.round
using TMPro;
public static class TMP_IntegerText
{
private static readonly char[] arr = new char[64]; // prefix + number + postfix can't exceed this capacity!
private static int charIndex = 0;
public static void SetText( this TMP_Text text, sbyte number )
@yasirkula
yasirkula / OpenShaderInNotepad.cs
Created August 3, 2019 13:14
An editor script for Unity 3D to open shaders in Notepad++ or the default text editor
using System.Diagnostics;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
public class OpenShaderInNotepad
{
private const string NPP1 = @"C:\Program Files\Notepad++\notepad++.exe";
private const string NPP2 = @"C:\Program Files (x86)\Notepad++\notepad++.exe";
@yasirkula
yasirkula / ScreenshotCapture.cs
Last active March 27, 2020 07:16
Quickly capture a screenshot in Unity
using System;
using System.IO;
using UnityEngine;
public static class ScreenshotCapture
{
// Saves the screenshot to desktop
public static void Capture()
{
string saveDirectory = Environment.GetFolderPath( Environment.SpecialFolder.DesktopDirectory );
@yasirkula
yasirkula / PluginJARExtractor.cs
Last active March 2, 2021 14:42
Automatically extract classes.jar file from Android Studio's .aar archive in Unity (for native Android plugin developers)
// Uses ZipStorer (c) 2016 Jaime Olivares [v3.4.0; August 4, 2017] (MIT-License: https://github.com/jaime-olivares/zipstorer/blob/master/LICENSE.md)
using System.Collections.Generic;
using System.Text;
using System;
using System.IO;
using System.IO.Compression;
using UnityEditor;
using UnityEngine;
@yasirkula
yasirkula / content.js
Last active November 28, 2022 18:29
Restore fullscreen button on embedded YouTube videos (Chrome Extension)
var checkDocument = function( doc )
{
var frames = doc.getElementsByTagName( "iframe" );
for( var i = 0, l = frames.length; i < l; i++ )
checkIframe( frames[i] );
};
var checkIframe = function(iframe)
{
if( iframe.src.indexOf( "https://www.youtube" ) == 0 )
@yasirkula
yasirkula / SimpleArchive.cs
Created May 22, 2019 12:24
Tar-like archive in pure C# (.NET 2.0 compatible)
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace SimplePatchToolCore
{
public class SimpleArchive
{
// Archive Structure
@yasirkula
yasirkula / HorizontalCamera.cs
Last active October 24, 2024 04:13
A script to fix the horizontal FOV/orthographic size of a camera to a specified value in Unity
using UnityEngine;
[ExecuteInEditMode]
[RequireComponent( typeof( Camera ) )]
public class HorizontalCamera : MonoBehaviour
{
private Camera m_camera;
private float lastAspect;
#pragma warning disable 0649
@yasirkula
yasirkula / GradientGraphic.cs
Last active March 2, 2025 21:47
Create 4-color gradient UI graphics 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
using Sprites = UnityEngine.Sprites;
#if UNITY_EDITOR