Created
March 19, 2014 02:36
-
-
Save TimothyFitz/9634519 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class Util | |
{ | |
static public T Choice<T>(T[] choices) { | |
// Why is Random.value [0,1] and not [0,1) like every other library? Or why isn't there a [0,1) variant? | |
return choices.Length > 0 ? choices[Mathf.FloorToInt(Random.value * 0.99999999f * choices.Length)] : default(T); | |
} | |
static public Vector2 PerpendicularCW(Vector2 vec) { | |
return new Vector2(vec.y, -vec.x); | |
} | |
static public Vector2 PerpendicularCCW(Vector2 vec) { | |
return new Vector2(-vec.y, vec.x); | |
} | |
static public float Angle(Vector2 vector) { | |
return Mathf.Atan2(vector.y, vector.x); | |
} | |
static public float Angle(Vector2 from, Vector2 to) { | |
return Angle(from - to); | |
} | |
static public bool AreColorsEqual(Color32 lhs, Color32 rhs) { | |
return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && lhs.a == rhs.a; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment