Skip to content

Instantly share code, notes, and snippets.

@Fonserbc
Fonserbc / Oklab.cs
Last active October 3, 2023 21:22
An implementation of the transformations to and from Oklab, along with color lerping using Oklab including unity's Gradient evaluation. For more information about Oklab by Björn Ottosson check https://bottosson.github.io/posts/oklab/
using UnityEngine;
/*
* Oklab Unity implementation by Ferran Bertomeu Castells @fonserbc
*
* Oklab by Björn Ottosson https://bottosson.github.io/posts/oklab/
* under Public Domain
*
* For the conversions, I understand unity's Color as a gamma-space color
*/
@Fonserbc
Fonserbc / SwipeInput.cs
Last active April 27, 2023 04:28
A simple swipe detector for touchscreens for Unity3D. Four cardinal directions.
using UnityEngine;
/*
* Swipe Input script for Unity by @fonserbc, free to use wherever
*
* Attack to a gameObject, check the static booleans to check if a swipe has been detected this frame
* Eg: if (SwipeInput.swipedRight) ...
*
*
*/
@Fonserbc
Fonserbc / PseudoRandomBoolean.cs
Last active May 21, 2021 13:26
A boolean, written for use in Unity3D, that evaluates to true pseudo-randomly. Given a *baseProbability* from 0 to 1, it follows a Pseudo-Random Distribution inspired by http://wiki.teamliquid.net/dota2/Pseudo_Random_Distribution Every time it evaluates false, it increases the probability to evaluate true.
using UnityEngine;
using System;
/**
* Source at https://gist.github.com/Fonserbc/d061905a48555e583edc
* Made by @fonserbc
* Inspired by Valve's PRNG in use in Dota 2
*/
public class PseudoRandomBoolean {
@Fonserbc
Fonserbc / EdgeCollider2DEditor.cs
Last active April 19, 2020 10:48
A small editor script for Unity3D to edit EdgeCollider2D points on editor
using UnityEditor;
using UnityEngine;
using System;
public class EdgeCollider2DEditor : EditorWindow {
[MenuItem("Window/EdgeCollider2D Snap")]
public static void ShowWindow() {
EditorWindow.GetWindow (typeof(EdgeCollider2DEditor));
}
@Fonserbc
Fonserbc / Easing.cs
Last active February 23, 2024 01:13
Compact and simple easing functions for Unity
using UnityEngine;
/*
* Most functions taken from Tween.js - Licensed under the MIT license
* at https://github.com/sole/tween.js
* Quadratic.Bezier by @fonserbc - Licensed under WTFPL license
*/
public delegate float EasingFunction(float k);
public class Easing