Implemented resource manager which can load textures and levels.
Implemented script to generate Resources.g.h file linking assets to code. Added assets from old project.
This commit is contained in:
9
oldproject/Assets/Scripts/Controller.meta
Executable file
9
oldproject/Assets/Scripts/Controller.meta
Executable file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee8b9a114dfdec440816f9c759dee732
|
||||
folderAsset: yes
|
||||
timeCreated: 1477769888
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
36
oldproject/Assets/Scripts/Controller/PlayerController.cs
Executable file
36
oldproject/Assets/Scripts/Controller/PlayerController.cs
Executable file
@ -0,0 +1,36 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class PlayerController : MonoBehaviour {
|
||||
|
||||
public Camera CameraObject;
|
||||
|
||||
public float MovementDelta;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
// Center camera on player
|
||||
var playerCoords = gameObject.transform.position;
|
||||
CameraObject.transform.position = new Vector3(playerCoords.x, playerCoords.y, CameraObject.transform.position.z);
|
||||
|
||||
// Handle movement keys
|
||||
float deltaX = 0, deltaY = 0;
|
||||
|
||||
if (Input.GetKey(KeyCode.DownArrow))
|
||||
deltaY -= MovementDelta * Time.deltaTime;
|
||||
if (Input.GetKey(KeyCode.UpArrow))
|
||||
deltaY += MovementDelta * Time.deltaTime;
|
||||
if (Input.GetKey(KeyCode.LeftArrow))
|
||||
deltaX -= MovementDelta * Time.deltaTime;
|
||||
if (Input.GetKey(KeyCode.RightArrow))
|
||||
deltaX += MovementDelta * Time.deltaTime;
|
||||
|
||||
gameObject.transform.Translate(deltaX, deltaY, 0);
|
||||
}
|
||||
}
|
12
oldproject/Assets/Scripts/Controller/PlayerController.cs.meta
Executable file
12
oldproject/Assets/Scripts/Controller/PlayerController.cs.meta
Executable file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fbc71aa16ba11f4ca78672f45b0fa09
|
||||
timeCreated: 1477769903
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
56
oldproject/Assets/Scripts/Controller/SceneLoaderController.cs
Executable file
56
oldproject/Assets/Scripts/Controller/SceneLoaderController.cs
Executable file
@ -0,0 +1,56 @@
|
||||
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 () {
|
||||
|
||||
}
|
||||
}
|
12
oldproject/Assets/Scripts/Controller/SceneLoaderController.cs.meta
Executable file
12
oldproject/Assets/Scripts/Controller/SceneLoaderController.cs.meta
Executable file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 598014e699a25e841916d55cd9e865ba
|
||||
timeCreated: 1477757088
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
9
oldproject/Assets/Scripts/Model.meta
Executable file
9
oldproject/Assets/Scripts/Model.meta
Executable file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f1eaad7a6db0740bbf4a937f148ac2
|
||||
folderAsset: yes
|
||||
timeCreated: 1477764951
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
18
oldproject/Assets/Scripts/Model/Layer.cs
Executable file
18
oldproject/Assets/Scripts/Model/Layer.cs
Executable file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Model
|
||||
{
|
||||
public class Layer
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public int Width;
|
||||
public int Height;
|
||||
|
||||
public int[,] Cells;
|
||||
}
|
||||
}
|
12
oldproject/Assets/Scripts/Model/Layer.cs.meta
Executable file
12
oldproject/Assets/Scripts/Model/Layer.cs.meta
Executable file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ece066914ebb15a4eb9364302cc4b0b5
|
||||
timeCreated: 1477767546
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
41
oldproject/Assets/Scripts/Model/Map.cs
Executable file
41
oldproject/Assets/Scripts/Model/Map.cs
Executable file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Model
|
||||
{
|
||||
public class Map
|
||||
{
|
||||
/// <summary>
|
||||
/// The width of the map in tiles
|
||||
/// </summary>
|
||||
public int Width = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The height of the map in tiles
|
||||
/// </summary>
|
||||
public int Height = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The width of a tile in pixels
|
||||
/// </summary>
|
||||
public int TileWidth = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The height of a tile in pixels
|
||||
/// </summary>
|
||||
public int TileHeight = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Loaded tile sets
|
||||
/// </summary>
|
||||
public Dictionary<int, Tile> Tiles = new Dictionary<int, Tile>();
|
||||
|
||||
/// <summary>
|
||||
/// Layers
|
||||
/// </summary>
|
||||
public List<Layer> Layers = new List<Layer>();
|
||||
}
|
||||
}
|
12
oldproject/Assets/Scripts/Model/Map.cs.meta
Executable file
12
oldproject/Assets/Scripts/Model/Map.cs.meta
Executable file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52238496c720c374994d050a357a309c
|
||||
timeCreated: 1477764951
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
15
oldproject/Assets/Scripts/Model/Tile.cs
Executable file
15
oldproject/Assets/Scripts/Model/Tile.cs
Executable file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Model
|
||||
{
|
||||
public class Tile
|
||||
{
|
||||
public string ImageSource;
|
||||
public int Width;
|
||||
public int Height;
|
||||
}
|
||||
}
|
12
oldproject/Assets/Scripts/Model/Tile.cs.meta
Executable file
12
oldproject/Assets/Scripts/Model/Tile.cs.meta
Executable file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0061c920a4f77a46ac2e6cd1174374d
|
||||
timeCreated: 1477767546
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
9
oldproject/Assets/Scripts/Storage.meta
Executable file
9
oldproject/Assets/Scripts/Storage.meta
Executable file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14b09c03a73215240aea60a8ee65c7a2
|
||||
folderAsset: yes
|
||||
timeCreated: 1477767546
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
43
oldproject/Assets/Scripts/Storage/MapLoader.cs
Executable file
43
oldproject/Assets/Scripts/Storage/MapLoader.cs
Executable file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using Model;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Storage
|
||||
{
|
||||
public static class MapLoader
|
||||
{
|
||||
public static void LoadLayer(Map map, string layerName, string dataCsv)
|
||||
{
|
||||
// Process layer attributes
|
||||
Layer layer = new Layer();
|
||||
layer.Name = layerName;
|
||||
|
||||
// Split into substrings
|
||||
string[] dataRows = dataCsv.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
for (int y = 0; y < dataRows.Length; y++)
|
||||
{
|
||||
string[] dataRowItems = dataRows[y].Trim().Split(',');
|
||||
|
||||
// Allocate cells
|
||||
if (y == 0)
|
||||
{
|
||||
layer.Cells = new int[dataRows.Length, dataRowItems.Length];
|
||||
layer.Width = dataRowItems.Length;
|
||||
layer.Height = dataRows.Length;
|
||||
}
|
||||
|
||||
// Set cells
|
||||
for (int x = 0; x < layer.Width; x++)
|
||||
layer.Cells[y, x] = Int32.Parse(dataRowItems[x]);
|
||||
}
|
||||
|
||||
// Add layer
|
||||
map.Layers.Add(layer);
|
||||
}
|
||||
}
|
||||
}
|
12
oldproject/Assets/Scripts/Storage/MapLoader.cs.meta
Executable file
12
oldproject/Assets/Scripts/Storage/MapLoader.cs.meta
Executable file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c11a44a1418f7c4bbfbd9f82893e900
|
||||
timeCreated: 1477767546
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user