Skip to content

Instantly share code, notes, and snippets.

@flarb
flarb / NaturalOrientation.cs
Created August 4, 2012 00:03
How to detect the "natural" orientation of an Android device in Unity3D. Also can use to detect tablet and phone.
using UnityEngine;
using System.Collections;
public class NaturalOrientation : MonoBehaviour {
public static int ORIENTATION_UNDEFINED = 0x00000000;
public static int ORIENTATION_PORTRAIT = 0x00000001;
public static int ORIENTATION_LANDSCAPE = 0x00000002;
public static int ROTATION_0 = 0x00000000;
@jkp
jkp / websocketserver.py
Created July 18, 2012 13:28
A simple WebSockets server with no dependencies
import struct
import SocketServer
from base64 import b64encode
from hashlib import sha1
from mimetools import Message
from StringIO import StringIO
class WebSocketsHandler(SocketServer.StreamRequestHandler):
magic = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
@pamelafox
pamelafox / senderror.js
Created February 21, 2012 19:20
Sending JS errors to server
function sendError(message, url, lineNum) {
var i;
// First check the URL and line number of the error
url = url || window.location.href;
lineNum = lineNum || 'None';
// If the error is from these 3rd party script URLs, we ignore
// We could also just ignore errors from all scripts that aren't our own
var scriptURLs = [
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@flarb
flarb / DiffuseDetailAmbient.shader
Created February 16, 2012 09:42
Mobile Ambient Diffuse Detail shader for Unity3D - just a simple one line change.
Shader "Mobile/Ambient Diffuse Detail" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Detail ("Detail (RGB)", 2D) = "gray" {}
}
SubShader {
Pass{
@hoesing
hoesing / ProjectAssetPostprocessor.cs
Created February 16, 2012 09:10
Unity asset pre/postprocessor for applying asset defaults by path.
// Drop this script in the Editor directory in your project (creating the Editor directory if it's not there yet)
// Then re-import the assets in the directories covered by this script (right click and reimport)
//
// I would replace my path checking with the path checking from this gist:
// https://gist.github.com/1842177
//
// The texture settings for icons might want to use some of his settings combined with mine as well
using UnityEngine;
@boj
boj / SimplexNoise.cs
Created February 7, 2012 14:14
Stefan Gustavson's "Simplex noise demystified" in C# + Unity3d Mathf methods.
using UnityEngine;
using System.Collections;
// copied and modified from http://webstaff.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
private static int[][] grad3 = new int[][] {
new int[] {1,1,0}, new int[] {-1,1,0}, new int[] {1,-1,0}, new int[] {-1,-1,0},
new int[] {1,0,1}, new int[] {-1,0,1}, new int[] {1,0,-1}, new int[] {-1,0,-1},
new int[] {0,1,1}, new int[] {0,-1,1}, new int[] {0,1,-1}, new int[] {0,-1,-1}};
@boj
boj / GameObjectQueue.cs
Created February 5, 2012 13:46
Unity3d Object Recycle System
using UnityEngine;
using System.Collections;
public class LinkObject {
public LinkObject prev = null;
public LinkObject next = null;
public GameObject data;
public LinkObject(GameObject link) {
data = link;
using System;
using System.IO//.Ports;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using UnityEngine;
/// <summary>
/// UdpPacket provides packetIO over UDP
@asus4
asus4 / TouchToMouseConverter.cs
Last active September 29, 2015 21:57
TouchEvent to MouseEvent for Unity
/**
Converts Mobile Touch to the default Mouse Click
## invoked these method in Mobile too
OnMouseDown
OnMouseDrag
OnMouseUp
## only called in touch screen