예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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");
            }
        }
예제 #3
0
        public static Type GetTypeGrid(this TypeGrid3D typegrid)
        {
            switch (typegrid)
            {
            case TypeGrid3D.Cube:
                return(typeof(CubeGrid));

            case TypeGrid3D.Hexagonal:
                return(typeof(HexagonalGrid));

            default:
                break;
            }
            throw new ArgumentException("Type is not implemented.");
        }
예제 #4
0
        public Grid3DDTO(Grid3D grid)
        {
            _type      = grid.GetTypeGrid();
            _name      = grid.name;
            _size_cell = grid.SizeCell;
            _gap       = grid.GapRatio;

            _map = new List <CellDTO>();
            Dictionary <Vector3Int, Cell> .Enumerator it = grid.GetEnumerator();
            while (it.MoveNext())
            {
                CellDTO dtocell = new CellDTO(it.Current.Value);
                _map.Add(dtocell);
            }
        }
예제 #5
0
 public static string[] GetTypesGrid(this TypeGrid3D typegrid)
 {
     return(new string[] { "Cube", "Hexagonal" });
 }