Skip to content

Instantly share code, notes, and snippets.

@yasirkula
yasirkula / FileDownloader.cs
Last active February 26, 2024 05:52
C# Download Public File From Google Drive™ (works for large files as well)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Text;
/* EXAMPLE USAGE
FileDownloader fileDownloader = new FileDownloader();
@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 / 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 / DeviceOrientationManager.cs
Created February 8, 2018 22:14
Easily enable/disable auto screen orientation in Unity and receive callback upon orientation change. See the comments section below for instructions.
using UnityEngine;
public class DeviceOrientationManager : MonoBehaviour
{
private const float ORIENTATION_CHECK_INTERVAL = 0.5f;
private float nextOrientationCheckTime;
private static ScreenOrientation m_currentOrientation;
public static ScreenOrientation CurrentOrientation
@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
{
@yasirkula
yasirkula / GradientGraphic.cs
Last active April 4, 2024 18:21
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
@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 / 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 / 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;