Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class LineDrawer : MonoBehaviour
  6. {
  7. List<Vector3> lines;
  8.  
  9. static Material lineMaterial;
  10. static void CreateLineMaterial()
  11. {
  12. if (!lineMaterial)
  13. {
  14. Shader shader = Shader.Find("Hidden/Internal-Colored");
  15. lineMaterial = new Material(shader);
  16. lineMaterial.hideFlags = HideFlags.HideAndDontSave;
  17. lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
  18. lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
  19. lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
  20. lineMaterial.SetInt("_ZWrite", 0);
  21. lineMaterial.color = Color.yellow;
  22. }
  23. }
  24. // Start is called before the first frame update
  25. void Start()
  26. {
  27. lines = new List<Vector3>();
  28. lines.Add(new Vector3(1, 1, 1));
  29. lines.Add(new Vector3(1, -1, 1));
  30. lines.Add(new Vector3(-1, 1, 1));
  31. lines.Add(new Vector3(-1, -1, 1));
  32. lines.Add(new Vector3(1, 1, -1));
  33. lines.Add(new Vector3(1, -1, -1));
  34. lines.Add(new Vector3(-1, 1, -1));
  35. lines.Add(new Vector3(-1, -1, -1));
  36. }
  37.  
  38. private void OnPostRender()
  39. {
  40. CreateLineMaterial();
  41. lineMaterial.SetPass(0);
  42. for (int i = 0; i < lines.Count - 1; i++)
  43. {
  44. GL.Begin(GL.LINES);
  45. GL.Vertex(lines[i]);
  46. GL.Vertex(lines[i + 1]);
  47. GL.End();
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement