Commit 7467a90a authored by 16도재형's avatar 16도재형

One small step for development, one giant leap for view (+ class name prefix deleted)

parent 0fe1b657
......@@ -13533,8 +13533,8 @@ Camera:
m_GameObject: {fileID: 1006940696}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_ClearFlags: 2
m_BackGroundColor: {r: 0.30882353, g: 0.30882353, b: 0.30882353, a: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
......@@ -14237,8 +14237,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
outerRadius: 1
innerRadius: 0
width: 80
height: 20
cellPrefab: {fileID: 1839775916168536, guid: 900341537233caf489d432cff5440dd3, type: 2}
--- !u!4 &1056054509
Transform:
......
public class GameInfo
{
public static int numOfPlayer = 2;
public static int mapWidth = 128;
public static int mapHeight = 80;
}
fileFormatVersion: 2
guid: f45b933381dfc084b952dec401c8cb52
timeCreated: 1518375411
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -4,33 +4,56 @@ using UnityEngine;
using CivModel;
using CivModel.Common;
public class CIVGameManager : MonoBehaviour {
public float outerRadius;
public float innerRadius;
public class GameManager : MonoBehaviour {
private static GameManager _manager = null;
public static GameManager I { get { return _manager; } }
public int width = 80;
public int height = 20;
// Current game
private CivModel.Game _game;
// Currently playing country
public float outerRadius = 1f; // Outer&inner radius of hex tile.
public float innerRadius; // These variables can be deleted if there are no use.
public GameObject cellPrefab;
private GameObject[,] _cells;
// Use this for initialization
void Start() {
// Singleton
if (_manager != null)
{
Destroy(gameObject);
return;
}
else
{
_manager = this;
}
// Use this when scene changing exists
// DontDestroyOnLoad(gameObject);
// Instantiate game instance
_game = new CivModel.Game( GameInfo.mapWidth, GameInfo.mapHeight, GameInfo.numOfPlayer, new CivModel.Common.GameSchemeFactory());
// Map tiling
innerRadius = outerRadius * Mathf.Sqrt(3.0f) / 2;
_cells = new GameObject[width, height];
_cells = new GameObject[GameInfo.mapWidth, GameInfo.mapHeight];
DrawMap();
}
// Update is called once per frame
void Update() {
RenderTile(_game.Terrain);
}
void DrawMap() // Draw hexagonal tile map
void DrawMap() // Instantiate hex tiles
{
for (int i = 0; i < width; i++)
for (int i = 0; i < GameInfo.mapWidth; i++)
{
for (int j = 0; j < height; j++)
for (int j = 0; j < GameInfo.mapHeight; j++)
{
Vector3 pos = new Vector3(2 * i * innerRadius, -0.05f, -j * outerRadius * 1.5f);
if (j % 2 != 0)
......@@ -42,4 +65,20 @@ public class CIVGameManager : MonoBehaviour {
}
}
}
// Read game terrain and update hex tile resource
void RenderTile(CivModel.Terrain terrain)
{
for (int i = 0; i < terrain.Width; i++)
{
for (int j = 0; j < terrain.Height; j++)
{
CivModel.Terrain.Point point = terrain.GetPoint(i, j);
// TODO: Make prefab component
// _cells[i, j].GetComponent<TilePrefab>().ChangeTile(point);
// _cells[i, j].GetComponent<TilePrefab>().BuildDistrict(point.TileBuilding);
// _cells[i, j].GetComponent<TilePrefab>().DrawUnit(point.Unit);
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment