Skip to content

Commit ee561ce

Browse files
Updated unitypackage in repo and fixed bugs
Fixed inconsistencies in files operations and the issue with SaveSettings having self referential jsonString as member
1 parent 2ec57cc commit ee561ce

26 files changed

+14835
-46602
lines changed
29.5 KB
Binary file not shown.
-2.4 MB
Binary file not shown.

Pause Menu Assetstore/Assets/Pause Menu Assets/Scripts/Pausemenu/PauseManager.cs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class PauseManager : MonoBehaviour
7979
/// <summary>
8080
/// The terrain detail density float. It's only public because you may want to adjust it in editor
8181
/// </summary>
82-
public float detailDensity;
82+
public float detailDensity;
8383

8484
/// <summary>
8585
/// Timescale value. The defualt is 1 for most games. You may want to change it if you are pausing the game in a slow motion situation
@@ -88,11 +88,11 @@ public class PauseManager : MonoBehaviour
8888
/// <summary>
8989
/// One terrain variable used if you have a terrain plugin like rtp.
9090
/// </summary>
91-
public Terrain terrain;
91+
public Terrain terrain;
9292
/// <summary>
9393
/// Other terrain variable used if you want to have an option to target low end harware.
9494
/// </summary>
95-
public Terrain simpleTerrain;
95+
public Terrain simpleTerrain;
9696
/// <summary>
9797
/// Inital shadow distance
9898
/// </summary>
@@ -169,19 +169,19 @@ public class PauseManager : MonoBehaviour
169169
/// <summary>
170170
/// Lod bias float array. You should manually assign these based on the quality level.
171171
/// </summary>
172-
public float[] LODBias;
172+
public float[] LODBias;
173173
/// <summary>
174174
/// Shadow distance array. You should manually assign these based on the quality level.
175175
/// </summary>
176-
public float[] shadowDist;
176+
public float[] shadowDist;
177177
/// <summary>
178178
/// An array of music audio sources
179179
/// </summary>
180-
public AudioSource[] music;
180+
public AudioSource[] music;
181181
/// <summary>
182182
/// An array of sound effect audio sources
183183
/// </summary>
184-
public AudioSource[] effects;
184+
public AudioSource[] effects;
185185
/// <summary>
186186
/// An array of the other UI elements, which is used for disabling the other elements when the game is paused.
187187
/// </summary>
@@ -193,7 +193,7 @@ public class PauseManager : MonoBehaviour
193193
/// <summary>
194194
/// Boolean for turning on simple terrain
195195
/// </summary>
196-
public Boolean useSimpleTerrain;
196+
public Boolean useSimpleTerrain;
197197
public static Boolean readUseSimpleTerrain;
198198
/// <summary>
199199
/// Event system
@@ -243,7 +243,7 @@ public class PauseManager : MonoBehaviour
243243

