|
需要设置材质 lineMaterial.SetPass(0);
Material lineMaterial;void CreateLineMaterial() { Shader shader = Shader.Find("Hidden/Internal-Colored"); lineMaterial = new Material(shader); lineMaterial.hideFlags = HideFlags.HideAndDontSave; //设置参数 lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); //设置参数 lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off); //设置参数 lineMaterial.SetInt("_ZWrite", 0); } private void Awake() { CreateLineMaterial(); }private void OnPostRender() { DrawMutilLine(); }void DrawMutilLine() { List<Vector3> posList = new List<Vector3>(); posList.Add(new Vector3(0.3f, 0.6f, 0)); posList.Add(new Vector3(1.2f, 1.8f, 0)); posList.Add(new Vector3(0.6f, 2.4f, 0)); posList.Add(new Vector3(1.5f, 2.7f, 0)); if (posList.Count < 2) return; lineMaterial.SetPass(0); GL.Begin(GL.LINES); GL.Color(Color.green); for (int i = 0; i < posList.Count - 1; i++) { GL.Vertex(posList); GL.Vertex(posList[i + 1]); } GL.End(); } |
|