//not in use, but it can be used to make new Mesh public static void GetHexMesh(float radius, GridMetrics.HexOrientation orientation, ref Mesh mesh) { mesh = new Mesh(); List<int> triangles = new List<int> { 0, 2, 1, 0, 5, 2, 2, 5, 3, 3, 5, 4 }; List<Vector3> vertices = new List<Vector3>(); List<Vector2> uvs = new List<Vector2>(); for (int i = 0; i < 6; i++) vertices.Add(Corner(Vector3.zero, radius, i, orientation)); uvs.Add(new Vector2(0.5f, 1f)); uvs.Add(new Vector2(1, 0.75f)); uvs.Add(new Vector2(1, 0.25f)); uvs.Add(new Vector2(0.5f, 0)); uvs.Add(new Vector2(0, 0.25f)); uvs.Add(new Vector2(0, 0.75f)); mesh.vertices = vertices.ToArray(); mesh.triangles = triangles.ToArray(); mesh.uv = uvs.ToArray(); mesh.name = "Hexagonal Plane"; mesh.RecalculateNormals(); //AssetDatabase.CreateAsset(mesh, "Assets/mesh.prefab"); //AssetDatabase.SaveAssets(); //AssetDatabase.Refresh(); }
public static Vector3 Corner(Vector3 origin, float radius, int corner, GridMetrics.HexOrientation orientation) { float angle = 60 * corner; if (orientation == GridMetrics.HexOrientation.Pointy) angle += 30; angle *= Mathf.PI / 180; return new Vector3(origin.x + radius * Mathf.Cos(angle), 0.1f, origin.z + radius * Mathf.Sin(angle)); }