Tiberiu Chibici
914ae0de0d
Implemented script to generate Resources.g.h file linking assets to code. Added assets from old project.
57 lines
1.6 KiB
C#
Executable File
57 lines
1.6 KiB
C#
Executable File
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Xml.Linq;
|
|
using Model;
|
|
using Storage;
|
|
using System.IO;
|
|
|
|
public class SceneLoaderController : MonoBehaviour {
|
|
|
|
public TextAsset BackgroundLayer;
|
|
public Sprite[] BackgroundTileSet;
|
|
|
|
private Map map;
|
|
|
|
private void LoadScene(Map map)
|
|
{
|
|
// Spawn objects
|
|
foreach (var layer in map.Layers)
|
|
{
|
|
GameObject layerObject = new GameObject(layer.Name);
|
|
|
|
for (int y = 0; y < layer.Height; y++)
|
|
for (int x = 0; x < layer.Width; x++)
|
|
{
|
|
// Obtain tile
|
|
int tileId = layer.Cells[y, x];
|
|
if (tileId >= 0)
|
|
{
|
|
// Spawn tile
|
|
GameObject tileObject = new GameObject(string.Format("{0}{1}{2}", layer.Name, x, y));
|
|
tileObject.transform.parent = layerObject.transform;
|
|
tileObject.transform.localPosition = new Vector3(x, -y, 0);
|
|
|
|
var spriteRenderer = tileObject.AddComponent<SpriteRenderer>();
|
|
spriteRenderer.sprite = BackgroundTileSet[tileId];
|
|
spriteRenderer.sortingLayerName = layer.Name;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Use this for initialization
|
|
void Start ()
|
|
{
|
|
// Load map
|
|
map = new Map();
|
|
MapLoader.LoadLayer(map, "Background", BackgroundLayer.text);
|
|
|
|
LoadScene(map);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
|
|
}
|
|
}
|