Skip to content

Instantly share code, notes, and snippets.

View mstevenson's full-sized avatar

Michael Stevenson mstevenson

View GitHub Profile
@mstevenson
mstevenson / MonoDevelop 2.4 Scheme.xml
Created December 24, 2011 04:10
MonoDevelop 2.4 Default Highlighting Scheme
<EditorStyle name="MonoDevelop 2.4" _description="Old default MonoDevelop theme">
<Style name="text" color="#000000" bgColor="#FFFFFF" />
<Style name="text.background.readonly" color="#FAFAFA" />
<Style name="linenumber" color="#888A85" bgColor="#FDFDFF" />
<Style name="linenumber.highlight" color="#555753" />
<Style name="iconbar" color="#FDFDFF" />
<Style name="iconbar.separator" color="#BABDB6" />
<Style name="fold" color="#BABDB6" bgColor="#FDFDFF" />
<Style name="fold.highlight" color="#555753" />
<Style name="fold.togglemarker" color="#000000" />
@mstevenson
mstevenson / ShuffleBag.cs
Last active May 25, 2020 12:16
Shuffle bag algorithm implemented in C#
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ShuffleBag<T> : ICollection<T>, IList<T>
{
private List<T> data = new List<T> ();
private int cursor = 0;
private T last;
@mstevenson
mstevenson / SepScript.mel
Created November 25, 2012 22:40
Maya MEL script that breaks up a mesh based on materials. Created by Andrew Coggeshall at Basenji Games.
// Poly Separate
// Copyright (C) 2012 Basenji Games
// Licensed under the MIT license
string $selection[] = `ls -sl`;
sepMat($selection[0]);
global proc sepMat(string $object){
string $shadingGroups[] = getSGsFromShape($object);
string $ParentName = ($object + "_lightMap_Group");
@mstevenson
mstevenson / MonoBehaviourSingleton.cs
Created December 18, 2012 04:51
Generic Singleton classes for Unity. Use MonoBehaviourSingletonPersistent for any singleton that must survive a level load.
using UnityEngine;
using System.Collections;
public class MonoBehaviourSingleton<T> : MonoBehaviour
where T : Component
{
private static T _instance;
public static T Instance {
get {
if (_instance == null) {
@mstevenson
mstevenson / CreateQuadMesh.cs
Created December 27, 2012 00:36
Create a quad mesh asset in Unity. Place this script in the Editor folder.
using System;
using UnityEngine;
using UnityEditor;
public class CreateQuadMesh : Editor {
[MenuItem("Assets/Create/Quad Mesh", false, 10000)]
public static void Create ()
{
Mesh mesh = BuildQuad (1, 1);
@mstevenson
mstevenson / FileUtility.cs
Created December 27, 2012 08:52
A small file utility class for Unity. Transform an absolute path into an Assets folder relative path, and get a list of all Resources directories in the project.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class FileUtility {
/// <summary>
/// Determine whether a given path is a directory.
/// </summary>
@mstevenson
mstevenson / gist:4471373
Created January 7, 2013 00:40
Fisher-Yates shuffle
for (int i = branches.Length - 1; i > 0; --i) {
int next = Random.Range (0, i + 1);
Transform temp = shuffled [i];
shuffled [i] = shuffled [next];
shuffled [next] = temp;
}
@mstevenson
mstevenson / CameraPlane.cs
Created January 17, 2013 00:47
A simple solution for grabbing and dragging physics objects in Unity. Attach a DragRigidbody component to an object that has a both collider and a rigidbody. Add the object to a layer named "Interactive".
using UnityEngine;
using System.Collections;
/// <summary>
/// Utility class for working with planes relative to a camera.
/// </summary>
public static class CameraPlane
{
/// <summary>
/// Returns world space position at a given viewport coordinate for a given depth.
@mstevenson
mstevenson / StateMachine.cs
Last active July 10, 2017 14:47
Untested off-the-cuff example of a possible method-based state machine design for Unity.
// Defines the required parameters and return value type for a StateMachine state.
// Returns a bool representing whether or not the state has finished running.
public delegate bool StateDelegate ();
// To use, create an instance of StateMachine inside of a MonoBehaviour, load it up with
// references to state methods with ChangeState(), then call its Execute() method during the
// MonoBehaviour's Update cycle. An example MonoBehaviour is included at the bottom of this file.
public class StateMachine
{
// Keep track of the currently running state
@mstevenson
mstevenson / CreateAssetFromScript.cs
Created February 6, 2013 22:39
Creates an on-disk instance of a Unity ScriptableObject. To install, copy CreateAssetFromScript.cs into an Editor folder in your Unity project. To use, first select a script that inherits from ScriptableObject in the Project window, then select the menu Assets > Create Asset From ScriptableObject.
using UnityEngine;
using UnityEditor;
using System;
public class CreateAssetFromScript : Editor {
[MenuItem("Assets/Create Asset From Manager Script", false, 10000)]
public static void CreateManager ()
{
ScriptableObject asset = ScriptableObject.CreateInstance (Selection.activeObject.name);