This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- python -*- | |
''' | |
SYNOPSIS | |
>>> import weighted | |
>>> choices = { 'heads': 2, 'tails': 1 } | |
>>> for i in xrange(100): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void DrawPolygon(Vector3 center, Vector3 axis, float radius, | |
int sides, Color color=default, float duration=0f, bool depthTest=true) | |
{ | |
//duration = Mathf.Max(0.001f, duration); | |
Vector3 start = Limb(axis); | |
Vector3 prior = start * radius; | |
if (sides < 3) sides = 3; | |
float step = 360f/sides; | |
for (float f = step; f <= 360f; f += step) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Vector3[] DistributePointsOnUnitSphere(int count) | |
{ | |
Assert.IsTrue(count > 0); | |
Vector3[] points = new Vector3[count]; | |
// The Fibonacci Sphere algorithm. | |
float phi = Mathf.PI * (Mathf.Sqrt(5f) - 1f); | |
float descent = 2f / (float)(count-1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Quaternion YawPitchRoll(float yaw, float pitch, float roll) | |
{ | |
Quaternion heading = Quaternion.AngleAxis(yaw, Vector3.up); | |
Quaternion attitude = Quaternion.AngleAxis(pitch, Vector3.right); | |
Quaternion bank = Quaternion.AngleAxis(roll, Vector3.forward); | |
return heading * attitude * bank; | |
// transform.rotation *= YawPitchRoll(yaw, pitch, roll); | |
///// transform.rotation *= Quaternion.Euler(pitch, yaw, roll); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Color HexRGB(uint hexcode) | |
{ | |
// e.g., 0xFF0033 | |
float b = (hexcode & 0xFF) / 255f; | |
float g = ((hexcode >> 8) & 0xFF) / 255f; | |
float r = ((hexcode >> 16) & 0xFF) / 255f; | |
return new Color(r, g, b); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given a float f, return next possible representation. | |
// This method will have issues around +/-maxfloat, +/-infinity, NaN. | |
// | |
public static float NextULP(float f, int ulp=1) | |
{ | |
int bits = System.BitConverter.SingleToInt32Bits(f); | |
return System.BitConverter.Int32BitsToSingle(bits + ulp); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Thing.cs | |
// Automatically indexed MonoBehaviour for searching by type. | |
// | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace Things | |
{ |
NewerOlder