Skip to content

Instantly share code, notes, and snippets.

@mumoshu
mumoshu / Unity+WebSocket.cs
Created August 31, 2011 16:13
Unity+WebSocket.cs
using UnityEngine;
using System.Collections;
using SuperWebSocket.Client;
using System;
public class Net : MonoBehaviour {
private string lastMessage = string.Empty;
public static string serverURI = "ws://192.168.100.196:12345/channels/0?userId=1";
public static WebSocket webSocket = new WebSocket(serverURI, "basic");
@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;
@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;
meter{
display: block;
border: 1px outset;
height: 20px;
width: 100px;
overflow: hidden;
}
meter div
{
display: block;
@albertobajo
albertobajo / parse_signed_request
Created November 10, 2010 10:03
Python implementation of Facebook's php signed_request parser: http://developers.facebook.com/docs/authentication/canvas
import hmac
import simplejson as json
from base64 import urlsafe_b64decode
from hashlib import sha256
def parse_signed_request(signed_request, secret):
[encoded_sig, payload] = signed_request.split('.')
# decode data
@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;
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):
@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{
@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
@GarethJones
GarethJones / MiniJson.cs
Created January 12, 2012 17:32
MiniJson Flash Unity version
// using UnityEngine;
using System;
using System.Collections;
using System.Text;
/* Based on the JSON parser from
* http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html
*
* I simplified it so that it doesn't throw exceptions
* and can be used in Unity iPhone with maximum code stripping.