Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@ahvonenj
ahvonenj / catchajax.js
Created August 10, 2015 09:01
Catch AJAX event / request
$(document).ajaxSend(function(event, request, settings)
{
console.log('Caught AJAX request!');
console.log(event);
console.log(request);
console.log(settings);
});
@radiatoryang
radiatoryang / DecentWater.shader
Last active September 26, 2015 22:09
a not-cheap but not-expensive water shader, decent quality DX9 2012-era water, by Robert Yang (@radiatoryang)
// a not-cheap but not-expensive water shader
// decent quality DX9 2012-era water, by Robert Yang (@radiatoryang)
// based on:
// built-in legacy Alpha-Bumped shader
// added cubemap reflection and rimlight stuff
// GlassStainedBumpDistort from Unity glass refraction demo
// http://forum.unity3d.com/threads/grabtexture-uv-correction-in-surface-shader.67742/
// ... this does NOT have fogging or edge blending (too expensive / annoying?)
@xanathar
xanathar / MoonSharp_Threading.cs
Created August 20, 2015 17:05
MoonSharp threading example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
namespace Playground
@mfuerstenau
mfuerstenau / zigzag-encoding.README
Last active April 15, 2026 16:39
ZigZag encoding/decoding explained
ZigZag-Encoding
---------------
Maps negative values to positive values while going back and
forth (0 = 0, -1 = 1, 1 = 2, -2 = 3, 2 = 4, -3 = 5, 3 = 6 ...)
(i >> bitlength-1) ^ (i << 1)
with "i" being the number to be encoded, "^" being
XOR-operation and ">>" would be arithemtic shifting-operation
@DGoodayle
DGoodayle / RadialLayout.cs
Created September 16, 2015 13:48
Radial Layouts in Unity
using UnityEngine;
using UnityEngine.UI;
/*
Radial Layout Group by Just a Pixel (Danny Goodayle) - http://www.justapixel.co.uk
Copyright (c) 2015
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
@gering
gering / Toolkit
Last active February 25, 2026 01:53
persitent data path handling in Unity with fallback
private static string[] _persistentDataPaths;
public static bool IsDirectoryWritable(string path) {
try {
if (!Directory.Exists(path)) return false;
string file = Path.Combine(path, Path.GetRandomFileName());
using (FileStream fs = File.Create(file, 1)) {}
File.Delete(file);
return true;
} catch {
@DGoodayle
DGoodayle / QuadTreeTest.cs
Last active May 12, 2025 10:01
Quadtree in Unity
using UnityEngine;
using System.Collections;
public class QuadTreeTest : MonoBehaviour {
public class TestObject : IQuadTreeObject{
private Vector3 m_vPosition;
public TestObject(Vector3 position){
m_vPosition = position;
}
public Vector2 GetPosition(){
@manuerumx
manuerumx / postJSON.cs
Last active October 20, 2021 05:39
Unity 3D example POST JSON Data to a Server with http Auth
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class goLevel : MonoBehaviour {
//With the @ before the string, we can split a long string in many lines without getting errors
private string json = @"{
'hello':'world',
'foo':'bar',
'count':25
@FreyaHolmer
FreyaHolmer / int2.cs
Last active August 15, 2024 08:42
int2 type for Unity
/////////////////////////////////////////////////////////////////////////////
// int2 is similar to Vector2, but with integers instead of floats
// Useful for various grid related things.
//
// - Swizzle operators xx/xy/yx/yy
// - Extended arithmetic operators similar to shader data types
// A few examples:
// int2(8,4) / int2(2,4) -> int2(4,1)
// 16 / int2(2,4) -> int2(8,4)
// int2(2,3) * int2(4,5) -> int2(8,15)
@yuri-tikhomirov
yuri-tikhomirov / FastList.cs
Last active September 16, 2025 01:48
FastList<T> is a System.Collections.Generic.List<T> modification such, that allows to not produce garbage when using foreach.
/*
FastList<T> is a System.Collections.Generic.List<T> modification such, that allows to not produce garbage when using foreach.
Useful for old versions of c# runtime (like Mono 2.x), i.e. for Unity.
It implements own instance-type enumerator and caches only one instance of this enumerator inside.
Instance-type enumerator allows to avoid boxing that occurs when foreach converts IEnumerator to IDisposable and calls Dispose().
(Default List<T> enumerator is value-type (struct), so when foreach converts to IDisposable, boxing occurs and 20 bytes of garbage will be collected.)
Warnings: