Skip to content

Instantly share code, notes, and snippets.

@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+
View EditorCameraZoomWithScrollWheel.cs
#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 / UIToggler.cs
Last active January 11, 2020 09:14
Quickly toggle the visibility of UI layer (canvases) in Unity's Scene view
View UIToggler.cs
using UnityEditor;
using UnityEngine;
public class UIToggler
{
private const int UI_LAYER = 1 << 5;
[InitializeOnLoadMethod]
private static void Init()
{
@yasirkula
yasirkula / ScreenshotCapture.cs
Last active March 27, 2020 07:16
Quickly capture a screenshot in Unity
View ScreenshotCapture.cs
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 / SimpleArchive.cs
Created May 22, 2019 12:24
Tar-like archive in pure C# (.NET 2.0 compatible)
View SimpleArchive.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace SimplePatchToolCore
{
public class SimpleArchive
{
// Archive Structure
@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.
View TimeManager.cs
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 / DirectoryComparer.cs
Last active January 26, 2021 09:22
Compare the contents of two directories and apply any changes to the target directory to synchronize these two directories
View DirectoryComparer.cs
#define COMPARE_FILE_CONTENTS
#if COMPARE_FILE_CONTENTS
#define USE_THREADS
#endif
using System;
using System.Collections.Generic;
using System.IO;
#if USE_THREADS
using System.Threading;
@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)
View PluginJARExtractor.cs
// 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 / UnlitWithShadows.shader
Last active March 3, 2021 05:17
Unlit shader with shadows support for Unity's Built-in Render Pipeline
View UnlitWithShadows.shader
Shader "Unlit/Texture with Shadows"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white"
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Geometry" }
@yasirkula
yasirkula / ScriptedAnimations.cs
Last active March 3, 2021 05:19
GC-free animation system for simple animations like scaling/moving objects or fading a UI element in Unity
View ScriptedAnimations.cs
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace ScriptedAnim
{
// Hide from Add Component menu
[AddComponentMenu( "" )]
public class ScriptedAnimations : MonoBehaviour
{
@yasirkula
yasirkula / SerializedPropertyRawValueGetter.cs
Last active April 30, 2021 03:07
Get/set the raw System.Object value of a SerializedProperty in Unity 3D
View SerializedPropertyRawValueGetter.cs
using System;
using System.Collections;
using System.Reflection;
using UnityEditor;
// Credit: http://answers.unity.com/answers/425602/view.html (I've only slightly modified the code)
public static class SerializedPropertyRawValueGetter
{
public static object GetRawValue( this SerializedProperty property )
{