public BoardObject CreateBoardObjectAt(Vector2Int pos, Type type) { //find model if (!type.IsSubclassOf(typeof(BoardObject))) { return(null); } TileSet.Piece piece; if (tileSet != null) { piece = tileSet.FindPieceFromType(type); } else { return(null); } if (piece == null) { Debug.LogError("Tileset does not contain type \"" + type.ToString() + '"'); return(null); } if (piece.Tile == null) { Debug.LogError("Tileset does not contain type \"" + type.ToString() + '"'); return(null); } //instantiate model GameObject newBoardObject = UnityEditor.PrefabUtility.InstantiatePrefab(piece.Tile) as GameObject; //configure gameobject newBoardObject.name = "Board Object (" + pos.x + "," + pos.y + ")"; newBoardObject.transform.SetParent(transform); //configure boardobject BoardObject boardObject = newBoardObject.GetComponent <BoardObject>(); boardObject.TileSetPiece = piece; if (!boardObject) { DestroyImmediate(newBoardObject); Debug.LogError("Board object prefab does not contain a board object script"); return(null); } //orient gameObject newBoardObject.transform.position = new Vector3(pos.x, 0, pos.y); newBoardObject.transform.rotation = Quaternion.Euler(0, (-90 * (int)piece.modelOrientation) + 90 * (int)boardObject.Orientation, 0); boardObject.Refresh(); return(boardObject); }