GetCellPoints()
Gets the points which outline a cell of the GridLayout.
阅读时间1 分钟最后更新于 1 个月前
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.GridModule
public ReadOnlySpan<Vector3> GetCellPoints()
Returns
Type | Description |
|---|---|
| ReadOnlySpan<Vector3> | The points which outline a cell, in cell space. |
Remarks
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.
Examples
// Draw the outline of the cell at the originusing 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)); } }}