Exemplo n.º 1
0
        /// <summary>
        /// Debug a hexagon grid.
        /// </summary>
        /// <param name="grid">The grid to debug.</param>
        /// <param name="color"> The color of the grid.</param>
        /// <param name="offset_grid_y"> The offset of y position. </param>
        /// <param name="size_grid">The size of the grid.</param>
        private static void DebugHexagonGrid(Grid3D grid, Color color, int offset_grid_y = 0, int size_grid = 10)
        {
            using (new Handles.DrawingScope(color))
            {
                Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                Vector3 pos      = grid.transform.position;
                float   CaseSize = grid.SizeCell * grid.GapRatio;
                pos.y += offset_grid_y - CaseSize / 2.0f;

                List <Vector3> axes     = grid.GetAxes();
                float          angle_xz = Vector3.Angle(axes[2], axes[0]) / 2;

                //Form
                Vector3[] form = new Vector3[7];
                int       p    = 0;
                for (int i = 0; i < axes.Count * 3; i += 3)
                {
                    if (axes[i % axes.Count].y == 0)
                    {
                        form[p] = pos + Quaternion.AngleAxis(angle_xz, axes[1]) * (axes[i % axes.Count] * CaseSize / 2.0f);
                        p++;
                    }
                }
                form[p] = form[0];

                //Grid
                for (int z = -size_grid; z <= size_grid; z++)
                {
                    for (int x = -size_grid; x <= size_grid; x++)
                    {
                        Vector3 cellpos = (axes[0] * x + axes[2] * z) * CaseSize;

                        Vector3[] points = new Vector3[7];
                        for (int i = 0; i < 7; i++)
                        {
                            points[i] = cellpos + form[i];
                        }
                        Handles.DrawPolyLine(points);
                    }
                }
            }
        }