Last active
August 29, 2015 14:07
-
-
Save kernalphage/a30bb44a434f68fee954 to your computer and use it in GitHub Desktop.
This file contains 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; | |
using System.Collections; | |
public class _C { | |
/* Screen to world utils */ | |
public static Vector2 ScreenBottomLeft() | |
{ | |
Vector2 dim = new Vector3(0,0,Camera.main.farClipPlane); | |
return Camera.main.ViewportToWorldPoint(dim); | |
return dim; | |
} | |
public static Vector2 ScreenTopRight() | |
{ | |
Vector2 dim = new Vector3(1,1,Camera.main.farClipPlane); | |
return Camera.main.ViewportToWorldPoint(dim); | |
return dim; | |
} | |
public static Vector2 RandomScreenPoint( Rect inset = new Rect() ) | |
{ | |
Vector2 topRight = ScreenTopRight(); | |
topRight.x += inset.x; | |
topRight.y += inset.y; | |
Vector2 bottomLeft = ScreenBottomLeft(); | |
bottomLeft.x -= inset.width; | |
bottomLeft.y -= inset.height; | |
float ex = Random.Range(topRight.x, bottomLeft.x); | |
float wy = Random.Range(topRight.y, bottomLeft.y); | |
return new Vector2(ex,wy); | |
} | |
public static Vector2 ClampToScreen(Vector2 input) | |
{ | |
Vector2 topRight = ScreenTopRight(); | |
Vector2 bottomLeft = ScreenBottomLeft(); | |
input.x = Mathf.Clamp(input.x, bottomLeft.x, topRight.x); | |
input.y = Mathf.Clamp(input.y, bottomLeft.y, topRight.y); | |
return input; | |
} | |
public static void Assert( bool condition, object throwable = null) | |
{ | |
if(!condition) | |
{ | |
if(throwable == null) throwable = "err"; | |
Debug.LogError(throwable.ToString()); | |
} | |
} | |
public static void Suggest( bool condition, object throwable = null) | |
{ | |
if(!condition) | |
{ | |
if(throwable == null) throwable = "warn"; | |
Debug.LogWarning(throwable.ToString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment