Commit 2e0a2048 authored by 16도재형's avatar 16도재형

Now we can select unit

parent a6b2fdb6
......@@ -40,6 +40,7 @@ GameObject:
- component: {fileID: 33382563896309128}
- component: {fileID: 23842930406273546}
- component: {fileID: 114528188812766900}
- component: {fileID: 64357967316059052}
m_Layer: 0
m_Name: hextile 1
m_TagString: Untagged
......@@ -229,6 +230,20 @@ MeshFilter:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1823159130722898}
m_Mesh: {fileID: 4300000, guid: 93b23d960c7fd2645bed567627e2e6db, type: 3}
--- !u!64 &64357967316059052
MeshCollider:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1823159130722898}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 3
m_Convex: 1
m_CookingOptions: 14
m_SkinWidth: 0.01
m_Mesh: {fileID: 4300000, guid: 93b23d960c7fd2645bed567627e2e6db, type: 3}
--- !u!65 &65133615766084452
BoxCollider:
m_ObjectHideFlags: 1
......@@ -237,7 +252,7 @@ BoxCollider:
m_GameObject: {fileID: 1864306018844118}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Enabled: 0
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
......@@ -249,7 +264,7 @@ BoxCollider:
m_GameObject: {fileID: 1187391223902348}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Enabled: 0
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
......
......@@ -11875,7 +11875,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0}
m_AnchorMax: {x: 0.5, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_SizeDelta: {x: 250, y: 90}
m_Pivot: {x: 0.5, y: 0}
--- !u!114 &863695363
MonoBehaviour:
......@@ -14492,7 +14492,7 @@ RectTransform:
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 20, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
......@@ -20689,7 +20689,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &1558743810
RectTransform:
m_ObjectHideFlags: 0
......@@ -24158,7 +24158,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &1831636215
RectTransform:
m_ObjectHideFlags: 0
......
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using CivModel;
using CivModel.Common;
......@@ -18,8 +21,12 @@ public class GameManager : MonoBehaviour {
// Current game
private CivModel.Game _game;
// Selected unit
private CivModel.Unit _currentUnit;
// Selected actor
private CivModel.Unit _selectedActor = null;
public bool IsThereTodos;
private CivModel.Unit[] _standbyUnits;
private int _standbyUnitIndex;
public float outerRadius = 1f; // Outer&inner radius of hex tile.
public float innerRadius; // These variables can be deleted if there are no use.
......@@ -54,6 +61,20 @@ public class GameManager : MonoBehaviour {
void Update() {
Render(_game.Terrain);
if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Unit unit = hit.collider.gameObject.GetComponent<HexTile>().point.Unit;
if (unit != null)
{
SelectUnit(unit);
}
}
}
// Camera movement
Vector3 mousePos = Input.mousePosition;
if (mousePos.x < 10)
......@@ -72,11 +93,10 @@ public class GameManager : MonoBehaviour {
{
CameraMove(CameraMoveDirection.Up);
}
Debug.Log("width, height: " + Screen.width + ", " + Screen.height);
Debug.Log(Input.mousePosition);
}
void DrawMap() // Instantiate hex tiles
// Instantiate hex tiles
void DrawMap()
{
_cells = new GameObject[GameInfo.mapWidth, GameInfo.mapHeight];
......@@ -91,6 +111,7 @@ public class GameManager : MonoBehaviour {
}
_cells[i, j] = Instantiate(cellPrefab, pos, Quaternion.identity);
_cells[i, j].name = Pos2Str(i, j);
_cells[i, j].GetComponent<HexTile>().point = _game.Terrain.GetPoint(i, j);
}
}
}
......@@ -111,7 +132,61 @@ public class GameManager : MonoBehaviour {
}
}
// Make unit array and iterate while all units consume all AP
// From Presenter.cs
void SelectNextUnit()
{
int tryNumber = (_standbyUnitIndex == -1) ? 1 : 2;
for (int j = 0; j < tryNumber; ++j)
{
if (_standbyUnitIndex == -1)
{
_standbyUnits = _game.PlayerInTurn.Units.ToArray();
}
int idx = _standbyUnitIndex + 1;
for (; idx < _standbyUnits.Length; ++idx)
{
var unit = _standbyUnits[idx];
if (unit.RemainAP > 0 && !unit.SkipFlag && unit.PlacedPoint.HasValue)
{
_standbyUnitIndex = idx;
_selectedActor = _standbyUnits[idx];
IsThereTodos = true;
Focus();
return;
}
}
_selectedActor = null;
_standbyUnitIndex = -1;
IsThereTodos = false;
}
}
void SelectUnit(Unit unit)
{
Debug.Log(unit.ToString() + " selected");
var units = _game.PlayerInTurn.Units.ToArray();
int idx = Array.IndexOf(units, unit);
if (idx == -1)
return;
_selectedActor = unit;
unit.SkipFlag = false;
_standbyUnits = units;
_standbyUnitIndex = idx;
IsThereTodos = true;
Focus();
}
// Camera focus
void Focus()
{
Focus(_selectedActor);
}
void Focus(CivModel.Unit unit)
{
if (unit == null)
......@@ -140,6 +215,7 @@ public class GameManager : MonoBehaviour {
return "(" + x + "," + y + ")";
}
// Camera move
void CameraMove(CameraMoveDirection moveDirection)
{
switch (moveDirection)
......
......@@ -5,10 +5,11 @@ using CivModel;
using CivModel.Common;
public class HexTile : MonoBehaviour {
public CivModel.Terrain.Point point;
// Use this for initialization
void Start () {
}
// Update is called once per frame
......@@ -16,14 +17,14 @@ public class HexTile : MonoBehaviour {
}
// This method should be changed when
// This method should be changed when unit type increses
public void DrawUnit(CivModel.Unit unit)
{
if (unit == null)
{
foreach(Transform child in transform)
{
child.gameObject.GetComponent<MeshRenderer>().enabled = false;
child.gameObject.GetComponent<Renderer>().enabled = false;
}
}
else
......@@ -32,11 +33,11 @@ public class HexTile : MonoBehaviour {
{
if (child.gameObject.name == "Pioneer")
{
child.gameObject.GetComponent<MeshRenderer>().enabled = true;
child.gameObject.GetComponent<Renderer>().enabled = true;
}
else
{
child.gameObject.GetComponent<MeshRenderer>().enabled = false;
child.gameObject.GetComponent<Renderer>().enabled = false;
}
}
}
......
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