Skip to content

Commit 0d12661

Browse files
Merge branch 'release/3.2.0'
2 parents 8b6b6d2 + d1e943d commit 0d12661

File tree

10 files changed

+89
-39
lines changed

10 files changed

+89
-39
lines changed

GameManager/Assets/Joyixir/GameManager/Scripts/Level/BaseLevel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ public virtual void InitializeLevel(BaseLevelConfig config)
2424
{
2525
_levelNumber = LevelManager.PlayerLevel;
2626
_levelConfig = config;
27+
NameLevelGameObject();
2728
FillVariables();
2829
PrepareUIRequirementsabstract();
2930
}
3031

32+
private void NameLevelGameObject()
33+
{
34+
// DEBUGGING PURPOSES
35+
gameObject.name = $"{GetType().Name}_{LevelManager.LastLoadedLevelRealIndex}";
36+
}
37+
3138
protected virtual void FillVariables()
3239
{
3340
}
@@ -83,13 +90,16 @@ public class LevelData
8390
public float Satisfaction;
8491
public int Score;
8592
public int LevelNumber;
93+
public int HumanReadableLevelNumber => LevelNumber + 1;
8694
public bool WinStatus;
95+
public int Attempt;
8796

8897
public static LevelData GenerateFromLevel(BaseLevel level)
8998
{
9099
var levelData = new LevelData();
91100
levelData.ForcedStatus = level.ForcedFinishStatus;
92101
levelData.LevelNumber = level.LevelNumber;
102+
levelData.Attempt = LevelManager.GetLevelAttempts(level.LevelNumber);
93103
if (levelData.ForcedStatus == LevelFinishStatus.Retry)
94104
{
95105
levelData.EarnedMoney = 0;

GameManager/Assets/Joyixir/GameManager/Scripts/Level/LevelManager.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using Joyixir.GameManager.Utils;
5-
using Joyixir.Utils;
65
using UnityEngine;
76
using UnityEngine.SceneManagement;
87
using Random = UnityEngine.Random;
@@ -19,6 +18,7 @@ public class LevelManager : MonoBehaviour
1918
public static Action<LevelData> OnLevelFinish;
2019
public static Action OnLevelStart;
2120
public static Action OnLevelReady;
21+
public static Action<int> OnLevelUnlocked; // Starts from 0
2222
public static Action<float> OnSceneChangeProgressChanged;
2323

2424
internal static BaseLevel CurrentLevel { get; set; }
@@ -43,7 +43,8 @@ public class LevelManager : MonoBehaviour
4343

4444
#endregion
4545

46-
46+
public static int LastLoadedLevelRealIndex { get; private set; }
47+
4748
public static int PlayerLevel
4849
{
4950
get => GameManagementPlayerPrefs.PlayerLevel;
@@ -101,6 +102,11 @@ private void CreateAndInitializeLevel()
101102
CurrentLevel.InitializeLevel(_pickedConfig);
102103
}
103104

105+
internal static int GetLevelAttempts(int levelNumber)
106+
{
107+
return GameManagementPlayerPrefs.GetLevelAttempts(levelNumber);
108+
}
109+
104110
private void CreateLevelWithScene()
105111
{
106112
if (CurrentLevel != null)
@@ -163,22 +169,30 @@ private BaseLevelConfig GetLevelConfigToLoad()
163169
{
164170
if (levelsConfigs.Count == 0)
165171
throw new Exception("No levels to load");
172+
var levelIndexToLoad = GetLevelIndexToLoad();
166173

167-
var configToLoad = levelsConfigs[0];
174+
var configToLoad = levelsConfigs[levelIndexToLoad];
175+
176+
if (configToLoad == null)
177+
throw new Exception("You assigned a null element to configs");
178+
LastLoadedLevelRealIndex = levelIndexToLoad;
179+
return configToLoad;
180+
}
181+
182+
private int GetLevelIndexToLoad()
183+
{
184+
var index = 0;
168185
if (minimumLevelToLoadAfterFirstFinish < levelsConfigs.Count)
169186
{
170187
var playerFinishedAllLevels = PlayerLevel > levelsConfigs.Count - 1;
171188
var levelIndex = playerFinishedAllLevels
172189
? Random.Range(minimumLevelToLoadAfterFirstFinish, levelsConfigs.Count)
173190
: PlayerLevel;
174-
configToLoad = levelsConfigs[levelIndex];
191+
index = levelIndex;
175192
}
176193
else
177-
configToLoad = levelsConfigs.PickRandom();
178-
179-
if (configToLoad == null)
180-
throw new Exception("You assigned a null element to configs");
181-
return configToLoad;
194+
index = Random.Range(0, levelsConfigs.Count);
195+
return index;
182196
}
183197

184198
private void UnSubscribeFromLevel()
@@ -208,6 +222,7 @@ internal void StartLevelWheneverReady()
208222
private void StartLevelNow()
209223
{
210224
SubscribeToLevel();
225+
GameManagementPlayerPrefs.AttemptLevel(CurrentLevel.LevelNumber);
211226
CurrentLevel.StartLevel();
212227
if (levelQueuedForStart)
213228
OnLevelReady -= StartLevelWheneverReady;
@@ -256,6 +271,7 @@ private int CalculateMoneyFromScore(int score)
256271
private static void IncreasePlayerLevel()
257272
{
258273
PlayerLevel++;
274+
OnLevelUnlocked?.Invoke(PlayerLevel);
259275
}
260276
}
261277
}

GameManager/Assets/Joyixir/GameManager/Scripts/Utils/GameManagementPlayerPrefs.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEngine;
1+
using System;
2+
using UnityEngine;
23

34
namespace Joyixir.GameManager.Utils
45
{
@@ -15,5 +16,16 @@ public static int PlayerTotalScore
1516
set => PlayerPrefs.SetInt("Joyixir_TotalScore", value);
1617
get => PlayerPrefs.GetInt("Joyixir_TotalScore", 0);
1718
}
19+
20+
public static int GetLevelAttempts(int levelNumber)
21+
{
22+
return PlayerPrefs.GetInt($"Joyixir_Level_{levelNumber}_Attempts", 0);
23+
}
24+
25+
public static void AttemptLevel(int levelNumber)
26+
{
27+
var newAttempt = GetLevelAttempts(levelNumber) + 1;
28+
PlayerPrefs.SetInt($"Joyixir_Level_{levelNumber}_Attempts", newAttempt);
29+
}
1830
}
1931
}

