public static void GetDrawStyle(this ConfigNode node, out UnityEngine.Color colour, out GLLines.Style style) { colour = XKCDColors.ColorTranslator.FromHtml(node.GetUniqueValue("colour")); style = (GLLines.Style)Enum.Parse(typeof(GLLines.Style), node.GetUniqueValue("style"), true); }
private void DrawLineMesh(UnityEngine.Mesh mesh, int vertex_count, UnityEngine.Color colour, GLLines.Style style) { mesh.vertices = VertexBuffer.vertices; int index_count = style == GLLines.Style.Dashed ? vertex_count & ~1 : vertex_count; var indices = new int[index_count]; for (int i = 0; i < index_count; ++i) { indices[i] = i; } var colours = new UnityEngine.Color[VertexBuffer.size]; if (style == GLLines.Style.Faded) { for (int i = 0; i < vertex_count; ++i) { var faded_colour = colour; // Fade from the opacity of |colour| (when i = 0) down to 20% of that // opacity. faded_colour.a *= 1 - 0.8f * (i / (float)vertex_count); colours[i] = faded_colour; } } else { for (int i = 0; i < vertex_count; ++i) { colours[i] = colour; } } mesh.colors = colours; mesh.SetIndices( indices, style == GLLines.Style.Dashed ? UnityEngine.MeshTopology.Lines : UnityEngine.MeshTopology.LineStrip, submesh: 0); mesh.RecalculateBounds(); // If the lines are drawn in layer 31 (Vectors), which sounds more // appropriate, they vanish when zoomed out. Layer 9 works; pay no // attention to its name. UnityEngine.Graphics.DrawMesh( mesh, UnityEngine.Vector3.zero, UnityEngine.Quaternion.identity, GLLines.line_material, (int)PrincipiaPluginAdapter.UnityLayers.Atmosphere, PlanetariumCamera.Camera); }