/// <summary> /// IUnstantiate an empty Grid3D. /// </summary> /// <param name="typegrid">The type of the grid.</param> /// <returns>The grid component associated to the gameobject.</returns> public static Grid3D InstantiateGrid3D(TypeGrid3D typegrid) { GameObject obj; Grid3D grid; switch (typegrid) { case TypeGrid3D.Cube: { obj = new GameObject("CubeGrid"); grid = obj.AddComponent <CubeGrid>(); } break; case TypeGrid3D.Hexagonal: { obj = new GameObject("HexagonalGrid"); grid = obj.AddComponent <HexagonalGrid>(); } break; default: throw new ArgumentException("No type implemented " + typegrid.ToString() + " inherit Grid3D"); } grid.Initialize(); Undo.RegisterCreatedObjectUndo(grid.gameObject, "Grid created"); return(grid); }
/// <summary> /// Gizmo for debuging a cell. /// </summary> /// <param name="index">The index of the cell.</param> /// <param name="grid">The grid it belongs</param> /// <param name="color">Color of the gizmo.</param> /// <param name="offsetSize"> The scale amount add to the grid size cell.</param> public static void DebugCell(Vector3Int index, Grid3D grid, Color color, float offsetSize = 0.01f) { if (grid == null) { return; } Gizmos.color = color; TypeGrid3D typegrid = grid.GetTypeGrid(); switch (typegrid) { case TypeGrid3D.Cube: { Gizmos.DrawWireCube(grid.GetPositionCell(index), Vector3.one * (grid.SizeCell + offsetSize)); } break; case TypeGrid3D.Hexagonal: { Gizmos.DrawMesh(ProceduralMesh.GetHexagonMesh(), grid.GetPositionCell(index), Quaternion.identity, Vector3.one * (grid.SizeCell + offsetSize)); } break; default: throw new ArgumentException("No type implemented " + typegrid.ToString() + " inherit Grid3D"); } }