Skip to content

Instantly share code, notes, and snippets.

@yasirkula
yasirkula / ShaderStripper.cs
Last active March 4, 2024 09:40
Stripping commonly unused shader variants in Unity's built-in render pipeline
//#define SHADER_COMPILATION_LOGGING
//#define SKIP_SHADER_COMPILATION
using System.Collections.Generic;
using UnityEditor.Build;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.Rendering;
public class ShaderStripper : IPreprocessShaders
@yasirkula
yasirkula / TimeManager.cs
Created February 8, 2018 22:12
Easily handle pause requests from multiple sources and receive callbacks upon pause/unpause and time scale changes in Unity. See the comments section below for instructions.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public static class TimeManager
{
private static List<object> pauseHolders = new List<object>();
public static event System.Action<bool> OnPauseStateChanged = null;
public static event System.Action<float> OnTimeScaleChanged = null;
@yasirkula
yasirkula / HorizontalCamera.cs
Last active March 6, 2024 13:02
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 / 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 / ScriptedAnimations.cs
Last active March 8, 2024 02:28
GC-free animation system for simple animations like scaling/moving objects or fading a UI element in Unity
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace ScriptedAnim
{
// Hide from Add Component menu
[AddComponentMenu( "" )]
public class ScriptedAnimations : MonoBehaviour
{
@yasirkula
yasirkula / EditorCollapseAll.cs
Last active March 11, 2024 11:53
An editor script for Unity 3D to collapse all GameObject's in Hierarchy view or to collapse all folders in Project view. See the comments section below for instructions.
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEditorInternal;
using UnityEngine.SceneManagement;
public static class EditorCollapseAll
{
private const BindingFlags INSTANCE_FLAGS = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
@yasirkula
yasirkula / UnitypackageExtractor.cs
Last active March 12, 2024 00:44
Extract a .unitypackage to any directory (even outside the project folder) from within Unity
#define STOP_EXTRACTION_WHEN_WINDOW_CLOSED
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Text;
using System.Threading;
using UnityEditor;
@yasirkula
yasirkula / ConvertTexturesToPNG.cs
Last active March 15, 2024 02:51
Convert all TGA, TIFF, PSD and BMP (customizable) Textures to PNG to reduce the project size without any quality loss in Unity
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
using Debug = UnityEngine.Debug;
using Object = UnityEngine.Object;
@yasirkula
yasirkula / WavyImage.cs
Last active April 3, 2024 11:51
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;
@yasirkula
yasirkula / CircleGraphic.cs
Last active April 11, 2024 03:33
Create circles/ellipses in Unity UI system in one of three modes: FillInside, FillOutside and Edge.
using UnityEngine;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
// Custom Editor to order the variables in the Inspector similar to Image component
[CustomEditor( typeof( CircleGraphic ) ), CanEditMultipleObjects]
public class CircleGraphicEditor : Editor
{