Skip to content

Instantly share code, notes, and snippets.

@twobob
twobob / InputEvents.cs
Created April 15, 2017 03:18 — forked from mstevenson/InputEvents.cs
Bind key presses to methods in Unity at runtime
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public delegate void InputKeyDelegate (KeyCode key);
public delegate void InputAxisDelegate (string name,float value);
public class InputEvents : MonoBehaviour
{
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class PolyPri : MonoBehaviour
{
void Start ()
{
MeshFilter[] myMeshs = FindObjectsOfType (typeof(MeshFilter)) as MeshFilter[];
@twobob
twobob / Reticle.cs
Created April 15, 2017 03:06
Demonstration of a screen-centered reticle in Unity
using UnityEngine;
using System.Collections;
public class Reticle : MonoBehaviour
{
public Texture2D reticle;
void Awake ()
{
// Set up reticle
@twobob
twobob / CreateQuadMesh.cs
Created April 15, 2017 03:05 — forked from mstevenson/CreateQuadMesh.cs
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);
@twobob
twobob / MonoBehaviourSingleton.cs
Created April 15, 2017 03:05 — forked from mstevenson/MonoBehaviourSingleton.cs
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) {
//https://gist.github.com/col000r/6658520
//but all the hard work done by mstevenson: https://gist.github.com/mstevenson/4050130
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ShuffleBag<T> : ICollection<T>, IList<T>
{
private List<T> data = new List<T> ();
@twobob
twobob / ShuffleBag.cs
Created April 15, 2017 03:03 — forked from mstevenson/ShuffleBag.cs
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;
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>
@twobob
twobob / StateMachine.cs
Created April 15, 2017 03:01 — forked from mstevenson/StateMachine.cs
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
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class CreateMergedMesh : ScriptableWizard
{
[MenuItem ("Prototype/Create Merged Mesh")]
static void CreateDataMesh ()
{