Skip to content

Instantly share code, notes, and snippets.

View hariedo's full-sized avatar

Ed Halley hariedo

View GitHub Profile
// Unity C# extension methods to the Transform class.
// Transform already has TransformPosition/InverseTransformPosition.
// Add the correct Quaternion terms to apply or find a relative rotation.
public static Quaternion TransformRotation(this Transform transform,
Quaternion localRotation)
{
return transform.rotation * localRotation;
}
// Unity LayerMask is castable to a 32bit int bit field.
// Add some extension methods to make it easier and more readable to
// determine if a given layer or object is within the bits of a mask.
public static bool Contains(this LayerMask mask, int layer)
{
return (0 != (mask & (1 << layer)));
}
public static bool Contains(this LayerMask mask, GameObject gob)
// UnityWaitToStartBehaviour.cs
//
using UnityEngine;
// The magical Start() method can also be treated as a coroutine if it returns
// IEnumerator. This lets a component class behave linearly, or at least start
// up with linear logic such as waiting for the right conditions to begin the
// Update() loop.
public class WaitToStartBehaviour: MonoBehaviour
//
// If the effective scale of a BoxCollider ends up making the .size negative,
// such as when a prefab is scaled (-1,+1,+1), then Unity complains loudly:
//
// /!\ BoxColliders does not support negative scale or size.
//
// This works around the problem by looking at the signs of the lossy scale,
// and flipping the same signs in the box collider's size vector. Since
// the box collider is always aligned with the local matrix, this has no
// effect on the collider except to quiet the console warnings.
// SelectionOutlinePreference.cs
//
using System;
using System.Reflection;
using UnityEngine;
using UnityEditor;
// Adds menu items to toggle the Unity Editor tab's outlining of the selected objects.
// Helpful when trying to preview the look of particle systems or other alpha-edged objects.
//
// FuzzTable.cs
//
using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
// A simple random string picking engine.
//
// Load it up like a list with string choices that can be picked from.
// UnityColorUtilities.cs
//
using UnityEngine;
public static class ColorUtilities
{
public static Color HexRGB(uint hexcode)
{
// e.g., 0xFF0033
float b = (hexcode & 0xFF) / 255f;
// UnityElementInitialization.cs
//
using System;
using UnityEngine;
// In Unity, new struct or class elements in a serialized list do not
// get a chance to run static initializers or constructors. All members
// are given their default(T) values instead. This is an example of how
// to use the OnValidate() method to support initialization.
@hariedo
hariedo / templates.py
Last active May 7, 2026 23:06
Walk a CSV to generate a series of placeholder PNG files of various sizes.
#!/usr/bin/env python3
#
# take a CSV of template image sizes, and make template image placeholders
# using the ImageMagick command line for each entry in the table
#
import subprocess
import csv
import os
// Swizzle.cs
//
using System;
using UnityEngine;
namespace Screenplay
{
public static class Swizzles
{
public enum Order