Skip to content

Instantly share code, notes, and snippets.

using System.Collections.Generic;
public static class DictionaryExtensions
{
public static bool AddToList<KEYTYPE, VALUETYPE>(this Dictionary<KEYTYPE, List<VALUETYPE>> dictionary, KEYTYPE key, VALUETYPE value)
{
bool isNew = false;
List<VALUETYPE> list;
if (!dictionary.TryGetValue(key, out list))
{
@becksebenius
becksebenius / gist:9593857
Created March 17, 2014 04:09
A small utility which adds a Unity event for preprocessing scene saves.
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
public class AssetSaveProcess : AssetModificationProcessor
{
public static event Action OnSaveCurrentScene;
public static string[] OnWillSaveAssets (string[] paths)
@becksebenius
becksebenius / gist:8775846
Created February 2, 2014 22:20
Radial timer shader for Unity3D. Assumes you're drawing it on a square mesh with uvs (0,0) to (1,1)
Shader "RadialTimer" {
Properties {
_Angle ("Angle", Range(0,180)) = 180
_Color ("Color", Color) = (1,1,1,1)
_InnerRadius ("Inner Radius", Range(0,1)) = 0
}
SubShader {
Tags
{
"RenderType"="Transparent"
@becksebenius
becksebenius / gist:8480885
Created January 17, 2014 20:32
Runtime vertex color painter
using UnityEngine;
using System.Collections;
public class VPainter : MonoBehaviour
{
public MeshCollider[] paintTargets = new MeshCollider[0];
public Color targetColor;
public float paintRadius = 1f;
public float paintSpeed = 1f;
@becksebenius
becksebenius / MeshExporter.cs
Last active December 25, 2015 09:59
Exports a mesh instance from the currently selected Mesh Filter. Should go in the Editor folder. http://blog.becksebenius.com/ for more.
using UnityEngine;
using UnityEditor;
public class MeshExporter
{
const string menuItemPath = "Assets/Export Mesh Instance";
[MenuItem(menuItemPath)]
public static void SaveMeshAsAsset ()
{
@becksebenius
becksebenius / gist:6012328
Created July 16, 2013 20:25
A trigger class for unity for easier trigger detection
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
using System;
public class Trigger : MonoBehaviour
{
public Action<Collider> onTriggerEnter;
public Action<Collider> onTriggerExit;