private void GenerateReticle(float radius, float thickness) { //float thickness = .02f; //float thickness = .0025f; // looks great on actual device at z=2m //thickness = .01f; float innerRadius = radius - 0.5f * thickness; float outerRadius = radius + 0.5f * thickness; int segments = 10; List <Vector3> verts = new List <Vector3>(); List <int> triangles = new List <int>(); List <Color32> colors = new List <Color32>(); Color32 black = new Color32(0xff, 0, 0, 0xc0); //Color32 red = new Color32(0xff, 0, 0, 0xc0); Color32 blue = new Color32(101, 215, 252, 0xc0); Color32 orange = new Color32(0xff, 0x8c, 0, 0xff); Color32 gold = new Color32(0xff, 0xd7, 0x00, 0xff); Color32 red = new Color32(244, 66, 66, 0xe0); Color32 startColor = red; Color32 endColor = red; // Outer circle ProceduralMeshUtils.DrawArc(verts, triangles, colors, startColor, endColor, innerRadius, outerRadius, 0, 360, segments); // Inner dot //ProceduralMeshUtils.DrawCircle(...); m_mesh.vertices = verts.ToArray(); m_mesh.triangles = triangles.ToArray(); m_mesh.colors32 = colors.ToArray(); m_mesh.RecalculateBounds(); // absolutely needed because Unity may erroneously think we are off-screen at times }
private void GenerateTimer(float radius, float thickness, float pctComplete) { //float thickness = .02f; //float thickness = .0025f; // looks great on actual device at z=2m float innerRadius = radius - 0.5f * thickness; float outerRadius = radius + 0.5f * thickness; int segments = 4; List <Vector3> verts = new List <Vector3>(); List <int> triangles = new List <int>(); List <Color32> colors = new List <Color32>(); Color32 black = new Color32(0xff, 0, 0, 0xc0); //Color32 red = new Color32(0xff, 0, 0, 0xc0); Color32 blue = new Color32(101, 215, 252, 0xc0); Color32 orange = new Color32(0xff, 0x8c, 0, 0xff); Color32 gold = new Color32(0xff, 0xd7, 0x00, 0xff); Color32 red = new Color32(244, 66, 66, 0x20); Color32 startColor = red; Color32 endColor = red; Color32 colorOff = new Color32(244, 66, 66, 0x20); Color32 colorOn = new Color32(244, 66, 66, 0xe0); int numTicks = 16; float tickPitch = 360.0f / numTicks; float tickWidth = tickPitch * 0.9f; float theta = 90f; for (int i = 0; i < numTicks; i++) { float height = 1 - (1 - Mathf.Sin(Mathf.Deg2Rad * theta)) * 0.5f; // how high up from bottom are we? Color32 color = height <= pctComplete ? colorOn : colorOff; ProceduralMeshUtils.DrawArc(verts, triangles, colors, color, color, innerRadius, outerRadius, theta - 0.5f * tickWidth, theta + 0.5f * tickWidth, segments); theta += tickPitch; } m_timerMesh.vertices = verts.ToArray(); m_timerMesh.triangles = triangles.ToArray(); m_timerMesh.colors32 = colors.ToArray(); m_timerMesh.RecalculateBounds(); // absolutely needed because Unity may erroneously think we are off-screen at times }
private void GenerateReticles(float radius, float thickness) { Color32 unusedColor = new Color32(); Mesh mesh = null; List <Vector3> verts = new List <Vector3>(); List <int> triangles = new List <int>(); m_defaultReticle = new GameObject("DefaultReticle"); m_defaultReticle.SetActive(true); m_defaultReticle.transform.parent = transform; m_defaultReticle.transform.localPosition = Vector3.zero; m_defaultReticle.transform.localRotation = Quaternion.identity; m_defaultReticle.AddComponent <MeshRenderer>().sharedMaterial = material; mesh = m_defaultReticle.AddComponent <MeshFilter>().mesh; verts.Clear(); triangles.Clear(); float innerRadius = radius - 0.5f * thickness; float outerRadius = radius + 0.5f * thickness; int segments = 8; ProceduralMeshUtils.DrawArc(verts, triangles, null, unusedColor, unusedColor, innerRadius, outerRadius, 0, 360, segments); mesh.vertices = verts.ToArray(); mesh.triangles = triangles.ToArray(); mesh.RecalculateBounds(); // absolutely needed because Unity may erroneously think we are off-screen at times m_lockedReticle = new GameObject("LockedReticle"); m_lockedReticle.SetActive(false); m_lockedReticle.transform.parent = transform; m_lockedReticle.transform.localPosition = Vector3.zero; m_lockedReticle.transform.localRotation = Quaternion.identity; m_lockedReticle.AddComponent <MeshRenderer>().sharedMaterial = material; mesh = m_lockedReticle.AddComponent <MeshFilter>().mesh; verts.Clear(); triangles.Clear(); ProceduralMeshUtils.DrawQuad(verts, triangles, null, unusedColor, +1 * Vector3.up * radius, thickness, radius); ProceduralMeshUtils.DrawQuad(verts, triangles, null, unusedColor, -1 * Vector3.up * radius, thickness, radius); ProceduralMeshUtils.DrawQuad(verts, triangles, null, unusedColor, +1 * Vector3.right * radius, radius, thickness); ProceduralMeshUtils.DrawQuad(verts, triangles, null, unusedColor, -1 * Vector3.right * radius, radius, thickness); mesh.vertices = verts.ToArray(); mesh.triangles = triangles.ToArray(); mesh.RecalculateBounds(); }