Skip to content

Instantly share code, notes, and snippets.

@FreyaHolmer
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 {
CGPROGRAM
@FreyaHolmer
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;
[RequireComponent(typeof(Rigidbody))]
public class RigidbodyMassCalculator : MonoBehaviour {
public float density = 1f;
public bool recalculateOnAwake = true;
Rigidbody rb;
@FreyaHolmer
FreyaHolmer / int2.cs
Last active August 15, 2024 08:42
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)
using UnityEngine;
using System.Collections.Generic;
public static class GameObjectExtensions {
public static T[] GetComponentsInChildrenOfAsset<T>( this GameObject go ) where T : Component {
List<Transform> tfs = new List<Transform>();
CollectChildren( tfs, go.transform );
List<T> all = new List<T>();
for (int i = 0; i < tfs.Count; i++)
@FreyaHolmer
FreyaHolmer / TransformExtensions.cs
Created August 8, 2015 07:17
Adds WorldToLocal and LocalToWorld to transform components in Unity
using UnityEngine;
public enum TransformType { Point, Direction, Vector };
public static class TransformExtensions {
public static Vector3 WorldToLocal( this Transform tf, Vector3 v3, TransformType type = TransformType.Point ) {
if( type == TransformType.Point )
return tf.InverseTransformPoint( v3 );
else if( type == TransformType.Direction )
@FreyaHolmer
FreyaHolmer / ScriptableObjectSpawner.cs
Last active January 8, 2020 06:51
ScriptableObject asset spawner for Unity
// Adds a menu item for easy creation of your ScriptableObject types
// Usage: Right click in project view -> Create -> ScriptableObject... -> Select your type
// It will land in the root of your assets folder with the same name as your class
// Freya Holmér - [email protected]
using UnityEngine;
using UnityEditor;
using System.Reflection;
using System.Linq;
using System.IO;