244244
//last shadow cascade value
245245
internal static int lastShadowCascade;
246-
246+
247247
public static Boolean aoBool;
248248
public static Boolean dofBool;
249249
private Boolean lastAOBool;
@@ -279,7 +279,7 @@ public class PauseManager : MonoBehaviour
279279
/// </summary>
280280
public void Start()
281281
{
282-
282+
283283
readUseSimpleTerrain = useSimpleTerrain;
284284
if (useSimpleTerrain)
285285
{
@@ -289,7 +289,7 @@ public void Start()
289289
{
290290
readTerrain = terrain;
291291
}
292-
292+
293293
mainCamShared = mainCam;
294294
//Set the lastmusicmult and last audiomult
295295
lastMusicMult = audioMusicSlider.value;
@@ -333,7 +333,16 @@ public void Start()
333333
lastTexLimit = QualitySettings.masterTextureLimit;
334334
//set last shadow cascade
335335
lastShadowCascade = QualitySettings.shadowCascades;
336-
saveSettings.LoadGameSettings(File.ReadAllText(Application.persistentDataPath + "/" + saveSettings.fileName));
336+
try
337+
{
338+
saveSettings.LoadGameSettings(File.ReadAllText(Application.persistentDataPath + "/" + saveSettings.fileName));
339+
}
340+
catch
341+
{
342+
Debug.Log("Game settings not found in: " + Application.persistentDataPath + "/" + saveSettings.fileName);
343+
saveSettings.SaveGameSettings();
344+
}
345+
337346
try
338347
{
339348
densityINI = Terrain.activeTerrain.detailObjectDensity;
@@ -362,6 +371,7 @@ public void Restart()
362371
{
363372
Application.LoadLevel(Application.loadedLevel);
364373
uiEventSystem.firstSelectedGameObject = defualtSelectedMain;
374+
365375
}
366376
/// <summary>
367377
/// Method to resume the game, so disable the pause menu and re-enable all other ui elements
@@ -467,7 +477,9 @@ public void Update()
467477
blurEffect.enabled = true;
468478
} */
469479
}
470-
else if(Input.GetKeyDown(KeyCode.Escape) && mainPanel.active == true) {
480+
else if (Input.GetKeyDown(KeyCode.Escape) && mainPanel.active == true)
481+
{
482+
471483
Time.timeScale = timeScale;
472484
mainPanel.SetActive(false);
473485
vidPanel.SetActive(false);
@@ -606,7 +618,7 @@ public void applyAudio()
606618
{
607619
StartCoroutine(applyAudioMain());
608620
uiEventSystem.SetSelectedGameObject(defualtSelectedMain);
609-
621+
610622
}
611623
/// <summary>
612624
/// Use an IEnumerator to first play the animation and then change the audio settings
@@ -823,7 +835,7 @@ public void apply()
823835
{
824836
StartCoroutine(applyVideo());
825837
uiEventSystem.SetSelectedGameObject(defualtSelectedMain);
826-
838+
827839
}
828840
/// <summary>
829841
/// Use an IEnumerator to first play the animation and then change the video settings.
@@ -1062,7 +1074,7 @@ public void toggleAO(Boolean b)
10621074
/// <param name="b"></param>
10631075
public void setFullScreen(Boolean b)
10641076
{
1065-
1077+
10661078

10671079
if (b == true)
10681080
{

Pause Menu Assetstore/Assets/Pause Menu Assets/Scripts/Pausemenu/SaveSettings.cs

Lines changed: 42 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -98,88 +98,70 @@ public class SaveSettings
9898
/// Resolution Width
9999
/// </summary>
100100
public int resWidth;
101-
/// <summary>
102-
/// The string that will be saved.
103-
/// </summary>
104-
static string jsonString;
105-
/// <summary>
106-
/// Create the JSON object needed to save settings.
107-
/// </summary>
108-
/// <param name="jsonString"></param>
109-
/// <returns></returns>
110-
public static object createJSONOBJ(string jsonString)
111-
{
112-
return JsonUtility.FromJson<SaveSettings>(jsonString);
113101

114-
}
115102
/// <summary>
116103
/// Read the game settings from the file
117104
/// </summary>
118105
/// <param name="readString"></param>
119106
public void LoadGameSettings(String readString)
120107
{
108+
SaveSettings read = JsonUtility.FromJson<SaveSettings>(readString);
109+
QualitySettings.antiAliasing = (int)read.aaQualINI;
110+
PauseManager.densityINI = read.densityINI;
111+
QualitySettings.shadowDistance = read.shadowDistINI;
112+
PauseManager.mainCamShared.farClipPlane = read.renderDistINI;
113+
PauseManager.treeMeshAmtINI = read.treeMeshAmtINI;
114+
PauseManager.mainCamShared.fieldOfView = read.fovINI;
115+
QualitySettings.antiAliasing = read.msaaINI;
116+
QualitySettings.vSyncCount = read.vsyncINI;
117+
PauseManager.lastTexLimit = read.textureLimit;
118+
QualitySettings.masterTextureLimit = read.textureLimit;
119+
AudioListener.volume = read.masterVolume;
120+
PauseManager.lastAudioMult = read.effectsVolume;
121+
PauseManager.lastMusicMult = read.musicVolume;
122+
PauseManager.dofBool = read.dofBool;
123+
PauseManager.aoBool = read.aoBool;
124+
QualitySettings.SetQualityLevel(read.curQualityLevel);
125+
QualitySettings.shadowCascades = read.lastShadowCascade;
126+
Screen.SetResolution(read.resWidth, read.resHeight, read.fullscreenBool);
127+
if (read.anisoLevel == 0)
128+
{
129+
QualitySettings.anisotropicFiltering = AnisotropicFiltering.Disable;
130+
}
131+
else if (read.anisoLevel == 1)
132+
{
133+
QualitySettings.anisotropicFiltering = AnisotropicFiltering.ForceEnable;
134+
}
135+
else if (read.anisoLevel == 2)
136+
{
137+
QualitySettings.anisotropicFiltering = AnisotropicFiltering.Enable;
138+
}
121139
try
122140
{
123-
124-
SaveSettings read = (SaveSettings)createJSONOBJ(readString);
125-
QualitySettings.antiAliasing = (int)read.aaQualINI;
126-
PauseManager.densityINI = read.densityINI;
127-
QualitySettings.shadowDistance = read.shadowDistINI;
128-
PauseManager.mainCamShared.farClipPlane = read.renderDistINI;
129-
PauseManager.treeMeshAmtINI = read.treeMeshAmtINI;
130-
PauseManager.mainCamShared.fieldOfView = read.fovINI;
131-
QualitySettings.antiAliasing = read.msaaINI;
132-
QualitySettings.vSyncCount = read.vsyncINI;
133-
PauseManager.lastTexLimit = read.textureLimit;
134-
QualitySettings.masterTextureLimit = read.textureLimit;
135-
AudioListener.volume = read.masterVolume;
136-
PauseManager.lastAudioMult = read.effectsVolume;
137-
PauseManager.lastMusicMult = read.musicVolume;
138-
PauseManager.dofBool = read.dofBool;
139-
PauseManager.aoBool = read.aoBool;
140-
QualitySettings.SetQualityLevel(read.curQualityLevel);
141-
QualitySettings.shadowCascades = read.lastShadowCascade;
142-
Screen.SetResolution(read.resWidth, read.resHeight, read.fullscreenBool);
143-
if (read.anisoLevel == 0)
141+
if (read.useSimpleTerrain)
144142
{
145-
QualitySettings.anisotropicFiltering = AnisotropicFiltering.Disable;
143+
PauseManager.readTerrain.heightmapMaximumLOD = (int)read.terrainHeightMapLOD;
146144
}
147-
else if (read.anisoLevel == 1)
148-
{
149-
QualitySettings.anisotropicFiltering = AnisotropicFiltering.ForceEnable;
150-
}
151-
else if (read.anisoLevel == 2)
152-
{
153-
QualitySettings.anisotropicFiltering = AnisotropicFiltering.Enable;
154-
}
155-
try
156-
{
157-
if (read.useSimpleTerrain)
158-
{
159-
PauseManager.readTerrain.heightmapMaximumLOD = (int)read.terrainHeightMapLOD;
160-
}
161-
else
162-
{
163-
PauseManager.readSimpleTerrain.heightmapMaximumLOD = (int)read.terrainHeightMapLOD;
164-
}
165-
PauseManager.readUseSimpleTerrain = read.useSimpleTerrain;
166-
}
167-
catch
145+
else
168146
{
169-
Debug.Log("Cannot read terain heightmap LOD because the terrain was not assigned.");
147+
PauseManager.readSimpleTerrain.heightmapMaximumLOD = (int)read.terrainHeightMapLOD;
170148
}
149+
PauseManager.readUseSimpleTerrain = read.useSimpleTerrain;
171150
}
172-
catch (FileNotFoundException)
151+
catch
173152
{
174-
Debug.Log("Game settings not found in: " + Application.persistentDataPath + "/" + fileName);
153+
Debug.Log("Cannot read terain heightmap LOD because the terrain was not assigned.");
175154
}
176-
177155
}
156+
157+
158+
178159
/// <summary>
179160
/// Get the quality/music settings before saving
180161
/// </summary>
181162
public void SaveGameSettings()
182163
{
164+
string jsonString;
183165
if (File.Exists(Application.persistentDataPath + "/" + fileName))
184166
{
185167
File.Delete(Application.persistentDataPath + "/" + fileName);

Pause Menu Assetstore/ClassDiagram1.cd

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6;0;6;-1
1+
5;0;6;-1
88 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)