Commit 61a58c6a authored by 16도재형's avatar 16도재형

Camera zoom works (This and previous commits are about #7)

parent a370fe31
...@@ -14236,7 +14236,8 @@ MonoBehaviour: ...@@ -14236,7 +14236,8 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
mainCamera: {fileID: 1006940699} mainCamera: {fileID: 1006940699}
cameraMoveSpeed: 3 cameraMoveSpeed: 4
cameraZoomSpeed: 6
outerRadius: 1 outerRadius: 1
innerRadius: 0 innerRadius: 0
cellPrefab: {fileID: 1823159130722898, guid: ef12b8f6d512e104b979d4a75f3e60c0, type: 2} cellPrefab: {fileID: 1823159130722898, guid: ef12b8f6d512e104b979d4a75f3e60c0, type: 2}
......
...@@ -14,17 +14,19 @@ public class GameManager : MonoBehaviour { ...@@ -14,17 +14,19 @@ public class GameManager : MonoBehaviour {
// Main Camera for Focus() // Main Camera for Focus()
[SerializeField] [SerializeField]
Camera mainCamera; Camera mainCamera;
// Camera move speed // For camera controll
[SerializeField] [SerializeField]
float cameraMoveSpeed; float cameraMoveSpeed;
enum CameraMoveDirection { Up, Down, Left, Right } [SerializeField]
float cameraZoomSpeed;
// For drawing hex tile // For drawing hex tile
public float outerRadius = 1f; // Outer&inner radius of hex tile. public float outerRadius = 1f; // Outer&inner radius of hex tile.
public float innerRadius; // These variables can be deleted if there are no use. public float innerRadius; // These variables can be deleted if there are no use.
// Hex tile cells // Hex tile cells
public GameObject cellPrefab; [SerializeField]
GameObject cellPrefab;
private GameObject[,] _cells; private GameObject[,] _cells;
// Current game // Current game
...@@ -104,25 +106,38 @@ public class GameManager : MonoBehaviour { ...@@ -104,25 +106,38 @@ public class GameManager : MonoBehaviour {
} }
} }
} }
// Camera movement // Camera movement
Vector3 mousePos = Input.mousePosition; Vector3 mousePos = Input.mousePosition;
if (mousePos.x < 10) if (mousePos.x < 10)
{ {
CameraMove(CameraMoveDirection.Left); CameraMove(Vector3.left);
} }
else if (mousePos.x > Screen.width - 10) else if (mousePos.x > Screen.width - 10)
{ {
CameraMove(CameraMoveDirection.Right); CameraMove(Vector3.right);
} }
if (mousePos.y < 10) if (mousePos.y < 10)
{ {
CameraMove(CameraMoveDirection.Down); CameraMove(Vector3.back);
} }
else if (mousePos.y > Screen.height - 10) else if (mousePos.y > Screen.height - 10)
{ {
CameraMove(CameraMoveDirection.Up); CameraMove(Vector3.forward);
} }
}
CameraZoom();
}
// Method that gives "(x,y)" string with input of CivModel.Position or 2 ints
public string Pos2Str(CivModel.Position pos)
{
return Pos2Str(pos.X, pos.Y);
}
public string Pos2Str(int x, int y)
{
return "(" + x + "," + y + ")";
}
// Instantiate hex tiles // Instantiate hex tiles
void DrawMap() void DrawMap()
...@@ -237,35 +252,17 @@ public class GameManager : MonoBehaviour { ...@@ -237,35 +252,17 @@ public class GameManager : MonoBehaviour {
mainCamera.transform.position = new Vector3(x, 6.75f, z); mainCamera.transform.position = new Vector3(x, 6.75f, z);
} }
// Method that gives "(x,y)" string with input of CivModel.Position or 2 ints // Camera controllings
public string Pos2Str(CivModel.Position pos) void CameraMove(Vector3 vec)
{ {
return Pos2Str(pos.X, pos.Y); mainCamera.transform.Translate(vec * cameraMoveSpeed * Time.deltaTime, Space.World);
} }
public string Pos2Str(int x, int y) void CameraZoom()
{ {
return "(" + x + "," + y + ")"; Vector2 vec2 = Input.mouseScrollDelta;
} Vector3 vec3 = new Vector3(vec2.x, 0, vec2.y);
mainCamera.transform.Translate(vec3 * cameraZoomSpeed * Time.deltaTime, Space.Self);
// Camera move }
void CameraMove(CameraMoveDirection moveDirection)
{
switch (moveDirection)
{
case CameraMoveDirection.Up:
mainCamera.transform.Translate(Vector3.forward * cameraMoveSpeed * Time.deltaTime, Space.World);
break;
case CameraMoveDirection.Down:
mainCamera.transform.Translate(Vector3.back * cameraMoveSpeed * Time.deltaTime, Space.World);
break;
case CameraMoveDirection.Left:
mainCamera.transform.Translate(Vector3.left * cameraMoveSpeed * Time.deltaTime, Space.World);
break;
case CameraMoveDirection.Right:
mainCamera.transform.Translate(Vector3.right * cameraMoveSpeed * Time.deltaTime, Space.World);
break;
}
}
// For state change of pseudo-FSM // For state change of pseudo-FSM
// There are enter, exit methods for move and attack states. Enter methods are public, exit methods are default. // There are enter, exit methods for move and attack states. Enter methods are public, exit methods are default.
......
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