Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. public static void DrawLine(Vector2 lineStart, Vector2 lineEnd, Color color)
  2. {
  3. DrawLine(lineStart, lineEnd, color, 1);
  4. }
  5.  
  6. public static void DrawBox(float x, float y, float w, float h, Color color)
  7. {
  8. DrawLine(new Vector2(x, y), new Vector2(x + w, y), color);
  9. DrawLine(new Vector2(x, y), new Vector2(x, y + h), color);
  10. DrawLine(new Vector2(x + w, y), new Vector2(x + w, y + h), color);
  11. DrawLine(new Vector2(x, y + h), new Vector2(x + w, y + h), color);
  12. }
  13.  
  14. public static void DrawLine(Vector2 lineStart, Vector2 lineEnd, Color color, int thickness)
  15. {
  16. if (_coloredLineTexture == null || _coloredLineColor != color)
  17. {
  18. _coloredLineColor = color;
  19. _coloredLineTexture = new Texture2D(1, 1);
  20. _coloredLineTexture.SetPixel(0, 0, _coloredLineColor);
  21. _coloredLineTexture.wrapMode = 0;
  22. _coloredLineTexture.Apply();
  23. }
  24.  
  25. DrawLineStretched(lineStart, lineEnd, _coloredLineTexture, thickness);
  26. }
  27.  
  28. public static void DrawLineStretched(Vector2 lineStart, Vector2 lineEnd, Texture2D texture, int thickness)
  29. {
  30. var vector = lineEnd - lineStart;
  31. float pivot = 57.29578f * Mathf.Atan(vector.y / vector.x);
  32. if (vector.x < 0f)
  33. {
  34. pivot += 180f;
  35. }
  36.  
  37. if (thickness < 1)
  38. {
  39. thickness = 1;
  40. }
  41.  
  42. int yOffset = (int)Mathf.Ceil((float)(thickness / 2));
  43.  
  44. GUIUtility.RotateAroundPivot(pivot, lineStart);
  45. GUI.DrawTexture(new Rect(lineStart.x, lineStart.y - (float)yOffset, vector.magnitude, (float)thickness), texture);
  46. GUIUtility.RotateAroundPivot(-pivot, lineStart);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement