Skip to content

Instantly share code, notes, and snippets.

@jaburns
jaburns / findrefs.sh
Last active September 8, 2016 04:23
Find scene and prefab references to scripts in Unity.
#!/usr/bin/env bash
#
# Run from the project root. Pass the full name of a script, or substring of the names of the scripts to check.
#
# Example
# $) ./findrefs.sh BackgroundCamera
# Finding matches for script Assets/Scripts/Camera/BackgroundCamera.cs.meta ...
# Assets/Prefabs/CaveBGCamera.prefab: m_Script: {fileID: 11500000, guid: 7e63acfee367c4314852b87218149bd3, type: 3}
# Assets/Prefabs/ForestBGCamera.prefab: m_Script: {fileID: 11500000, guid: 7e63acfee367c4314852b87218149bd3, type: 3}
#
@jaburns
jaburns / BumperZapper.cs
Last active November 16, 2015 22:11
Type-safe implementation of Unity's SendMessage
using UnityEngine;
public class BumperZapper : MonoBehaviour
{
Rigidbody2D _rb;
void Awake()
{
_rb = GetComponent<Rigidbody2D>();
}
using UnityEngine;
using UnityEditor;
static public class PolygonHolePunchMenuItem
{
[MenuItem("Tools/PolygonCollider2D Punch Hole")]
static public void PolygonHolePunchMenuItem_Click()
{
if (!Selection.activeGameObject) return;
var collider = Selection.activeGameObject.GetComponent<PolygonCollider2D>();
@jaburns
jaburns / struniq.sh
Last active November 16, 2015 22:34
Pass in a string, exits 0 if all characters are unique.
#!/usr/bin/env bash
echo "$1" | fold -w 1 | sort | tee /tmp/struniq | uniq | cmp -s - /tmp/struniq
@jaburns
jaburns / playground.html
Created August 25, 2015 18:01
Shim for messing around with effects
<!DOCTYPE html>
<html>
<body>
<canvas id="paper" width="1024" height="768"></canvas>
<script>
// ---------------------------------------------------------------------------
var canvas = document.getElementById("paper");
var ctx = canvas.getContext("2d");
var mouse = {}, keys = {};
canvas.addEventListener('mousemove', function(e) {
@jaburns
jaburns / CubicSplineWalker.cs
Created August 15, 2015 23:19
Estimates the length of a cubic Bezier spline and provides an interface to walk it at a constant speed.
using UnityEngine;
using System;
using System.Collections.Generic;
public class CubicSplineWalker
{
readonly Vector2 _anchor0;
readonly Vector2 _control0;
readonly Vector2 _control1;
readonly Vector2 _anchor1;
@jaburns
jaburns / StarlingAtlasSlicer.cs
Last active August 29, 2015 14:20
Starling sprite animation atlas slicer for Unity
using System;
using System.Collections.Generic;
using System.Xml;
using UnityEditor;
using UnityEngine;
public class StarlingAtlasSlicer
{
[MenuItem("CONTEXT/TextureImporter/Slice Sprite Using XML")]
static public void SliceUsingXML(MenuCommand command)
@jaburns
jaburns / gdrive-invert-icons
Created March 30, 2015 21:04
Force inverted tray icons for OSX Google Drive
#!/usr/bin/env bash
cd /Applications/Google\ Drive.app/Contents/Resources
for file in $(find . -depth 1 | grep 'inverse.*png'); do
echo "Fixing $file ..."
cp "$file" "$(printf "$file" | sed 's/-inverse//')"
done
echo 'Done!'
@jaburns
jaburns / vidup
Last active November 3, 2017 08:02
Script to screengrab video, convert to webm, upload to server, and get link.
#!/usr/bin/env bash
#
# Depends on ffmpeg with libvpx so you'll need to
# brew install ffmpeg --with-libvpx
# or
# brew reinstall ffmpeg --with-libvpx
# if you've already got ffmpeg, but it's not linked against libvpx.
#
vid_name='vidup_tmp'
remote='you@yourdomain.tld:/home/you/vidcaps'
@jaburns
jaburns / Makefile
Last active August 29, 2015 14:16
:|
default: all
all: public/index.html
public/index.html: index.html
cpp index.html | sed '/^#.*/d' > public/index.html