*
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class Tools{
|
||||
|
||||
static Material lineMaterial;
|
||||
static void CreateLineMaterial()
|
||||
{
|
||||
if( !lineMaterial ) {
|
||||
lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
|
||||
"SubShader { Pass { " +
|
||||
" Blend SrcAlpha OneMinusSrcAlpha " +
|
||||
" ZWrite Off Cull Off Fog { Mode Off } " +
|
||||
" BindChannels {" +
|
||||
" Bind \"vertex\", vertex Bind \"color\", color }" +
|
||||
"} } }" );
|
||||
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
|
||||
lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void DrawRectangle(Rect rect, Color color){
|
||||
DrawRectangle (rect.x, rect.y, rect.width, rect.height, color);
|
||||
}
|
||||
public static void DrawRectangle(float x, float y, float width, float height, Color color){
|
||||
CreateLineMaterial ();
|
||||
lineMaterial.SetPass (0);
|
||||
GL.Begin(GL.QUADS);
|
||||
GL.Color(color);
|
||||
GL.Vertex3(x, y, 0);
|
||||
GL.Vertex3(x, y + height, 0);
|
||||
GL.Vertex3(x + width, y + height, 0);
|
||||
GL.Vertex3(x + width, y, 0);
|
||||
GL.End();
|
||||
}
|
||||
|
||||
public static Rect BoundsToRect(Bounds bounds){
|
||||
return new Rect(bounds.min.x, bounds.min.y, bounds.max.x - bounds.min.x, bounds.max.y - bounds.min.y);
|
||||
}
|
||||
|
||||
public static Vector3 WorldToGuiPoint(Vector3 point){
|
||||
|
||||
var pt = Camera.main.WorldToScreenPoint(point);
|
||||
pt.y = Camera.main.pixelHeight - pt.y;
|
||||
return pt;
|
||||
}
|
||||
|
||||
public static void BeginGui(bool verticalFlip = true){
|
||||
GL.PushMatrix();
|
||||
if (verticalFlip) {
|
||||
GL.LoadPixelMatrix (0, Camera.current.pixelWidth, Camera.current.pixelHeight, 0);
|
||||
} else {
|
||||
GL.LoadPixelMatrix (0, Camera.current.pixelWidth, 0, Camera.current.pixelHeight);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void EndGui(){
|
||||
GL.PopMatrix();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user