Skip to content

Instantly share code, notes, and snippets.

@Fonserbc
Fonserbc / Oklab.cs
Last active Mar 8, 2021
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/
View Oklab.cs
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 Mar 24, 2021
A simple swipe detector for touchscreens for Unity3D. Four cardinal directions.
View SwipeInput.cs
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 Aug 29, 2015
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.
View PseudoRandomBoolean.cs
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 Apr 19, 2020
A small editor script for Unity3D to edit EdgeCollider2D points on editor
View EdgeCollider2DEditor.cs
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 Apr 6, 2021
Compact and simple easing functions for Unity
View Easing.cs
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