Skip to content

Instantly share code, notes, and snippets.

FreyaHolmer / AssetCopyUtils.cs
Last active May 9, 2024 10:36
Adds context menu items to assets: Copy/Paste import settings & Copy GUID. Put this script in any Editor/ folder in your project and recompile!
// written by so use at your own risk c:
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
/// <summary>Utility functions to copy GUIDs, as well as Copy/Paste import settings</summary>
public static class AssetCopyUtils {
const int CTX_MENU_LOCATION = 70;
FreyaHolmer / SceneViewZAlign.cs
Last active November 27, 2023 11:32
Allows the scene view camera to use Z up/down (be sure to place this script in an Editor/ folder)
// Allows you to change the up vector in the scene view to the Z axis.
// Y-up mode uses Unity's default implementation.
// Original code from Akulist on the Unity forums, modified by Freya Holmér:
// • Fixed orbit+RMB zoom not working
// • Toggling will now align the camera immediately to the new up vector
// • When the camera is upside down in Z axis mode, left/right orbit will no longer be mirrored (pls fix this too Unity~)
// • Moved toggle buttons to under the gizmo
// • Fixed broken rotation state when focusing a different window in Unity and coming back to the scene view
FreyaHolmer / BlendTest.cs
Created August 11, 2020 13:56
Alpha blending comparisons
// alpha blending test
// more info:
// add this script to an object in the scene,
// then edit src and dst to see - will it blend?
using UnityEngine;
public class BlendTest : MonoBehaviour {
FreyaHolmer / FlyCamera.cs
Last active May 22, 2024 14:26
A camera controller for easily flying around a scene in Unity smoothly. WASD for lateral movement, Space & Ctrl for vertical movement, Shift to move faster. Add this script to an existing camera, or an empty game object, hit play, and you're ready to go~
using UnityEngine;
[RequireComponent( typeof(Camera) )]
public class FlyCamera : MonoBehaviour {
public float acceleration = 50; // how fast you accelerate
public float accSprintMultiplier = 4; // how much faster you go when "sprinting"
public float lookSensitivity = 1; // mouse look sensitivity
public float dampingCoefficient = 5; // how quickly you break to a halt after you stop your input
public bool focusOnEnable = true; // whether or not to focus and lock cursor immediately on enable
FreyaHolmer / MathWishlist.cs
Created January 15, 2020 12:07
Things I'd love to have in Unity's Mathf and Vector classes~
public class MathWishlist {
// Mathf
public const float TAU = 6.28318530717959f;
public static float Frac( float x ) => x - Mathf.Floor( x );
public static float Smooth01(float x) => x * x * (3 - 2 * x);
public static float InverseLerpUnclamped( float a, float b, float value) => (value - a) / (b - a);
public static float Remap(float iMin, float iMax, float oMin, float oMax, float value) {
float t = Mathf.InverseLerp(iMin, iMax, value);
return Mathf.Lerp( oMin, oMax, t );
FreyaHolmer / LengthTable.cs
Created August 21, 2019 02:18
Béziér curve utility class for converting a t value to percentage of distance along the spline
using UnityEngine;
public class LengthTable {
public float[] distances;
int SmpCount => distances.Length;
float TotalLength => distances[SmpCount - 1];
public LengthTable( OrientedCubicBezier3D bezier, int precision = 16 ) {
distances = new float[precision];
FreyaHolmer / IMGUIDebugger.cs
Created May 2, 2019 04:38
Unity script to open the IMGUI debugger. Useful for editor UI debugging! Make sure you put it in an Editor/ folder in your project
using UnityEditor;
using System;
public static class IMGUIDebugger {
static Type type = Type.GetType( "UnityEditor.GUIViewDebuggerWindow,UnityEditor" );
[MenuItem( "Window/IMGUI Debugger" )]
public static void Open() => EditorWindow.GetWindow( type ).Show();
FreyaHolmer / Circular Circles.shader
Created March 4, 2019 20:25
A shader for rendering circles arranged in a circle. Written in CG for use in the Unity engine
Shader "Custom/Circular Circles" {
Properties {
_CircleCount ("Circle Count", Float ) = 8
_CircleRadius ("Circle Radius", Range(0, 1)) = 0.18
_CircleSharpness ("Circle Sharpness", Range(0, 0.999)) = 0.95
_GroupRadius("Group Radius", Range(0, 1)) = 0.6
SubShader {
Pass {
FreyaHolmer / RigidbodyMassCalculator.cs
Created December 18, 2015 19:54
Used to approximate a proper mass value for all the colliders in a given Rigidbody
using UnityEngine;
using System.Linq;
public class RigidbodyMassCalculator : MonoBehaviour {
public float density = 1f;
public bool recalculateOnAwake = true;
Rigidbody rb;
FreyaHolmer / int2.cs
Last active November 2, 2023 15:59
int2 type for Unity
// int2 is similar to Vector2, but with integers instead of floats
// Useful for various grid related things.
// - Swizzle operators xx/xy/yx/yy
// - Extended arithmetic operators similar to shader data types
// A few examples:
// int2(8,4) / int2(2,4) -> int2(4,1)
// 16 / int2(2,4) -> int2(8,4)
// int2(2,3) * int2(4,5) -> int2(8,15)