Skip to content

Commit

Permalink
Camera position and rotation values adjusted for levels
Browse files Browse the repository at this point in the history
  • Loading branch information
arifemrebulut committed Oct 4, 2022
1 parent 2330820 commit d8e2452
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 20 deletions.
22 changes: 17 additions & 5 deletions Assets/_Game/Scenes/Game.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Assets/_Game/Scriptables/LevelData/Level1.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 3 additions & 1 deletion Assets/_Game/Scriptables/LevelData/Level10.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 3 additions & 1 deletion Assets/_Game/Scriptables/LevelData/Level2.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 3 additions & 1 deletion Assets/_Game/Scriptables/LevelData/Level3.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 3 additions & 1 deletion Assets/_Game/Scriptables/LevelData/Level4.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 3 additions & 1 deletion Assets/_Game/Scriptables/LevelData/Level5.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 3 additions & 1 deletion Assets/_Game/Scriptables/LevelData/Level6.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 3 additions & 1 deletion Assets/_Game/Scriptables/LevelData/Level7.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 3 additions & 1 deletion Assets/_Game/Scriptables/LevelData/Level8.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 3 additions & 1 deletion Assets/_Game/Scriptables/LevelData/Level9.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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}
9 changes: 8 additions & 1 deletion Assets/_Game/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ private void OnDisable()

private void IncreaseLevelIndex()
{
CurrentLevelIndex++;
if (CurrentLevelIndex + 1 >= LevelManager.Instance.levelCount)
{
CurrentLevelIndex = 2;
}
else
{
CurrentLevelIndex++;
}
}

public enum GameStatus
Expand Down
4 changes: 2 additions & 2 deletions Assets/_Game/Scripts/LevelData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
31 changes: 29 additions & 2 deletions Assets/_Game/Scripts/LevelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DG.Tweening;
using TMPro;
using System;
using System.Linq;

public class LevelManager : MonoBehaviour
{
Expand All @@ -21,20 +22,28 @@ 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;

private bool onStart = true;

public int initialPlayerNumber { get; private set; }
public int levelCount { get { return levels.Length; } }

public static LevelManager Instance { get; private set; }

Expand All @@ -49,6 +58,8 @@ private void Awake()
{
Instance = this;
}

mainCamera = Camera.main;
}

private void OnEnable()
Expand All @@ -66,6 +77,7 @@ private void OnDisable()
private void Start()
{
SetupLevels();
SetCameraTransform(false);
}

private void SetupLevels()
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -144,6 +156,7 @@ private void MoveOldLevelToDestroyPoint()

GetLevelInformations();
CreateCurrentLevel();
SetCameraTransform();
MoveNewLevelToCenter();
}));
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d8e2452

Please sign in to comment.