Skip to content

Instantly share code, notes, and snippets.

@darktable
darktable / SavWav.cs
Created April 6, 2012 05:01
Unity3D: script to save an AudioClip as a .wav file.
// Copyright (c) 2012 Calvin Rien
// http://the.darktable.com
//
// This software is provided 'as-is', without any express or implied warranty. In
// no event will the authors be held liable for any damages arising from the use
// of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
@darktable
darktable / GUIMerge.cs
Created March 29, 2012 18:58
Unity3D: Script to merge multiple GUISkins into a single GUISkin with multiple custom styles.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
public class GUIMerge : MonoBehaviour {
public GUISkin primary;
public GUISkin[] skins;
@darktable
darktable / CodeProfiler.cs
Created March 14, 2012 04:02
Unity3D: Tweaked version of @robotduck's CodeProfiler script.
// You can switch to a regular Update() loop
// if you comment out this line. (makes debugging easier)
#define COROUTINE
//
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using UnityEngine;
using Debug = UnityEngine.Debug;
@darktable
darktable / GUIScaler.cs
Created March 11, 2012 23:36
Unity3D: script to automatically scale gui elements on high dpi devices (like iPhone 4 or iPad 3rd Generation).
using UnityEngine;
using System.Collections;
namespace UnityEngine {
/// <summary>
/// Usage:
///
/// (optional) Call GUIScaler.Initialize() in Start(), Awake() or OnEnable() (only needed once)
/// Call GUIScaler.Begin() at the top of your OnGUI() methods
/// Call GUIScaler.End() at the bottom of your OnGUI() methods
@darktable
darktable / SelectWithLayer.cs
Created February 23, 2012 03:49
Unity3D: editor script to select all objects that are in a particular layer.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using DB = UnityEngine.Debug;
public class SelectWithLayer : ScriptableObject {
static void SelectLayer(int layerNum) {
var objs = Selection.GetFiltered(typeof(GameObject), SelectionMode.Deep);
@darktable
darktable / .hgignore
Created February 20, 2012 03:40
hg: Starter hgignore file for Unity3D projects
syntax: glob
.DS_Store
*.sln
*.userprefs
*.csproj
*.pidb
*.unitypackage
syntax: regexp
^Build/.*
@darktable
darktable / IconPostprocessor.cs
Created February 16, 2012 05:00
Unity3D: Editor script to prevent images added to Assets/Platform from being compressed. (Requires Unity Pro?)
using System.IO;
using UnityEditor;
using UnityEngine;
public class IconPostprocessor : AssetPostprocessor {
void OnPreprocessTexture () {
if (assetPath.ToLower().StartsWith(Path.Combine("assets", "platform"))) {
var ti = (TextureImporter) assetImporter;
@darktable
darktable / zwoptex.json
Created December 7, 2011 21:39
Zwoptex: Template for exporting zwoptex data in JSON format.
{"frames": {
{% for sprite in spritesAndAliases %}
"{{ sprite.name }}":
{
"frame": {"x":{{ sprite.textureRectX }},"y":{{ sprite.textureRectY }},"w":{{ sprite.textureRectWidth }},"h":{{ sprite.textureRectHeight }}},
"rotated": {% if sprite.isRotated %}true{% else %}false{% /if %},
"trimmed": {% if sprite.isTrimmed %}true{% else %}false{% /if %},
"spriteSourceSize": {"x":0,"y":0,"w":{{ sprite.sourceSizeWidth }},"h":{{ sprite.sourceSizeHeight }}},
"sourceSize": {"w":{{ sprite.sourceSizeWidth }},"h":{{ sprite.sourceSizeHeight }}},
"spriteColorRect": {"x":{{ sprite.sourceColorRectX }},"y":{{ sprite.sourceColorRectY }},"w":{{ sprite.sourceColorRectWidth }},"h":{{ sprite.sourceColorRectHeight }}},
@darktable
darktable / DebugConsole.cs
Created December 1, 2011 00:25
Unity3D: Heavily modified version of Jeremy Hollingsworth's DebugConsole script.
#define DEBUG_CONSOLE
#define DEBUG_LEVEL_LOG
#define DEBUG_LEVEL_WARN
#define DEBUG_LEVEL_ERROR
#if (UNITY_EDITOR || DEVELOPMENT_BUILD)
#define DEBUG
#endif
#if (UNITY_IOS || UNITY_ANDROID)
@darktable
darktable / MiniJSON.cs
Created November 30, 2011 23:08
Unity3D: MiniJSON Decodes and encodes simple JSON strings. Not intended for use with massive JSON strings, probably < 32k preferred. Handy for parsing JSON from inside Unity3d.
/*
* Copyright (c) 2013 Calvin Rien
*
* Based on the JSON parser by Patrick van Bergen
* http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html
*
* Simplified it so that it doesn't throw exceptions
* and can be used in Unity iPhone with maximum code stripping.
*
* Permission is hereby granted, free of charge, to any person obtaining