private static Mesh CreateMesh(RadialBarSettings settings) { // radii var innerRadius = settings.Radius - settings.Width; // get base points along the circle; var nPoints = (int)(settings.Progress * Mathf.PI * 2 / settings.RadiansPerSection); var points = new Vector2[nPoints + 1]; for (var i = 0; i < nPoints; i++) { points[i] = GetPoint(i * settings.RadiansPerSection); } // final point points[nPoints] = GetPoint(settings.Progress * Mathf.PI * 2); // vertices var nVertices = (nPoints + 1) * 2; var vertices = new Vector3[nVertices]; var colors = new Color[nVertices]; var normals = new Vector3[nVertices]; var triangles = new int[nPoints * 6]; for (var i = 0; i < nPoints + 1; i++) { var j = i * 2; vertices[j] = new Vector3(points[i].x * innerRadius, 0f, points[i].y * innerRadius); vertices[j + 1] = new Vector3(points[i].x * settings.Radius, 0f, points[i].y * settings.Radius); colors[j] = Color.white; colors[j + 1] = Color.white; normals[j] = Vector3.up; normals[j + 1] = Vector3.up; if (i < nPoints) { var k = i * 6; triangles[k] = j; triangles[k + 1] = j + 1; triangles[k + 2] = j + 2; triangles[k + 3] = j + 2; triangles[k + 4] = j + 1; triangles[k + 5] = j + 3; } } return(new Mesh { name = $"radialMesh({settings.Radius}, {settings.Width}, {settings.Progress}, {settings.RadiansPerSection})", vertices = vertices, triangles = triangles, colors = colors, normals = normals }); }
private static Mesh GetMesh(RadialBarSettings settings) { if (_meshCache.TryGetValue(settings, out var mesh)) { return(mesh); } mesh = CreateMesh(settings); _meshCache.Add(settings, mesh); Logger.Debug($"Mesh created: {mesh.name}"); return(mesh); }
public static Texture Get(float radius, float width, float progress, float radiansPerSection = 2 *Mathf.PI / 100) { var settings = new RadialBarSettings(radius, width, progress, radiansPerSection); if (_renderTextureCache.TryGetValue(settings, out var texture)) { return(texture); } texture = new RenderTexture(settings.Size, settings.Size, 32); _renderTextureCache.Add(settings, texture); RadialRenderer.Render(GetMesh(settings), texture); return(texture); }