Skip to content

Instantly share code, notes, and snippets.

View michaelbartnett's full-sized avatar

Michael Bartnett michaelbartnett

View GitHub Profile
@michaelbartnett
michaelbartnett / ListPrefabChanges.cs
Created April 18, 2014 02:49
helper class for showing changes properties in a prefab instance, needs a StringListWindow helper that just prints a bunch of strings to an editor window
using System;
using System.Linq;
using UnityEngine;
using UnityEditor;
public class ListPrefabChanges : EditorWindow
{
[MenuItem("Tools/List Prefab Changes")]
private static void Command()
{
@michaelbartnett
michaelbartnett / HashableWeakRefOfT.cs
Last active August 29, 2015 14:00
A rough HashableWeakRef<T> implementation. Missing many details and cases.
using System;
class HashableWeakRef<T> : IEquatable<HashableWeakRef<T>> where T : class
{
private WeakReference weakRef;
public T Target { get { return (T) weakRef.Target; } }
public HashableWeakRef(T target)
{
@michaelbartnett
michaelbartnett / Program.cs
Last active August 29, 2015 14:00
HashableWeakRef<T> examle
using System;
using System.Collections.Generic;
namespace TestHashableWeakRef
{
class MainClass
{
public static void Main (string[] args)
{
@michaelbartnett
michaelbartnett / TestDependentCoroStop.cs
Last active August 29, 2015 14:03
Demonstrates that using MonoBehaviour.StopCoroutine(IEnumerator myCoro) will block forever if other coroutines have yielded myCoro's UnityEngine.Coroutine handle.
using System;
using UnityEngine;
using IEnumerator=System.Collections.IEnumerator;
using System.Collections.Generic;
public class TestDependentCoroStop : MonoBehaviour
{
[SerializeField] bool runTest = false;
void Update()
using System;
using UnityEngine;
using IEnumerator=System.Collections.IEnumerator;
public enum CoroStatus
{
Running,
Suspended,
Stopped,
@michaelbartnett
michaelbartnett / shittyname.hs
Last active August 29, 2015 14:05
Goofing around after learning to implement zipWith in Learn You A Haskell
-- Shitty name generator for your next RPG Character. I have no idea what I'm doing, but Haskell seems pretty fun so far.
-- Feels awkward to implement zipWith using this, but I wanted to play around more with partial application
multiMap :: [a -> b] -> [a] -> [b]
multiMap [] _ = []
multiMap _ [] = []
multiMap (f:fs) (x:xs) = f x:multiMap fs xs
-- Redundantly reimplemented zipWith because LYAH told me to
zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
@michaelbartnett
michaelbartnett / us2cs_regexp_notes
Created August 29, 2014 05:25
Some possible unity script => csharp regexps
Replace var with type
(var)\W+\w+(\W*:)\W*(\w+)
Replace function ... eh
(function)\W+\w+\W*\(.*\)\W*(:\W*(\w+))?
Replace function with return type
(function)\W+\w+\W*\(.*\)\W*:\W*(\w+)\W*{
Replace void function
@michaelbartnett
michaelbartnett / named_arg_fail.cs
Last active August 29, 2015 14:05
mono sadness
//
// EppyEditor.PropertyField is supposed to be a replacement for functions like
// EditorGUILayout.FloatField and EditorGUILayout.TextField except it handles
// multi-object editing correctly without the programmer having to think about
// it, and chooses the correct GUI function based on the type paramter 'T'.
//
// This is different from EditorGUILayout.PropertyField in that (A) you get the
// result back, (B) it doesn't print a label automatically (doable already with
// propertyfield, but not if you want it to return an exact type) and (C) it allows
// you to pass in different function refs to tweak how it works.
@michaelbartnett
michaelbartnett / AngryCoroutine.cs
Created September 22, 2014 22:48
Unity3D compiler bug
using UnityEngine;
using System.Collections;
public class AngryCoroutine : MonoBehaviour
{
IEnumerator Start()
{
while (false) {
yield return null;
}
@michaelbartnett
michaelbartnett / GrossLinq.cs
Created October 23, 2014 02:18
monodevelop sigh
from assembly in AppDomain.CurrentDomain.GetAssemblies()
#if TEST
let typeList =
(new Func<Type[]>(() => {
Type[] result = null;
try {
result = assembly.GetTypes();
} catch (ReflectionTypeLoadException) {
if (assembly.FullName.StartsWith("MonoDevelop.NUnit")) {
// the MonoDevelop.NUnit assembly is screwed up