Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

GridLayout.GetCellPoints

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public ReadOnlySpan<Vector3> GetCellPoints();

Returns

ReadOnlySpan<Vector3> The points which outline a cell, in cell space.

Description

Gets the points which outline a cell of the GridLayout.

The points are in cell space, so they describe a cell before GridLayout.cellSize is applied. Scale them by GridLayout.cellSize for the shape of a cell, then Grid.Swizzle that by Grid.cellSwizzle and offset it by GridLayout.CellToLocal to place it on a given cell. They trace the cell's outline clockwise, so consecutive points are the cell's edges. The same points serve every cell of the GridLayout, so they are read straight from the engine and nothing is copied or allocated.

 // Draw the outline of the cell at the origin
using System;
using UnityEngine;

public class ExampleClass : MonoBehaviour { void OnDrawGizmos() { Grid grid = GetComponent<Grid>(); ReadOnlySpan<Vector3> points = grid.GetCellPoints(); Vector3 origin = grid.CellToLocal(Vector3Int.zero); for (int i = 0; i < points.Length; ++i) { Vector3 from = origin + Grid.Swizzle(grid.cellSwizzle, Vector3.Scale(points[i], grid.cellSize)); Vector3 to = origin + Grid.Swizzle(grid.cellSwizzle, Vector3.Scale(points[(i + 1) % points.Length], grid.cellSize)); Gizmos.DrawLine(grid.LocalToWorld(from), grid.LocalToWorld(to)); } } }