Skip to content

Instantly share code, notes, and snippets.

View DanPuzey's full-sized avatar

Dan Puzey DanPuzey

View GitHub Profile
@DanPuzey
DanPuzey / Promise.cs
Last active July 14, 2023 02:18
Unity3d: promises for Coroutines
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Promises
{
/// <summary>
/// Contains extension methods that provide promise-like behaviour for coroutines.
/// </summary>
@DanPuzey
DanPuzey / Log.cs
Last active October 24, 2018 10:28
Unity logging wrapper, for better performance and usage.
using UnityEngine;
namespace Assets.Phunk.Core
{
public static class Log
{
#region Error
public static void ErrorFormat(UnityEngine.Object context, string template, params object[] args)
{
var message = string.Format(template, args);
@DanPuzey
DanPuzey / SelectionHistory.cs
Created May 31, 2018 09:34
Unity3d editor window to show recent selections
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class SelectionHistory : EditorWindow
{
private const int NumberOfItemsToKeep = 6;
private const string MultiSelectPrefix = "+";
private const int ItemsPerRow = 2;
@DanPuzey
DanPuzey / GitRepl.ps1
Last active April 3, 2017 12:20
Super-hacky git REPL for PowerShell/Posh-Git
function GitPrompt()
{
Write-Host
$realLASTEXITCODE = $LASTEXITCODE
$Host.UI.RawUI.ForegroundColor = "White"
Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
checkGit($pwd.ProviderPath)
$global:LASTEXITCODE = $realLASTEXITCODE
Write-Host "`ngit> " -NoNewLine -ForegroundColor "DarkGray"
}
@DanPuzey
DanPuzey / EventAggregator.cs
Created January 30, 2017 20:56
Unity3d/C# EventAggregator (Unity v5.5+)
using System;
using System.Linq;
using Diagnostics;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Events
{
public static class EventAggregator
@DanPuzey
DanPuzey / AddToRegistry.cs
Created October 26, 2015 17:17
Prototype Unity3d service locator (nicer than singletons!)
using UnityEngine;
namespace FunkyGeek.Core
{
/// <summary>
/// Adds a list of components (typically from this or child GameObjects) to the global registry.
/// </summary>
public class AddToRegistry : MonoBehaviour
{
public Object[] ObjectsToAdd;
@DanPuzey
DanPuzey / .gitattributes
Created October 23, 2015 15:27
.gitAttributes for Unity LFS
*.tif filter=lfs diff=lfs merge=lfs -text
*.cubemap filter=lfs diff=lfs merge=lfs -text
*.tga filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.raw filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.psd filter=lfs diff=lfs merge=lfs -text
*.mov filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text
@DanPuzey
DanPuzey / .gitignore
Created October 21, 2015 09:43
My Unity3d .gitignore
# unneeded Unity folders
temp/
library/
screenshots/
# VS user files
*.csproj.user
*.suo
# unneeded VS project files
@DanPuzey
DanPuzey / gist:c03e369eb7090808ca9c
Last active August 29, 2015 14:22
Random snippet of .cs that is broken in my Unity project (but works in a clean project)
string s = "RHUBARB" + "æ" + "CUSTARD";
var c = s[7];
var i = (int)c;
Debug.Log(c); // expect æ in console
Debug.Log(i); // expect 230 in console
IEnumerable<string> ErrorsFor3(string[] hayStack, string[] needles, Func<string, string, string> errorMessageGenerator)
{
return hayStack.Select(hay => needle.FirstOrDefault(hay.Contains))
.Where(n => n != null)
.Select(matchingNeedle => errormessageGenerator(hay, matchingNeedle));
}