Skip to content

Instantly share code, notes, and snippets.

View hariedo's full-sized avatar

Ed Halley hariedo

View GitHub Profile
# -*- python -*-
'''
SYNOPSIS
>>> import weighted
>>> choices = { 'heads': 2, 'tails': 1 }
>>> for i in xrange(100):
// 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)
// 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
{
// all the usual Singleton stuff (optional)
public VitalThing vital = null;
//
// 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
using System;
using System.Reflection;
using UnityEngine;
using UnityEditor;
// Put in a folder called 'Editor' anywhere inside project Assets folder.
// Combines ideas based on forum posts:
// https://discussions.unity.com/t/dsiable-selection-outlines-on-object/869598/2
// https://discussions.unity.com/t/editor-how-to-add-checkmarks-to-menuitems/114525/6
// 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.