Skip to content

Instantly share code, notes, and snippets.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public static class ListExtensions
{
public static T PickRandom<T>(this IList<T> source)
{
if (source.Count == 0)
return default(T);
/// <summary>
/// Maps a value from some arbitrary range to the 0 to 1 range
/// </summary>
/// <param name="value">Value.</param>
/// <param name="min">Lminimum value.</param>
/// <param name="max">maximum value</param>
public static float Map01(float value, float min, float max)
{
return (value - min) * 1f / (max - min);
}
@Grogal
Grogal / Unity Orthographic Camera in Units
Last active October 25, 2015 08:59
Unity Orthographic Camera in Units
float height = 2*Camera.main.orthographicSize;
float width = height*Camera.main.aspect;
@Grogal
Grogal / .gitignore
Created October 15, 2015 13:45 — forked from thebeardphantom/.gitignore
Unity GitIgnore
# Ignore everything
/*
/*/
# Inverse ignore some stuff
!/Assets/
!/ProjectSettings/
!.gitignore
# OS Stuff
using UnityEngine;
public static class ColliderExtensions {
public static bool IsVisibleFrom(this Collider collider, Camera camera)
{
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(camera);
return GeometryUtility.TestPlanesAABB(planes, collider.bounds);
}
@Grogal
Grogal / ScriptableAssetCreator.cs
Created October 7, 2015 10:13 — forked from prodigga/ScriptableAssetCreator.cs
Right click on any script in your project that defines a ScriptableObject and create a ScriptableObject asset out of it! See here http://imgur.com/a/e7FDR#0 NOTE: This script was made somewhat redundant with the introduction of the [CreateAssetMenu] attribute - look it up :)
using UnityEditor;
using UnityEngine;
/// <summary>
/// Right click on any script in your project that defines a ScriptableObject
/// and create a ScriptableObject asset out of it! See here http://imgur.com/a/e7FDR#0
/// </summary>
/// <author>Tim Aksu</author>
/// <email>timur.s.aksu@gmail.com</email>
public static class ScriptableObjectUtility
@Grogal
Grogal / SpecialEventClass.cs
Created October 1, 2015 06:06 — forked from stramit/SpecialEventClass.cs
SpecialEventClass
/*
* When developing the UI system we came across a bunch of things we were not happy
* with with regards to how certain events and calls could be sent in a loosely coupled
* way. We had this requirement because with a UI you tend to implement widgets that receive
* certain events, but you don't really want to have lots of glue code to manage them
* and keep track of them. The eventing interfaces we developed helped with this. One of
* the interesting things, is that they are not justfor the UI system! You can use this as
* a type-safe, fast, and simple alternative to SendMessage (never use SendMessage!).
* So how does it all work?