Skip to content

Instantly share code, notes, and snippets.

@v21
v21 / unity-analytics
Created April 6, 2011 10:50
What Unity sent to Google Analytics
GET /__utm.gif?utmwv=1.3&utmn=1102687404&utmcs=ISO-8859-1&utmsr=1920x1080&utmsc=24-bit&utmul=en&utmje=0&utmfl=-&utmdt=Unity%20Editor&utmhn=editor%2Eanalytics%2Eunity3d%2Ecom&utmr=%2D&utmt=event&utme=5%28Compiler%2Aerror%20CS0619%2A%60UnityEngine%2EAudioSource%2ErolloffFactor%27%20is%20obsolete%3A%20%60rolloffFactor%20is%20not%20supported%20anymore%2E%20Use%20min%2D%2C%20maxDistance%20and%20rolloffMode%20instead%2E%27%29%281%29%3A&utmac=UA-16068464-6&utmcc=__utma%3D1.1790855761.1301922981.1302003006.1302086526.8%3B%2B__utmz%3D1.1302086526.8.1.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B HTTP/1.1
User-Agent: UnityEditor/3.3.0.63135 (Macintosh; U; Intel Mac OS X 10.6; en)
Host: www.google-analytics.com
Accept: */*
@v21
v21 / gist:5377854
Created April 13, 2013 10:20
> Okay. Maths is beyond me, so: I want to get a tangental line to a 3D line at a random angle & random point along it, of a random length.How? Like this:
Vector3 randomVector = Random.onUnitSphere;
Plane plane = new Plane(randomVector, start, end);
float breakPoint = Random.value;
Vector3 candidatePoint = plane.normal * Random.value * maxBreakDistanceFromPath + (end - start) * breakPoint + start;
return candidatePoint;
@v21
v21 / gist:5378391
Created April 13, 2013 13:23
A script to get a random point on a mesh, for Unity3D
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RandomPointOnMesh : MonoBehaviour
{
public MeshCollider lookupCollider;
public bool bangGetPoint;
private Vector3 randomPoint;
Vector3 parallaxCenter = background.parallaxCenter.position;
Vector3 mainOffset = mainCamera.position - parallaxCenter;
cam1.position = parallaxCenter + Vector3.Scale(mainOffset, cam1Factor);
(Scale is component-wise multiplication)
@v21
v21 / gist:8029204
Created December 18, 2013 20:16
An implementation of Photoshop's "Screen" blend mode for Unity3D.
Shader "Sunspots" {
Properties {
_MainTex ("Texture1 (RGB)", 2D) = "white" {}
_Color ("Main Color", Color) = (1,1,1,1)
}
Category {
Tags {"RenderType"="Opaque" "Queue"="Transparent"}
Lighting Off
BindChannels {
@v21
v21 / MakeGif.cs
Created December 24, 2013 11:36
Unity3D editor script to run the game and extract a set number of images and save them to a file. Put this code into a file called MakeGif.cs inside a folder called "Editor"
using System;
using UnityEditor;
using UnityEngine;
using System.Collections;
public class MakeGif : EditorWindow {
public string folder = "ScreenshotFolder";
public int frameRate = 25;
take a file.gif
gifsicle.exe -b -O3 file.gif
"C:\Program Files (x86)\IrfanView\i_view32.exe" file.gif /extract=("\extracted",gif)
gifsicle.exe extracted/file_frame_*.gif > file.gif
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class DontDestroyOnLoad : MonoBehaviour {
void OnEnable()
{
DontDestroyOnLoad(gameObject);
}
}
@v21
v21 / Extensions.cs
Created May 20, 2014 10:52
List extensions in c#
using System.Linq;
using UnityEngine;
using System;
using System.Collections.Generic;
using Debug = UnityEngine.Debug;
using Object = UnityEngine.Object;
using Random = UnityEngine.Random;
public static class Extensions
{
@v21
v21 / gist:5f3ea035cc0c349f8d1a
Created June 3, 2014 13:31
RGB to HSV and vice versa (in shaders)
float3 Hue(float H)
{
float R = abs(H * 6 - 3) - 1;
float G = 2 - abs(H * 6 - 2);
float B = 2 - abs(H * 6 - 4);
return saturate(float3(R,G,B));
}
float3 HSVtoRGB(in float3 HSV)