Skip to content

Instantly share code, notes, and snippets.

@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 }}},
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(Sprite))]
public class SpritePropertyDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent labelN)
{
if (property.objectReferenceValue != null)
{
@darktable
darktable / Helper.cs
Created June 8, 2019 15:48
A utility script to find every component of a particular type in a scene. Not sure what the results will be if you have multiple additive scenes loaded.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Helper : MonoBehaviour
{
public static List<T> FindThemAll<T>(bool includeInactive = false) where T : UnityEngine.Component
{
var scene = SceneManager.GetActiveScene();
@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 / PostprocessBuildPlayer.cs
Created July 24, 2012 22:11
Unity3D: C# replacement for the python version of PostprocessBuildPlayer
using UnityEngine;
using System.Collections;
using UnityEditor;
using UnityEditor.Callbacks;
using System.IO;
public class PostprocessBuildPlayer : ScriptableObject {
[PostProcessBuild]
static void OnPostprocessBuildPlayer(BuildTarget target, string buildPath) {
@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 / UpdateXcodeProject.cs
Created October 5, 2012 16:57
Unity3D: Post-process script that copies the xcode build output to another directory. Used for updating a heavily modified Xcode project without stomping on changes to AppController.mm, Info.plist, etc.
/* **************************************************************************
Copyright 2012 Calvin Rien
(http://the.darktable.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@darktable
darktable / minijsonjsdemo.js
Created August 30, 2012 21:54
Unity3D: Example of using MiniJSON in UnityScript (JavaScript).
#pragma strict
import MiniJSON;
import System.Collections.Generic;
function Start () {
var jsonString = "{ \"array\": [1.44,2,3], " +
"\"object\": {\"key1\":\"value1\", \"key2\":256}, " +
"\"string\": \"The quick brown fox \\\"jumps\\\" over the lazy dog \", " +
"\"unicode\": \"\\u3041 Men\\u00fa sesi\\u00f3n\", " +
"\"int\": 65536, " +
import struct
import SocketServer
from base64 import b64encode
from hashlib import sha1
from mimetools import Message
from StringIO import StringIO
# import threading
class WebSocketsHandler(SocketServer.StreamRequestHandler):
@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;