Skip to content

Instantly share code, notes, and snippets.

@Sov3rain
Sov3rain / UnityAsyncOperationAwaiter.cs
Created April 16, 2024 20:25 — forked from mattyellen/UnityAsyncOperationAwaiter.cs
Allows the use of async/await (instead of yield) with any Unity AsyncOperation
public static class ExtensionMethods
{
public static TaskAwaiter GetAwaiter(this AsyncOperation asyncOp)
{
var tcs = new TaskCompletionSource<object>();
asyncOp.completed += obj => { tcs.SetResult(null); };
return ((Task)tcs.Task).GetAwaiter();
}
}
@Sov3rain
Sov3rain / non_breaking_space.ahk
Last active February 13, 2024 12:33
Auto Hotkey script thats send non-breaking spaces characters when CTRL+ALT+SPACE (on AZERTY layout) is pressed.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
; CTRL+ALT+SPACE sends a non-breaking space character
^!Space::Send {U+00A0}
@Sov3rain
Sov3rain / EventManager.cs
Created January 1, 2024 19:56
Simple 0 dependency Event Bus for Unity C#
using System;
public static class EventManager<T>
{
private static event Action<T> Event;
public static void AddListener(Action<T> handler) => Event += handler;
public static void RemoveListener(Action<T> handler) => Event -= handler;
@Sov3rain
Sov3rain / space_cadet.ahk
Last active November 19, 2023 12:32
AutoHotKey script to mimic the Space Cadet Keyboard shift features.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Space Cadet Shift - If the shift key is tapped without being used to uppercase a key then it acts as a curly bracket key instead.
~LShift::
KeyWait, LShift
If (A_TimeSinceThisHotkey < 150 and A_PriorKey = "LShift") {
SendRaw, {
@Sov3rain
Sov3rain / Standard-DoubleSided.shader
Last active June 20, 2023 07:46 — forked from jminor/Standard-DoubleSided.shader
Unity Standard-DoubleSided.shader
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Standard (Double Sided)"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo", 2D) = "white" {}
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
@Sov3rain
Sov3rain / saveBlobAsFile.js
Created December 6, 2022 13:14
save a blob as a file
const blobUrl = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = blobUrl;
link.download = fileName;
document.body.appendChild(link);
// link.click() does not work on the latest Firefox and some modern browsers.
link.dispatchEvent(
new MouseEvent('click', {
@Sov3rain
Sov3rain / DeepClone.cs
Created June 1, 2022 13:57
How to make a deep copy in c# with binary formatter
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
static public class DeepCloning
{
static public T DeepClone<T>(this T source)
{
var formatter = new BinaryFormatter();
using var stream = new MemoryStream();
@Sov3rain
Sov3rain / IfNotNull.cs
Last active April 13, 2022 15:42
Monad in c#
using System;
void Main()
{
string foo = "Hello";
// a.then(f).then(g).then(j)
foo.Then(x => x.Trim().Ret())
.Then(x => x.Substring(0, 5).Ret())
.Then(x => x.Length.Ret())
@Sov3rain
Sov3rain / TouchOverUI.cs
Last active January 5, 2022 16:26
[Unity] Find if a touch is over a UI element
static class TouchHelper
{
// OG version: https://www.reddit.com/r/Unity3D/comments/6o9zsy/comment/dkgxa1i/?utm_source=share&utm_medium=web2x&context=3
public static bool IsOverUI()
{
PointerEventData pointerData = new PointerEventData(EventSystem.current);
pointerData.position = Input.mousePosition;
List<RaycastResult> results = new List<RaycastResult>();
@Sov3rain
Sov3rain / TwoFingersObjectRotation.cs
Created January 3, 2022 16:18
[Unity] Rotate any object with double finger touch
using static UnityEngine.TouchPhase;
using UnityEngine;
public class TwoFingersObjectRotation : MonoBehaviour
{
[SerializeField]
private Transform _target;
private Vector2 _startPosition;