Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void DrawLine(Vector2 lineStart, Vector2 lineEnd, Color color)
- {
- DrawLine(lineStart, lineEnd, color, 1);
- }
- public static void DrawBox(float x, float y, float w, float h, Color color)
- {
- DrawLine(new Vector2(x, y), new Vector2(x + w, y), color);
- DrawLine(new Vector2(x, y), new Vector2(x, y + h), color);
- DrawLine(new Vector2(x + w, y), new Vector2(x + w, y + h), color);
- DrawLine(new Vector2(x, y + h), new Vector2(x + w, y + h), color);
- }
- public static void DrawLine(Vector2 lineStart, Vector2 lineEnd, Color color, int thickness)
- {
- if (_coloredLineTexture == null || _coloredLineColor != color)
- {
- _coloredLineColor = color;
- _coloredLineTexture = new Texture2D(1, 1);
- _coloredLineTexture.SetPixel(0, 0, _coloredLineColor);
- _coloredLineTexture.wrapMode = 0;
- _coloredLineTexture.Apply();
- }
- DrawLineStretched(lineStart, lineEnd, _coloredLineTexture, thickness);
- }
- public static void DrawLineStretched(Vector2 lineStart, Vector2 lineEnd, Texture2D texture, int thickness)
- {
- var vector = lineEnd - lineStart;
- float pivot = 57.29578f * Mathf.Atan(vector.y / vector.x);
- if (vector.x < 0f)
- {
- pivot += 180f;
- }
- if (thickness < 1)
- {
- thickness = 1;
- }
- int yOffset = (int)Mathf.Ceil((float)(thickness / 2));
- GUIUtility.RotateAroundPivot(pivot, lineStart);
- GUI.DrawTexture(new Rect(lineStart.x, lineStart.y - (float)yOffset, vector.magnitude, (float)thickness), texture);
- GUIUtility.RotateAroundPivot(-pivot, lineStart);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement