public static SMBTileMap ParseTileMap(string filename) { TextAsset levelfile = Resources.Load <TextAsset> (filename); SMBTileMap tileMap = JsonUtility.FromJson <SMBTileMap>(levelfile.text); // In the json file, size is in pixels, here we converting it to units // (1 pixel = 100 units) tileMap.size *= 0.01f; return(tileMap); }
// Use this for initialization void Start() { SMBTileMap tileMap = SMBLevelParser.ParseTileMap(SMBConstants.tilesDescrition); if (tileMap == null) { return; } TileSize = tileMap.size; TileMap = new Dictionary <string, SMBTile>(); foreach (SMBTile tile in tileMap.tiles) { TileMap [tile.id] = tile; } Level = SMBLevelParser.ParseLevel(SMBConstants.levelFilename); if (Level == null) { return; } // Level parents object _levelParent = new GameObject(); _levelParent.name = "LevelTiles"; _levelParent.transform.parent = transform.parent; if (!isLevelValid()) { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif return; } InstantiateLevel(); // Camera follow player _camera = FindObjectOfType <SMBCamera>(); if (_camera == null) { return; } _camera.player = _player; // Set Camera position to the players poitions _camera.SetCameraPos(_player.transform.position); // Set camera locking positions int levelWidth = Level.GetLength(1); int levelHeight = Level.GetLength(0); LockLeftX = TileSize * 0.5f; LockRightX = ((float)levelWidth - 1.5f) * TileSize; LockDownY = -TileSize * 0.5f; LockUpY = ((float)levelHeight + 0.5f) * TileSize; }