From d8e2452bda5c2b18ab458ca55d43dbac0c135f06 Mon Sep 17 00:00:00 2001 From: Arif Emre Bulut Date: Tue, 4 Oct 2022 21:37:17 +0300 Subject: [PATCH] Camera position and rotation values adjusted for levels --- Assets/_Game/Scenes/Game.unity | 22 ++++++++++--- .../_Game/Scriptables/LevelData/Level1.asset | 4 ++- .../_Game/Scriptables/LevelData/Level10.asset | 4 ++- .../_Game/Scriptables/LevelData/Level2.asset | 4 ++- .../_Game/Scriptables/LevelData/Level3.asset | 4 ++- .../_Game/Scriptables/LevelData/Level4.asset | 4 ++- .../_Game/Scriptables/LevelData/Level5.asset | 4 ++- .../_Game/Scriptables/LevelData/Level6.asset | 4 ++- .../_Game/Scriptables/LevelData/Level7.asset | 4 ++- .../_Game/Scriptables/LevelData/Level8.asset | 4 ++- .../_Game/Scriptables/LevelData/Level9.asset | 4 ++- Assets/_Game/Scripts/GameManager.cs | 9 +++++- Assets/_Game/Scripts/LevelData.cs | 4 +-- Assets/_Game/Scripts/LevelManager.cs | 31 +++++++++++++++++-- 14 files changed, 86 insertions(+), 20 deletions(-) diff --git a/Assets/_Game/Scenes/Game.unity b/Assets/_Game/Scenes/Game.unity index f82d146..b5cfe92 100644 --- a/Assets/_Game/Scenes/Game.unity +++ b/Assets/_Game/Scenes/Game.unity @@ -337,6 +337,15 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: levels: + - {fileID: 11400000, guid: 938b699d1166c694ca4665cd5259970c, type: 2} + - {fileID: 11400000, guid: be700eb7d62c18c48865f891414a706f, type: 2} + - {fileID: 11400000, guid: 7e795fa0beca4154c8c8d58752842728, type: 2} + - {fileID: 11400000, guid: 2f862abdba44aa74a92212c47c0e78e1, type: 2} + - {fileID: 11400000, guid: 41b93a3e46be4424db34ec06f500de5d, type: 2} + - {fileID: 11400000, guid: 5e6fcd0862e40bc428bad25527fc50e4, type: 2} + - {fileID: 11400000, guid: 980a4aad42168104d827d800c1d0bc20, type: 2} + - {fileID: 11400000, guid: 907736b99b27d3b42bb2e8ed6da0d778, type: 2} + - {fileID: 11400000, guid: e39578be750ffee4c854247327b4841e, type: 2} - {fileID: 11400000, guid: 7785067c1ce4cd1429145e4a1cf59cc3, type: 2} colorNumberPairs: {fileID: 11400000, guid: 3343782cd2c7c464d9bc2e1028adbf1e, type: 2} levelsParent: {fileID: 820352260} @@ -347,8 +356,11 @@ MonoBehaviour: numberCubePrefab: {fileID: 7848193507420482270, guid: 43fadf1b5e61a7a45926254fb043cffe, type: 3} wallTilePrefab: {fileID: 6970115088225149969, guid: b5cc39b2695165f438e01a3853cec940, type: 3} roadTilePrefab: {fileID: 7276498328561995595, guid: 59c74d76621356944a62f7eaf07b2133, type: 3} - oldLevelSlideDuration: 0.35 - newLevelSlideDuration: 0.5 + levelBorderCube: {fileID: 5290094178444827526, guid: 981cb30fcb25be841b38bd485ea23b55, type: 3} + cameraPositionLerpDuration: 0.2 + cameraRotationLerpDuration: 0.2 + oldLevelSlideDuration: 2 + newLevelSlideDuration: 2 levelSuccessConfetti: {fileID: 2004083741} --- !u!1 &604123958 GameObject: @@ -700,11 +712,11 @@ PrefabInstance: m_Modifications: - target: {fileID: 888156194509449408, guid: b3bb2052c983592439417b8f16b9ddd7, type: 3} propertyPath: m_LocalPosition.x - value: -15 + value: -30 objectReference: {fileID: 0} - target: {fileID: 7116179399827610293, guid: b3bb2052c983592439417b8f16b9ddd7, type: 3} propertyPath: m_LocalPosition.x - value: 15 + value: 30 objectReference: {fileID: 0} - target: {fileID: 9025097603850047240, guid: b3bb2052c983592439417b8f16b9ddd7, type: 3} propertyPath: m_RootOrder @@ -1102,7 +1114,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1246718367 RectTransform: m_ObjectHideFlags: 0 diff --git a/Assets/_Game/Scriptables/LevelData/Level1.asset b/Assets/_Game/Scriptables/LevelData/Level1.asset index bbd53a3..d02bc52 100644 --- a/Assets/_Game/Scriptables/LevelData/Level1.asset +++ b/Assets/_Game/Scriptables/LevelData/Level1.asset @@ -12,5 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ea8b38accc8592345ba802e92df32984, type: 3} m_Name: Level1 m_EditorClassIdentifier: - initialPlayerNumber: 256 levelTexture: {fileID: 2800000, guid: 88a7a4ab8ebb9fc458b528d5be2ecc30, type: 3} + initialPlayerNumber: 256 + cameraPosition: {x: 0, y: 10, z: -1.38} + cameraRotation: {x: 83, y: 0, z: 0} diff --git a/Assets/_Game/Scriptables/LevelData/Level10.asset b/Assets/_Game/Scriptables/LevelData/Level10.asset index c4915f8..09c55c9 100644 --- a/Assets/_Game/Scriptables/LevelData/Level10.asset +++ b/Assets/_Game/Scriptables/LevelData/Level10.asset @@ -12,5 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ea8b38accc8592345ba802e92df32984, type: 3} m_Name: Level10 m_EditorClassIdentifier: - initialPlayerNumber: 2 levelTexture: {fileID: 2800000, guid: 1c6b7e54d908eeb40a66ea022a2075fa, type: 3} + initialPlayerNumber: 2 + cameraPosition: {x: 0, y: 25.98, z: -4.24} + cameraRotation: {x: 81, y: 0, z: 0} diff --git a/Assets/_Game/Scriptables/LevelData/Level2.asset b/Assets/_Game/Scriptables/LevelData/Level2.asset index e2ec9e3..9138137 100644 --- a/Assets/_Game/Scriptables/LevelData/Level2.asset +++ b/Assets/_Game/Scriptables/LevelData/Level2.asset @@ -12,5 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ea8b38accc8592345ba802e92df32984, type: 3} m_Name: Level2 m_EditorClassIdentifier: - initialPlayerNumber: 128 levelTexture: {fileID: 2800000, guid: 9007492f769f3444593fb004f5b619b4, type: 3} + initialPlayerNumber: 128 + cameraPosition: {x: 0, y: 13.75, z: -1.8} + cameraRotation: {x: 83, y: 0, z: 0} diff --git a/Assets/_Game/Scriptables/LevelData/Level3.asset b/Assets/_Game/Scriptables/LevelData/Level3.asset index 27ccce0..ecf967a 100644 --- a/Assets/_Game/Scriptables/LevelData/Level3.asset +++ b/Assets/_Game/Scriptables/LevelData/Level3.asset @@ -12,5 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ea8b38accc8592345ba802e92df32984, type: 3} m_Name: Level3 m_EditorClassIdentifier: - initialPlayerNumber: 2 levelTexture: {fileID: 2800000, guid: 3d102fad7c59be548950d8f85d7d6b2d, type: 3} + initialPlayerNumber: 2 + cameraPosition: {x: -0.52, y: 23.71, z: -2.93} + cameraRotation: {x: 83, y: 0, z: 0} diff --git a/Assets/_Game/Scriptables/LevelData/Level4.asset b/Assets/_Game/Scriptables/LevelData/Level4.asset index e506765..3b68b5a 100644 --- a/Assets/_Game/Scriptables/LevelData/Level4.asset +++ b/Assets/_Game/Scriptables/LevelData/Level4.asset @@ -12,5 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ea8b38accc8592345ba802e92df32984, type: 3} m_Name: Level4 m_EditorClassIdentifier: - initialPlayerNumber: 32 levelTexture: {fileID: 2800000, guid: 71f6b4cbbabb48e4396995b7f63946c8, type: 3} + initialPlayerNumber: 32 + cameraPosition: {x: -0.1, y: 17.75, z: -2.25} + cameraRotation: {x: 81, y: 0, z: 0} diff --git a/Assets/_Game/Scriptables/LevelData/Level5.asset b/Assets/_Game/Scriptables/LevelData/Level5.asset index 76b24ae..eca3cb4 100644 --- a/Assets/_Game/Scriptables/LevelData/Level5.asset +++ b/Assets/_Game/Scriptables/LevelData/Level5.asset @@ -12,5 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ea8b38accc8592345ba802e92df32984, type: 3} m_Name: Level5 m_EditorClassIdentifier: - initialPlayerNumber: 16 levelTexture: {fileID: 2800000, guid: a7916309192d2244eb1e2bd897e667fc, type: 3} + initialPlayerNumber: 16 + cameraPosition: {x: -0.95, y: 21.38, z: -4.86} + cameraRotation: {x: 80, y: 0, z: 0} diff --git a/Assets/_Game/Scriptables/LevelData/Level6.asset b/Assets/_Game/Scriptables/LevelData/Level6.asset index 30d02f7..0a7545a 100644 --- a/Assets/_Game/Scriptables/LevelData/Level6.asset +++ b/Assets/_Game/Scriptables/LevelData/Level6.asset @@ -12,5 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ea8b38accc8592345ba802e92df32984, type: 3} m_Name: Level6 m_EditorClassIdentifier: - initialPlayerNumber: 8 levelTexture: {fileID: 2800000, guid: f80d2d1306256414ab0fc4c61bc9555b, type: 3} + initialPlayerNumber: 8 + cameraPosition: {x: 0, y: 18.48, z: -3.85} + cameraRotation: {x: 80, y: 0, z: 0} diff --git a/Assets/_Game/Scriptables/LevelData/Level7.asset b/Assets/_Game/Scriptables/LevelData/Level7.asset index 7aebedf..d9b2f79 100644 --- a/Assets/_Game/Scriptables/LevelData/Level7.asset +++ b/Assets/_Game/Scriptables/LevelData/Level7.asset @@ -12,5 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ea8b38accc8592345ba802e92df32984, type: 3} m_Name: Level7 m_EditorClassIdentifier: - initialPlayerNumber: 4 levelTexture: {fileID: 2800000, guid: 9df51ac51437cea4da912d94799aa2f3, type: 3} + initialPlayerNumber: 4 + cameraPosition: {x: 0, y: 18.63, z: -2.95} + cameraRotation: {x: 81, y: 0, z: 0} diff --git a/Assets/_Game/Scriptables/LevelData/Level8.asset b/Assets/_Game/Scriptables/LevelData/Level8.asset index 1765d9b..eb28879 100644 --- a/Assets/_Game/Scriptables/LevelData/Level8.asset +++ b/Assets/_Game/Scriptables/LevelData/Level8.asset @@ -12,5 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ea8b38accc8592345ba802e92df32984, type: 3} m_Name: Level8 m_EditorClassIdentifier: - initialPlayerNumber: 8 levelTexture: {fileID: 2800000, guid: 913f9115940b2764ab534a869b1fe3d4, type: 3} + initialPlayerNumber: 8 + cameraPosition: {x: 0.5, y: 18.61, z: -3.07} + cameraRotation: {x: 81, y: 0, z: 0} diff --git a/Assets/_Game/Scriptables/LevelData/Level9.asset b/Assets/_Game/Scriptables/LevelData/Level9.asset index ff6df60..2693aaf 100644 --- a/Assets/_Game/Scriptables/LevelData/Level9.asset +++ b/Assets/_Game/Scriptables/LevelData/Level9.asset @@ -12,5 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ea8b38accc8592345ba802e92df32984, type: 3} m_Name: Level9 m_EditorClassIdentifier: - initialPlayerNumber: 2 levelTexture: {fileID: 2800000, guid: be732b7dc41544545b3d100675453584, type: 3} + initialPlayerNumber: 2 + cameraPosition: {x: 0, y: 21.62, z: -3.55} + cameraRotation: {x: 81, y: 0, z: 0} diff --git a/Assets/_Game/Scripts/GameManager.cs b/Assets/_Game/Scripts/GameManager.cs index ebff166..d58a26f 100644 --- a/Assets/_Game/Scripts/GameManager.cs +++ b/Assets/_Game/Scripts/GameManager.cs @@ -33,7 +33,14 @@ private void OnDisable() private void IncreaseLevelIndex() { - CurrentLevelIndex++; + if (CurrentLevelIndex + 1 >= LevelManager.Instance.levelCount) + { + CurrentLevelIndex = 2; + } + else + { + CurrentLevelIndex++; + } } public enum GameStatus diff --git a/Assets/_Game/Scripts/LevelData.cs b/Assets/_Game/Scripts/LevelData.cs index d360d96..7916a75 100644 --- a/Assets/_Game/Scripts/LevelData.cs +++ b/Assets/_Game/Scripts/LevelData.cs @@ -3,11 +3,11 @@ [CreateAssetMenu(fileName = "LevelData", menuName = "ScriptableObjects/LevelData")] public class LevelData : ScriptableObject { + public Texture2D levelTexture; + public int initialPlayerNumber; [Header("Camera Settings for Level")] public Vector3 cameraPosition; public Vector3 cameraRotation; - - public Texture2D levelTexture; } \ No newline at end of file diff --git a/Assets/_Game/Scripts/LevelManager.cs b/Assets/_Game/Scripts/LevelManager.cs index 34608ea..544f14b 100644 --- a/Assets/_Game/Scripts/LevelManager.cs +++ b/Assets/_Game/Scripts/LevelManager.cs @@ -2,6 +2,7 @@ using DG.Tweening; using TMPro; using System; +using System.Linq; public class LevelManager : MonoBehaviour { @@ -21,13 +22,20 @@ public class LevelManager : MonoBehaviour [SerializeField] private GameObject numberCubePrefab; [SerializeField] private GameObject wallTilePrefab; [SerializeField] private GameObject roadTilePrefab; - + [SerializeField] private GameObject levelBorderCube; + + [Header("Camera Tweens")] + [SerializeField] private float cameraPositionLerpDuration; + [SerializeField] private float cameraRotationLerpDuration; + [Header("Level Success Slide Tween")] [SerializeField] private float oldLevelSlideDuration; [SerializeField] private float newLevelSlideDuration; [SerializeField] private ParticleSystem levelSuccessConfetti; + private Camera mainCamera; + private GameObject currentLevel; private LevelData currentLevelData; private int currentLevelIndex; @@ -35,6 +43,7 @@ public class LevelManager : MonoBehaviour private bool onStart = true; public int initialPlayerNumber { get; private set; } + public int levelCount { get { return levels.Length; } } public static LevelManager Instance { get; private set; } @@ -49,6 +58,8 @@ private void Awake() { Instance = this; } + + mainCamera = Camera.main; } private void OnEnable() @@ -66,6 +77,7 @@ private void OnDisable() private void Start() { SetupLevels(); + SetCameraTransform(false); } private void SetupLevels() @@ -100,7 +112,7 @@ private void CreateCurrentLevel() for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) - { + { Color pixelColor = levelTexture.GetPixel(x, y); if (!CompareColors(pixelColor, Color.white)) @@ -144,6 +156,7 @@ private void MoveOldLevelToDestroyPoint() GetLevelInformations(); CreateCurrentLevel(); + SetCameraTransform(); MoveNewLevelToCenter(); })); } @@ -185,6 +198,20 @@ private void MoveNewLevelToCenter() .SetEase(Ease.OutCirc); } + private void SetCameraTransform(bool lerp = true) + { + if (lerp) + { + mainCamera.transform.DOMove(currentLevelData.cameraPosition, cameraPositionLerpDuration).SetEase(Ease.OutSine); + mainCamera.transform.DORotate(currentLevelData.cameraRotation, cameraRotationLerpDuration).SetEase(Ease.OutSine); + } + else + { + mainCamera.transform.position = currentLevelData.cameraPosition; + mainCamera.transform.localEulerAngles = currentLevelData.cameraRotation; + } + } + private bool CompareColors(Color color1, Color color2) { return Mathf.Abs(color1.r - color2.r) <= 0.01f