Commit 457b45a7 authored by 18손재민's avatar 18손재민

카메라 조작감 개선 WIP

parent 3711a2a4
......@@ -10,24 +10,27 @@ public class CameraController : MonoBehaviour {
/// Coroutine controls scene changing.
/// </summary>
public static Coroutine sceneChanger;
/// <summary>
/// Check if scene is changing now.
/// </summary>
public static bool isSceneChanging = false;
/// <summary>
/// Coroutine controls room fade in when camera zoom in.
/// </summary>
Coroutine fadeIn;
/// <summary>
/// Coroutine controls room fade out when camera zoom out.
/// </summary>
Coroutine fadeOut;
/*
* If camera is in Tetris view, ideal position is (108, 240, -1)
* size 300
* */
readonly float camX = 9.5f;
readonly float camY = 4f;
public Vector3 tetrisCameraCoord = new Vector3(108, 240, -1);
public Vector3 originPos;
public const float tetrisCameraSize = 300f;
public const float inGameCameraSize = 4.5f;
GameManager.GameState lastGameState;
Vector3 destination;
private void Awake()
{
mapManager = GameObject.Find("MapManager").GetComponent<MapManager>();
......@@ -36,48 +39,56 @@ public class CameraController : MonoBehaviour {
// Use this for initialization
void Start()
{
lastGameState = GameManager.GameState.Ingame;
destination = transform.position;
}
// Update is called once per frame
void Update()
{
ChangeState();
GotoDestination();
if(GameManager.gameState == GameManager.GameState.Ingame)
if (GameManager.gameState == GameManager.GameState.Ingame)
originPos = player.transform.position + new Vector3(0, 0, -1);
else if (GameManager.gameState == GameManager.GameState.Tetris)
originPos = tetrisCameraCoord;
}
public IEnumerator CameraShake(float _amount)
{
float amount = _amount;
while (amount > 0)
{
MapManager.originPos = transform.position;
transform.position = new Vector3(0.2f * Random.insideUnitCircle.x * amount * GetComponent<Camera>().orthographicSize + originPos.x,
Random.insideUnitCircle.y * amount * GetComponent<Camera>().orthographicSize + originPos.y, originPos.z);
amount -= _amount / 40;
yield return null;
}
transform.localPosition = originPos;
}
IEnumerator ChangeScene(Vector3 cameraDestination, float sizeDestination, GameManager.GameState _gameState)
public IEnumerator ChangeScene(GameManager.GameState _gameState)
{
GameObject grid = GameObject.Find("Grid");
float sizeDestination = 0;
isSceneChanging = true;
if (fadeIn != null)
StopCoroutine(fadeIn);
if (fadeOut != null)
StopCoroutine(fadeOut);
if(GameManager.gameState == GameManager.GameState.Ingame)
if (_gameState == GameManager.GameState.Ingame)
{
fadeIn = StartCoroutine(mapManager.RoomFadeIn(MapManager.currentRoom));
StartCoroutine(mapManager.RoomFadeIn(MapManager.currentRoom));
grid.transform.position = new Vector3(0, 0, 0);
sizeDestination = inGameCameraSize;
}
else if(GameManager.gameState == GameManager.GameState.Tetris)
else if (_gameState == GameManager.GameState.Tetris)
{
fadeOut = StartCoroutine(mapManager.RoomFadeOut(MapManager.currentRoom));
StartCoroutine(mapManager.RoomFadeOut(MapManager.currentRoom));
grid.transform.position = new Vector3(0, 0, 2);
sizeDestination = tetrisCameraSize;
}
while ((_gameState == GameManager.GameState.Tetris && GetComponent<Camera>().orthographicSize < sizeDestination - 1) || (_gameState == GameManager.GameState.Ingame && GetComponent<Camera>().orthographicSize > sizeDestination + 0.0001))
while ((_gameState == GameManager.GameState.Tetris && GetComponent<Camera>().orthographicSize < sizeDestination - 5) || (_gameState == GameManager.GameState.Ingame && GetComponent<Camera>().orthographicSize > sizeDestination + 0.05))
{
yield return new WaitForSeconds(0.01f);
Vector2 coord = Vector2.Lerp(transform.position, cameraDestination, Mathf.Sqrt(Time.deltaTime));
yield return null;
Vector2 coord = Vector2.Lerp(transform.position, originPos, Mathf.Sqrt(Time.deltaTime));
transform.position = new Vector3(coord.x, coord.y, -1);
GetComponent<Camera>().orthographicSize = Mathf.Lerp(GetComponent<Camera>().orthographicSize, sizeDestination, Mathf.Sqrt(Time.deltaTime));
MapManager.originPos = transform.position;
}
transform.position = cameraDestination;
transform.position = originPos;
GetComponent<Camera>().orthographicSize = sizeDestination;
isSceneChanging = false;
}
......@@ -138,10 +149,10 @@ public class CameraController : MonoBehaviour {
transform.position = Vector3.Lerp(transform.position, new Vector3(posx, posy, -1), 2f * Time.deltaTime);
transform.position = new Vector3(transform.position.x, transform.position.y, -1); //카메라를 원래 z축으로 이동
}
/*else if(MapManager.isRoomFalling == true)
else if(MapManager.isRoomFalling == true)
{
transform.position = player.transform.position + new Vector3(0, 0.2f, -1);
}*/
}
}
// Camera.main.transform.position = new Vector3(posx, posy, -10);
}
......@@ -189,28 +200,4 @@ public class CameraController : MonoBehaviour {
return -1;
}
public void ChangeState()
{
if (Input.GetKeyDown(KeyCode.Tab))
{
Vector3 cameraDestination = new Vector3(0, 0, 0);
float sizeDestination = 0f;
if (GameManager.gameState == GameManager.GameState.Ingame)
{
cameraDestination = tetrisCameraCoord;
sizeDestination = tetrisCameraSize;
GameManager.gameState = GameManager.GameState.Tetris;
}
else if (GameManager.gameState == GameManager.GameState.Tetris)
{
cameraDestination = player.transform.position;
sizeDestination = inGameCameraSize;
GameManager.gameState = GameManager.GameState.Ingame;
}
if (sceneChanger != null)
StopCoroutine(sceneChanger);
sceneChanger = StartCoroutine(ChangeScene(cameraDestination, sizeDestination, GameManager.gameState));
}
}
}
\ No newline at end of file
......@@ -26,22 +26,18 @@ public class Player : MonoBehaviour {
if (tx < ttx)
{
MapManager.currentRoom.CloseDoor("Left", true);
MapManager.currentRoom.inGameDoorLeft.GetComponent<Door>().close = true;
}
else if (tx > ttx)
{
MapManager.currentRoom.CloseDoor("Right", true);
MapManager.currentRoom.inGameDoorRight.GetComponent<Door>().close = true;
}
else if (ty < tty)
{
MapManager.currentRoom.CloseDoor("Down", true);
MapManager.currentRoom.inGameDoorDown.GetComponent<Door>().close = true;
}
else if (ty > tty)
{
MapManager.currentRoom.CloseDoor("Up", true);
MapManager.currentRoom.inGameDoorUp.GetComponent<Door>().close = true;
}
}
ttx = tx;
......
......@@ -24,7 +24,15 @@ public class GameManager : MonoBehaviour {
}
// Update is called once per frame
void Update () {
void Update ()
{
if (Input.GetKeyDown(KeyCode.Tab) && CameraController.isSceneChanging != true)
{
if (gameState == GameState.Ingame)
gameState = GameState.Tetris;
else if (gameState == GameState.Tetris)
gameState = GameState.Ingame;
StartCoroutine(FindObjectOfType<Camera>().GetComponent<CameraController>().ChangeScene(gameState));
}
}
}
fileFormatVersion: 2
guid: 3eeb43e73bfaf1f48901afcdbe4f6d11
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: af419b0d4a8e8ed4b8066e753699f2bf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -4,7 +4,6 @@ using UnityEngine;
public class Door : MonoBehaviour {
public bool close = false;
public int position;
public int enteredPosition;
public Animator animatorThisRoom;
......@@ -12,7 +11,7 @@ public class Door : MonoBehaviour {
private void OnTriggerExit2D(Collider2D collision)
{
if (enteredPosition == position && collision.tag.Equals("Player") && close == true)
if (enteredPosition == position && collision.tag.Equals("Player"))
{
switch (position)
{
......@@ -45,7 +44,7 @@ public class Door : MonoBehaviour {
animatorThisRoom.SetBool("doorClose", true);
animatorNextRoom.SetBool("doorClose", true);
}
close = false;
}
}
}
......@@ -136,11 +136,6 @@ public class MapManager : MonoBehaviour {
/// Right door in ingame.
/// </summary>
public GameObject inGameDoorRight;
/// <summary>
/// Array for the normal Room candidates.
/// </summary>
......@@ -155,19 +150,13 @@ public class MapManager : MonoBehaviour {
List<RoomInGame>[,] normalRoomsDistributed = new List<RoomInGame>[3, 3];
/// <summary>
/// Room player exists.
/// Not related to player's real position, it also consider if player enter the room ordinarily.
/// </summary>
public static Room currentRoom;
/// <summary>
/// Temporary room player exists according to only position.
/// </summary>
public static Room tempRoom;
/// <summary>
/// Queue that saves rooms waiting for upgrade tetrimino.
/// </summary>
......@@ -405,7 +394,7 @@ public class MapManager : MonoBehaviour {
if (shakeCamera)
{
Camera camera = FindObjectOfType<Camera>();
StartCoroutine(CameraShake(5 * (top - bottom + 1) / CameraController.tetrisCameraSize, camera.transform.position, camera));
StartCoroutine(camera.GetComponent<CameraController>().CameraShake(5 * (top - bottom + 1) / CameraController.tetrisCameraSize));
}
for (int i = 0; i < height; i++)
{
......@@ -600,7 +589,7 @@ public class MapManager : MonoBehaviour {
te.transform.position += new Vector3(0, -fallSpeed, 0);
}
Camera camera = FindObjectOfType<Camera>();
StartCoroutine(CameraShake(20 / CameraController.tetrisCameraSize, camera.transform.position, camera));
StartCoroutine(camera.GetComponent<CameraController>().CameraShake(20 / CameraController.tetrisCameraSize));
EndTetrimino(te);
}
/// <summary>
......@@ -739,7 +728,7 @@ public class MapManager : MonoBehaviour {
yield return new WaitForSeconds(1f);
tetriminoSpawner.MakeTetrimino();
}
/// <summary>
/*/// <summary>
/// Shake the camera when tetrimino has fallen.
/// </summary>
/// <param name="_amount">Amount you want to shake the camera.</param>
......@@ -759,7 +748,7 @@ public class MapManager : MonoBehaviour {
yield return null;
}
camera.transform.localPosition = originPos;
}
}*/
/// <summary>
/// Make room fade in.
/// </summary>
......@@ -768,15 +757,14 @@ public class MapManager : MonoBehaviour {
public IEnumerator RoomFadeIn(Room room)
{
float alpha = 1;
yield return new WaitForSeconds(0.1f);
while(alpha > 0.0001)
for (int i = 0; i < 20; i++)
{
alpha = Mathf.Lerp(alpha, 0, Mathf.Sqrt(Time.deltaTime));
yield return new WaitForSeconds(0.01f);
room.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, alpha);
room.leftTetrisDoor.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, alpha);
room.rightTetrisDoor.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, alpha);
room.fog.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, alpha);
yield return null;
alpha -= 0.05f;
}
room.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
room.leftTetrisDoor.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
......@@ -791,14 +779,14 @@ public class MapManager : MonoBehaviour {
public IEnumerator RoomFadeOut(Room room)
{
float alpha = 0;
while (alpha < 0.99909)
for(int i = 0; i < 20; i++)
{
alpha = Mathf.Lerp(alpha, 1, Mathf.Sqrt(Time.deltaTime));
yield return new WaitForSeconds(0.01f);
room.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, alpha);
room.leftTetrisDoor.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, alpha);
room.rightTetrisDoor.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, alpha);
room.fog.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, alpha);
yield return null;
alpha += 0.05f;
}
room.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1);
room.leftTetrisDoor.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1);
......
......@@ -249,7 +249,6 @@ public class Room : MonoBehaviour
}
door.GetComponent<Door>().animatorThisRoom = animatorThisRoom;
door.GetComponent<Door>().animatorNextRoom = animatorNextRoom;
door.GetComponent<Door>().close = true;
}
}
else
......
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