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 / 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
@darktable
darktable / app.yaml
Created March 16, 2011 19:10
GAE: App.yaml designed for serving a static site on Google App Engine (Python). Copy your static html and files into a folder called "static" next to app.yaml. Contains a bunch of mimetype declarations from html5boilerplate's .htaccess. May not be neces
application: you-app-name-here
version: 1
runtime: python
api_version: 1
default_expiration: "30d"
handlers:
- url: /(.*\.(appcache|manifest))
mime_type: text/cache-manifest
@darktable
darktable / WorldNormalFromDepthTexture.shader
Created November 11, 2023 18:00 — forked from bgolus/WorldNormalFromDepthTexture.shader
Different methods for getting World Normal from Depth Texture, without any external script dependencies.
Shader "WorldNormalFromDepthTexture"
{
Properties {
[KeywordEnum(3 Tap, 4 Tap, Improved, Accurate)] _ReconstructionMethod ("Normal Reconstruction Method", Float) = 0
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100
@darktable
darktable / SpatialHash.cs
Last active August 29, 2023 13:43
Spatial hash implementation for Unity.
// The contents of this file is free and unencumbered software released into the
// public domain. For more information, please refer to <http://unlicense.org/>
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Assertions;
public class SpatialHash<T>
@darktable
darktable / Loggers.cs
Created July 31, 2023 01:47 — forked from thygrrr/Loggers.cs
A zero-boilerplate static logger for Unity in 25 lines of code
//SPDX-License-Identifier: Unlicense OR CC0-1.0+
using System;
using System.Collections.Generic;
using UnityEngine;
using Object = UnityEngine.Object;
// ReSharper disable MemberCanBePrivate.Global
namespace Loggers
{
/// <summary>
@darktable
darktable / GenerateSceneLoaderMenu.cs
Created July 17, 2023 13:23
Utility script to generate a menu items to load the scenes included in build settings.
// The contents of this file is free and unencumbered software released into the
// public domain. For more information, please refer to <http://unlicense.org/>
using System;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
@darktable
darktable / DrawingColor.cs
Created July 8, 2023 01:12
A static class you can use in Unity to access all the predefined colors in Microsoft's System.Drawing.Color.
using UnityEngine;
/// <summary>
/// Microsoft has a ton of predefined colors in System.Drawing.Color
/// </summary>
public static class DrawingColor
{
// only Unity color not represented (Unity's "green" is Microsoft's "Lime")
public static readonly Color Clear = Color.clear;
@darktable
darktable / EventManager.cs
Created April 11, 2023 15:04
EventManager script found in the Unity's FPS Micro Game sample. Useful for global event broadcasting.
using System;
using System.Collections.Generic;
namespace Unity.FPS.Game
{
public interface IBroadcastEvent { }
// A simple Event System that can be used for remote systems communication
public static class EventManager
{
@darktable
darktable / ServiceLocator.cs
Created April 11, 2023 15:02
Service locator pattern with callback system derived from EventManager script found in Unity FPS Microgame.
/*****************************************************************************
MIT License
Copyright (c) 2023 Calvin Rien
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is