GameManager/Assets/Joyixir/Utility

Submodule Utility deleted from fee2ace

GameManager/Assets/Joyixir/Utility.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

GameManager/Packages/manifest.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"dependencies": {
3-
"com.unity.collab-proxy": "1.7.1",
3+
"com.unity.collab-proxy": "1.15.15",
44
"com.unity.ide.rider": "2.0.7",
5-
"com.unity.ide.visualstudio": "2.0.11",
6-
"com.unity.ide.vscode": "1.2.3",
7-
"com.unity.test-framework": "1.1.27",
5+
"com.unity.ide.visualstudio": "2.0.14",
6+
"com.unity.ide.vscode": "1.2.5",
7+
"com.unity.test-framework": "1.1.31",
88
"com.unity.textmeshpro": "3.0.6",
99
"com.unity.timeline": "1.4.8",
1010
"com.unity.ugui": "1.0.0",

GameManager/Packages/packages-lock.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"dependencies": {
33
"com.unity.collab-proxy": {
4-
"version": "1.7.1",
4+
"version": "1.15.15",
55
"depth": 0,
66
"source": "registry",
77
"dependencies": {
8-
"com.unity.nuget.newtonsoft-json": "2.0.0"
8+
"com.unity.services.core": "1.0.1"
99
},
1010
"url": "https://packages.unity.com"
1111
},
@@ -26,7 +26,7 @@
2626
"url": "https://packages.unity.com"
2727
},
2828
"com.unity.ide.visualstudio": {
29-
"version": "2.0.11",
29+
"version": "2.0.14",
3030
"depth": 0,
3131
"source": "registry",
3232
"dependencies": {
@@ -35,21 +35,23 @@
3535
"url": "https://packages.unity.com"
3636
},
3737
"com.unity.ide.vscode": {
38-
"version": "1.2.3",
38+
"version": "1.2.5",
3939
"depth": 0,
4040
"source": "registry",
4141
"dependencies": {},
4242
"url": "https://packages.unity.com"
4343
},
44-
"com.unity.nuget.newtonsoft-json": {
45-
"version": "2.0.0",
44+
"com.unity.services.core": {
45+
"version": "1.0.1",
4646
"depth": 1,
4747
"source": "registry",
48-
"dependencies": {},
48+
"dependencies": {
49+
"com.unity.modules.unitywebrequest": "1.0.0"
50+
},
4951
"url": "https://packages.unity.com"
5052
},
5153
"com.unity.test-framework": {
52-
"version": "1.1.27",
54+
"version": "1.1.31",
5355
"depth": 0,
5456
"source": "registry",
5557
"dependencies": {

GameManager/ProjectSettings/ProjectSettings.asset

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ PlayerSettings:
1212
targetDevice: 2
1313
useOnDemandResources: 0
1414
accelerometerFrequency: 60
15-
companyName: DefaultCompany
16-
productName: utility
15+
companyName: Joyixir
16+
productName: Game Manager
1717
defaultCursor: {fileID: 0}
1818
cursorHotspot: {x: 0, y: 0}
1919
m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1}
@@ -68,6 +68,12 @@ PlayerSettings:
6868
androidRenderOutsideSafeArea: 1
6969
androidUseSwappy: 1
7070
androidBlitType: 0
71+
androidResizableWindow: 0
72+
androidDefaultWindowWidth: 1920
73+
androidDefaultWindowHeight: 1080
74+
androidMinimumWindowWidth: 400
75+
androidMinimumWindowHeight: 300
76+
androidFullscreenMode: 1
7177
defaultIsNativeResolution: 1
7278
macRetinaSupport: 1
7379
runInBackground: 1
@@ -121,13 +127,14 @@ PlayerSettings:
121127
vulkanEnableSetSRGBWrite: 0
122128
vulkanEnablePreTransform: 0
123129
vulkanEnableLateAcquireNextImage: 0
130+
vulkanEnableCommandBufferRecycling: 1
124131
m_SupportedAspectRatios:
125132
4:3: 1
126133
5:4: 1
127134
16:10: 1
128135
16:9: 1
129136
Others: 1
130-
bundleVersion: 0.1
137+
bundleVersion: 3.2.0
131138
preloadedAssets: []
132139
metroInputSource: 0
133140
wsaTransparentSwapchain: 0
@@ -145,7 +152,8 @@ PlayerSettings:
145152
resolutionScalingMode: 0
146153
androidSupportedAspectRatio: 1
147154
androidMaxAspectRatio: 2.1
148-
applicationIdentifier: {}
155+
applicationIdentifier:
156+
Standalone: com.Joyixir.Game-Manager
149157
buildNumber:
150158
Standalone: 0
151159
iPhone: 0
@@ -235,6 +243,7 @@ PlayerSettings:
235243
useCustomGradlePropertiesTemplate: 0
236244
useCustomProguardFile: 0
237245
AndroidTargetArchitectures: 1
246+
AndroidTargetDevices: 0
238247
AndroidSplashScreenScale: 0
239248
androidSplashScreen: {fileID: 0}
240249
AndroidKeystoreName:
@@ -251,6 +260,7 @@ PlayerSettings:
251260
height: 180
252261
banner: {fileID: 0}
253262
androidGamepadSupportLevel: 0
263+
chromeosInputEmulation: 1
254264
AndroidMinifyWithR8: 0
255265
AndroidMinifyRelease: 0
256266
AndroidMinifyDebug: 0
@@ -345,6 +355,7 @@ PlayerSettings:
345355
cameraUsageDescription:
346356
locationUsageDescription:
347357
microphoneUsageDescription:
358+
bluetoothUsageDescription:
348359
switchNMETAOverride:
349360
switchNetLibKey:
350361
switchSocketMemoryPoolSize: 6144
@@ -483,7 +494,9 @@ PlayerSettings:
483494
switchPlayerConnectionEnabled: 1
484495
switchUseNewStyleFilepaths: 0
485496
switchUseMicroSleepForYield: 1
497+
switchEnableRamDiskSupport: 0
486498
switchMicroSleepForYieldTime: 25
499+
switchRamDiskSpaceSize: 12
487500
ps4NPAgeRating: 12
488501
ps4NPTitleSecret:
489502
ps4NPTrophyPackPath:
@@ -625,6 +638,7 @@ PlayerSettings:
625638
metroFTAName:
626639
metroFTAFileTypes: []
627640
metroProtocolName:
641+
vcxProjDefaultLanguage:
628642
XboxOneProductId:
629643
XboxOneUpdateKey:
630644
XboxOneSandboxId:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
m_EditorVersion: 2020.3.16f1
2-
m_EditorVersionWithRevision: 2020.3.16f1 (049d6eca3c44)
1+
m_EditorVersion: 2020.3.33f1
2+
m_EditorVersionWithRevision: 2020.3.33f1 (915a7af8b0d5)

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# GameManager
22

3-
A simple unity game management system to handle loading a game, its levels and saving the levels data such as score, gained money, level number. Also it provides enough public Actions for other classes to do things based on game status changes like listening to level finish to send analytics, etc.
3+
A simple unity game management system to handle loading a game, its levels and saving the levels data such as score, gained money, level number. Technically its a full game circle.
4+
Also it provides enough public Actions for other classes to do things based on game status changes like listening to level finish to send analytics, etc.
45

56
## Features
67

78
- Starts, ends, restarts levels
89
- Handles level number, score, money, satisfaction
910
- Initialization is separated from level start
1011
- Handles all required actions
12+
- Tracks number of attempts
1113

1214

1315
## Installation
1416
There are three ways to use it
15-
**Keep in mind that this repo is dependent to Unity TMPro and [Joyixir Utility](https://github.com/joyixir/utility)**
17+
**Keep in mind that this repo is dependent to Unity TMPro**
1618

1719
### Unitypackage
1820
- Go to the releases section and download the .unitypackage file
@@ -78,6 +80,7 @@ public static LevelManager Instance;
7880
public static Action<LevelData> OnLevelFinish;
7981
public static Action OnLevelStart;
8082
public static Action OnLevelReady;
83+
public static Action<int> OnLevelUnlocked; // Starts from 0
8184
```
8285
## What is LevelData?
8386
The short answer is the simplified data of ANY kind of levels. Doesn’t matter if a baseball or a shooter, simulation or a runner, every sort of level should be simplified to some general parameters.
@@ -113,7 +116,9 @@ public class LevelData
113116
public float Satisfaction;
114117
public int Score;
115118
public int LevelNumber;
119+
public int HumanReadableLevelNumber => LevelNumber + 1;
116120
public bool WinStatus;
121+
public int Attempt;
117122

118123
public static LevelData GenerateFromLevel(BaseLevel level)
119124
{

0 commit comments

Comments
 (0)