//Width = radius //Height = angleSecPerRadiusSec //gridSize = radiusSize public RadialGrid2D(int radiusSec, int angleSecPerRadiusSec, float radiusSize, Vector3 originPos, PositionSpace positionSpace, Transform parent) : base(radiusSec, angleSecPerRadiusSec, radiusSize, originPos, positionSpace) { int total = 1; for (int i = 1; i < Width; i++) { total += i * Height; } grid = new TGridObject[total]; gridText = new TextMeshPro[total]; for (int currRadiusSec = 0; currRadiusSec < Width; ++currRadiusSec) { int numOfSec = currRadiusSec == 0 ? 1 : currRadiusSec * Height; int startOfSec = SectionToIndex(currRadiusSec, 1); for (int currAngleSec = 0; currAngleSec < numOfSec; ++currAngleSec) { int index = startOfSec + currAngleSec; grid[index] = default; Vector3 gridPos = currRadiusSec == 0 ? gridPos = Vector3.zero + originPos : GridToWorldPos(currRadiusSec, currAngleSec); gridText[index] = UtilityClass.CreateWorldText(grid[index].ToString(), Color.white, parent, gridPos + CenterOffset(currRadiusSec, currAngleSec, gridPos), (int)gridSize.x * 10, TextAlignmentOptions.Center, 0); } } }
public Grid2D(int width, int height, float gridSize, Vector3 originPos, PositionSpace positionSpace, Transform parent) : base(width, height, gridSize, originPos, positionSpace) { grid = new TGridObject[Width, Height]; gridText = new TextMeshPro[Width, Height]; for (int horizontal = 0; horizontal < Width; ++horizontal) { for (int vertical = 0; vertical < Height; ++vertical) { grid[horizontal, vertical] = default; gridText[horizontal, vertical] = UtilityClass.CreateWorldText(grid[horizontal, vertical].ToString(), Color.white, parent, GridToWorldPos(horizontal, vertical) + this.gridSize * .5f, 10, TextAlignmentOptions.Center, 0); Debug.DrawLine(GridToWorldPos(horizontal, vertical), GridToWorldPos(horizontal + 1, vertical), Color.white, 100f); Debug.DrawLine(GridToWorldPos(horizontal, vertical), GridToWorldPos(horizontal, vertical + 1), Color.white, 100f); } } Debug.DrawLine(GridToWorldPos(0, Height), GridToWorldPos(Width, Height), Color.white, 100f); Debug.DrawLine(GridToWorldPos(Width, 0), GridToWorldPos(Width, Height), Color.white, 100f); }