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: ...@@ -13533,8 +13533,8 @@ Camera:
m_GameObject: {fileID: 1006940696} m_GameObject: {fileID: 1006940696}
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_ClearFlags: 1 m_ClearFlags: 2
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} m_BackGroundColor: {r: 0.30882353, g: 0.30882353, b: 0.30882353, a: 0}
m_NormalizedViewPortRect: m_NormalizedViewPortRect:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 0
...@@ -14237,8 +14237,6 @@ MonoBehaviour: ...@@ -14237,8 +14237,6 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
outerRadius: 1 outerRadius: 1
innerRadius: 0 innerRadius: 0
width: 80
height: 20
cellPrefab: {fileID: 1839775916168536, guid: 900341537233caf489d432cff5440dd3, type: 2} cellPrefab: {fileID: 1839775916168536, guid: 900341537233caf489d432cff5440dd3, type: 2}
--- !u!4 &1056054509 --- !u!4 &1056054509
Transform: 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; ...@@ -4,33 +4,56 @@ using UnityEngine;
using CivModel; using CivModel;
using CivModel.Common; using CivModel.Common;
public class CIVGameManager : MonoBehaviour { public class GameManager : MonoBehaviour {
public float outerRadius; private static GameManager _manager = null;
public float innerRadius; public static GameManager I { get { return _manager; } }
public int width = 80; // Current game
public int height = 20; 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; public GameObject cellPrefab;
private GameObject[,] _cells; private GameObject[,] _cells;
// Use this for initialization // Use this for initialization
void Start() { 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; innerRadius = outerRadius * Mathf.Sqrt(3.0f) / 2;
_cells = new GameObject[width, height]; _cells = new GameObject[GameInfo.mapWidth, GameInfo.mapHeight];
DrawMap(); DrawMap();
} }
// Update is called once per frame // Update is called once per frame
void Update() { 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); Vector3 pos = new Vector3(2 * i * innerRadius, -0.05f, -j * outerRadius * 1.5f);
if (j % 2 != 0) if (j % 2 != 0)
...@@ -42,4 +65,20 @@ public class CIVGameManager : MonoBehaviour { ...@@ -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