-
Notifications
You must be signed in to change notification settings - Fork 26
/
PauseManager.cs
1200 lines (1136 loc) · 42.4 KB
/
PauseManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
//using UnityStandardAssets.ImageEffects;
/// <summary>
/// Copyright (c) 2016 Eric Zhu
/// </summary>
namespace GreatArcStudios
{
/// <summary>
/// The pause menu manager. You can extend this to make your own. Everything is pretty modular, so creating you own based off of this should be easy. Thanks for downloading and good luck!
/// </summary>
public class PauseManager : MonoBehaviour
{
/// <summary>
/// This is the main panel holder, which holds the main panel and should be called "main panel"
/// </summary>
public GameObject mainPanel;
/// <summary>
/// This is the video panel holder, which holds all of the controls for the video panel and should be called "vid panel"
/// </summary>
public GameObject vidPanel;
/// <summary>
/// This is the audio panel holder, which holds all of the silders for the audio panel and should be called "audio panel"
/// </summary>
public GameObject audioPanel;
/// <summary>
/// These are the game objects with the title texts like "Pause menu" and "Game Title"
/// </summary>
public GameObject TitleTexts;
/// <summary>
/// The mask that makes the scene darker
/// </summary>
public GameObject mask;
/// <summary>
/// Audio Panel animator
/// </summary>
public Animator audioPanelAnimator;
/// <summary>
/// Video Panel animator
/// </summary>
public Animator vidPanelAnimator;
/// <summary>
/// Quit Panel animator
/// </summary>
public Animator quitPanelAnimator;
/// <summary>
/// Pause menu text
/// </summary>
public Text pauseMenu;
/// <summary>
/// Main menu level string used for loading the main menu. This means you'll need to type in the editor text box, the name of the main menu level, ie: "mainmenu";
/// </summary>
public String mainMenu;
//DOF script name
/// <summary>
/// The Depth of Field script name, ie: "DepthOfField". You can leave this blank in the editor, but will throw a null refrence exception, which is harmless.
/// </summary>
public String DOFScriptName;
/// <summary>
/// The Ambient Occlusion script name, ie: "AmbientOcclusion". You can leave this blank in the editor, but will throw a null refrence exception, which is harmless.
/// </summary>
public String AOScriptName;
/// <summary>
/// The main camera, assign this through the editor.
/// </summary>
public Camera mainCam;
/// <summary>
/// The main camera game object, assign this through the editor.
/// </summary>
public GameObject mainCamObj;
/// <summary>
/// The terrain detail density float. It's only public because you may want to adjust it in editor
/// </summary>
public float detailDensity;
/// <summary>
/// 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
/// </summary>
public float timeScale = 1f;
/// <summary>
/// One terrain variable used if you have a terrain plugin like rtp.
/// </summary>
public Terrain terrain;
/// <summary>
/// Other terrain variable used if you want to have an option to target low end harware.
/// </summary>
public Terrain simpleTerrain;
/// <summary>
/// Inital shadow distance
/// </summary>
protected float shadowDistINI;
/// <summary>
/// Inital render distance
/// </summary>
protected float renderDistINI;
/// <summary>
/// Inital AA quality 2, 4, or 8
/// </summary>
protected float aaQualINI;
/// <summary>
/// Inital terrain detail density
/// </summary>
protected float densityINI;
/// <summary>
/// Amount of trees that are acutal meshes
/// </summary>
protected float treeMeshAmtINI;
/// <summary>
/// Inital fov
/// </summary>
protected float fovINI;
/// <summary>
/// Inital msaa amount
/// </summary>
protected int msaaINI;
/// <summary>
/// Inital vsync count, the Unity docs say,
/// <code>
/// //This will set the game to have one VSync per frame
/// QualitySettings.vSyncCount = 1;
/// </code>
/// <code>
/// //This will disable vsync
/// QualitySettings.vSyncCount = 0;
/// </code>
/// </summary>
protected int vsyncINI;
/// <summary>
/// AA drop down menu.
/// </summary>
public UnityEngine.UI.Dropdown aaCombo;
/// <summary>
/// Aniso drop down menu.
/// </summary>
public UnityEngine.UI.Dropdown afCombo;
public UnityEngine.UI.Slider fovSlider;
public UnityEngine.UI.Slider modelQualSlider;
public UnityEngine.UI.Slider terrainQualSlider;
public UnityEngine.UI.Slider highQualTreeSlider;
public UnityEngine.UI.Slider renderDistSlider;
public UnityEngine.UI.Slider terrainDensitySlider;
public UnityEngine.UI.Slider shadowDistSlider;
public UnityEngine.UI.Slider audioMasterSlider;
public UnityEngine.UI.Slider audioMusicSlider;
public UnityEngine.UI.Slider audioEffectsSlider;
public UnityEngine.UI.Toggle vSyncToggle;
public UnityEngine.UI.Toggle aoToggle;
public UnityEngine.UI.Toggle dofToggle;
public UnityEngine.UI.Toggle fullscreenToggle;
/// <summary>
/// The preset text label.
/// </summary>
public Text presetLabel;
/// <summary>
/// Resolution text label.
/// </summary>
public Text resolutionLabel;
/// <summary>
/// Lod bias float array. You should manually assign these based on the quality level.
/// </summary>
public float[] LODBias;
/// <summary>
/// Shadow distance array. You should manually assign these based on the quality level.
/// </summary>
public float[] shadowDist;
/// <summary>
/// An array of music audio sources
/// </summary>
public AudioSource[] music;
/// <summary>
/// An array of sound effect audio sources
/// </summary>
public AudioSource[] effects;
/// <summary>
/// An array of the other UI elements, which is used for disabling the other elements when the game is paused.
/// </summary>
public GameObject[] otherUIElements;
/// <summary>
/// Editor boolean for hardcoding certain video settings. It will allow you to use the values defined in LOD Bias and Shadow Distance
/// </summary>
public Boolean hardCodeSomeVideoSettings;
/// <summary>
/// Boolean for turning on simple terrain
/// </summary>
public Boolean useSimpleTerrain;
//int for amount of effects
private int _audioEffectAmt = 0;
//Inital audio effect volumes
private float[] _beforeEffectVol;
//Initial master volume
private float _beforeMaster;
//Initial music volume
private float _beforeMusic;
//Preset level
private int _currentLevel;
//Resoutions
private Resolution[] allRes;
//Camera dof script
private MonoBehaviour tempScript;
//Presets
private String[] presets;
//Fullscreen Boolean
private Boolean isFullscreen;
//current resoultion
private Resolution currentRes;
private Boolean aoBool;
private Boolean dofBool;
/*
//Color fade duration value
//public float crossFadeDuration;
//custom color
//public Color _customColor;
//Animation clips
private AnimationClip audioIn;
private AnimationClip audioOut;
public AnimationClip vidIn;
public AnimationClip vidOut;
public AnimationClip mainIn;
public AnimationClip mainOut;
*/
//Blur Variables
//Blur Effect Script (using the standard image effects package)
//public Blur blurEffect;
//Blur Effect Shader (should be the one that came with the package)
//public Shader blurEffectShader;
//Boolean for if the blur effect was originally enabled
//public Boolean blurBool;
/// <summary>
/// The start method; you will need to place all of your inital value getting/setting here.
/// </summary>
public void Start()
{
//Get the presets from the quality settings
presets = QualitySettings.names;
presetLabel.text = presets[QualitySettings.GetQualityLevel()].ToString();
_currentLevel = QualitySettings.GetQualityLevel();
//Get the current resoultion, if the game is in fullscreen, and set the label to the original resolution
allRes = Screen.resolutions;
currentRes = Screen.currentResolution;
Debug.Log("ini res" + currentRes);
resolutionLabel.text = Screen.currentResolution.width.ToString() + " x " + Screen.currentResolution.height.ToString();
isFullscreen = Screen.fullScreen;
//get all specified audio source volumes
_beforeEffectVol = new float[_audioEffectAmt];
_beforeMaster = AudioListener.volume;
//get all ini values
aaQualINI = QualitySettings.antiAliasing;
renderDistINI = mainCam.farClipPlane;
shadowDistINI = QualitySettings.shadowDistance;
fovINI = mainCam.fieldOfView;
msaaINI = QualitySettings.antiAliasing;
vsyncINI = QualitySettings.vSyncCount;
//enable titles
TitleTexts.SetActive(true);
//Find terrain
terrain = Terrain.activeTerrain;
//Disable other panels
mainPanel.SetActive(false);
vidPanel.SetActive(false);
audioPanel.SetActive(false);
//Enable mask
mask.SetActive(false);
//set the blur boolean to false;
//blurBool = false;
try
{
densityINI = Terrain.activeTerrain.detailObjectDensity;
}
catch (Exception e)
{
if (terrain = null)
{
Debug.Log("Terrain Not Assigned");
}
else
{
Debug.Log(e);
}
}
//Add the blur effect
/*mainCamObj.AddComponent(typeof(Blur));
blurEffect = (Blur)mainCamObj.GetComponent(typeof(Blur));
blurEffect.blurShader = blurEffectShader;
blurEffect.enabled = false; */
}
/// <summary>
/// Restart the level by loading the loaded level.
/// </summary>
public void Restart()
{
Application.LoadLevel(Application.loadedLevel);
}
/// <summary>
/// Method to resume the game, so disable the pause menu and re-enable all other ui elements
/// </summary>
public void Resume()
{
Time.timeScale = timeScale;
mainPanel.SetActive(false);
vidPanel.SetActive(false);
audioPanel.SetActive(false);
TitleTexts.SetActive(false);
mask.SetActive(false);
for (int i = 0; i < otherUIElements.Length; i++)
{
otherUIElements[i].gameObject.SetActive(true);
}
/* if (blurBool == false)
{
blurEffect.enabled = false;
}
else
{
//if you want to add in your own stuff do so here
return;
} */
}
/// <summary>
/// All the methods relating to qutting should be called here.
/// </summary>
public void quitOptions()
{
vidPanel.SetActive(false);
audioPanel.SetActive(false);
quitPanelAnimator.enabled = true;
quitPanelAnimator.Play("QuitPanelIn");
}
/// <summary>
/// Method to quit the game. Call methods such as auto saving before qutting here.
/// </summary>
public void quitGame()
{
Application.Quit();
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#endif
}
/// <summary>
/// Cancels quittting by playing an animation.
/// </summary>
public void quitCancel()
{
quitPanelAnimator.Play("QuitPanelOut");
}
/// <summary>
///Loads the main menu scene.
/// </summary>
public void returnToMenu()
{
Application.LoadLevel(mainMenu);
}
// Update is called once per frame
/// <summary>
/// The update method. This mainly searches for the user pressing the escape key.
/// </summary>
public void Update()
{
//colorCrossfade();
if (vidPanel.active == true)
{
pauseMenu.text = "Video Menu";
}
else if (audioPanel.active == true)
{
pauseMenu.text = "Audio Menu";
}
else if (mainPanel.active == true)
{
pauseMenu.text = "Pause Menu";
}
if (Input.GetKeyDown(KeyCode.Escape))
{
mainPanel.SetActive(true);
vidPanel.SetActive(false);
audioPanel.SetActive(false);
TitleTexts.SetActive(true);
mask.SetActive(true);
Time.timeScale = 0;
for (int i = 0; i < otherUIElements.Length; i++)
{
otherUIElements[i].gameObject.SetActive(false);
}
/* if (blurBool == false)
{
blurEffect.enabled = true;
} */
}
}
/*
void colorCrossfade()
{
Debug.Log(pauseMenu.color);
if (pauseMenu.color == Color.white)
{
pauseMenu.CrossFadeColor(_customColor, crossFadeDuration, true, false);
}
else {
pauseMenu.CrossFadeColor(Color.white, crossFadeDuration, true, false);
}
} */
/////Audio Options
/// <summary>
/// Show the audio panel
/// </summary>
public void Audio()
{
mainPanel.SetActive(false);
vidPanel.SetActive(false);
audioPanel.SetActive(true);
audioPanelAnimator.enabled = true;
audioIn();
pauseMenu.text = "Audio Menu";
}
/// <summary>
/// Play the "audio panel in" animation.
/// </summary>
public void audioIn()
{
audioPanelAnimator.Play("Audio Panel In");
audioMasterSlider.value = AudioListener.volume;
for (int i = 0; i < music.Length; i++)
{
audioMusicSlider.value = effects[i].volume;
}
for (int i = 0; i < effects.Length; i++)
{
audioEffectsSlider.value = effects[i].volume;
}
}
/// <summary>
/// Audio Option Methods
/// </summary>
/// <param name="f"></param>
public void updateMasterVol(float f)
{
//Controls volume of all audio listeners
AudioListener.volume = f;
}
/// <summary>
/// Update music effects volume
/// </summary>
/// <param name="f"></param>
public void updateMusicVol(float f)
{
for (int _musicAmt = 0; _musicAmt < music.Length; _musicAmt++)
{
music[_musicAmt].volume = f;
}
//_beforeMusic = music.volume;
}
/// <summary>
/// Update the audio effects volume
/// </summary>
/// <param name="f"></param>
public void updateEffectsVol(float f)
{
for (_audioEffectAmt = 0; _audioEffectAmt < effects.Length; _audioEffectAmt++)
{
//get the values for all effects before the change
_beforeEffectVol[_audioEffectAmt] = effects[_audioEffectAmt].volume;
//lower it by a factor of f because we don't want every effect to be set to a uniform volume
effects[_audioEffectAmt].volume *= f;
}
}
/// <summary>
/// The method for changing the applying new audio settings
/// </summary>
public void applyAudio()
{
StartCoroutine(applyAudioMain());
}
/// <summary>
/// Use an IEnumerator to first play the animation and then change the audio settings
/// </summary>
/// <returns></returns>
protected IEnumerator applyAudioMain()
{
audioPanelAnimator.Play("Audio Panel Out");
yield return StartCoroutine(CoroutineUtilities.WaitForRealTime((float)audioPanelAnimator.GetCurrentAnimatorClipInfo(0).Length));
mainPanel.SetActive(true);
vidPanel.SetActive(false);
audioPanel.SetActive(false);
_beforeMaster = AudioListener.volume;
}
/// <summary>
/// Cancel the audio setting changes
/// </summary>
public void cancelAudio()
{
StartCoroutine(cancelAudioMain());
}
/// <summary>
/// Use an IEnumerator to first play the animation and then change the audio settings
/// </summary>
/// <returns></returns>
protected IEnumerator cancelAudioMain()
{
audioPanelAnimator.Play("Audio Panel Out");
// Debug.Log(audioPanelAnimator.GetCurrentAnimatorClipInfo(0).Length);
yield return StartCoroutine(CoroutineUtilities.WaitForRealTime((float)audioPanelAnimator.GetCurrentAnimatorClipInfo(0).Length));
mainPanel.SetActive(true);
vidPanel.SetActive(false);
audioPanel.SetActive(false);
AudioListener.volume = _beforeMaster;
Debug.Log(_beforeMaster +AudioListener.volume);
for (_audioEffectAmt = 0; _audioEffectAmt < effects.Length; _audioEffectAmt++)
{
//get the values for all effects before the change
effects[_audioEffectAmt].volume = _beforeEffectVol[_audioEffectAmt];
}
for (int _musicAmt = 0; _musicAmt < music.Length; _musicAmt++)
{
music[_musicAmt].volume = _beforeMusic;
}
}
/////Video Options
/// <summary>
/// Show video
/// </summary>
public void Video()
{
mainPanel.SetActive(false);
vidPanel.SetActive(true);
audioPanel.SetActive(false);
vidPanelAnimator.enabled = true;
videoIn();
pauseMenu.text = "Video Menu";
}
/// <summary>
/// Play the "video panel in" animation
/// </summary>
public void videoIn()
{
vidPanelAnimator.Play("Video Panel In");
if (QualitySettings.antiAliasing == 0)
{
aaCombo.value = 0;
}
else if (QualitySettings.antiAliasing == 1)
{
aaCombo.value = 1;
}
else if (QualitySettings.antiAliasing == 2)
{
aaCombo.value = 2;
}
else if (QualitySettings.antiAliasing == 3)
{
aaCombo.value = 3;
}
if (QualitySettings.anisotropicFiltering == AnisotropicFiltering.ForceEnable)
{
afCombo.value = 2;
}
else if (QualitySettings.anisotropicFiltering == AnisotropicFiltering.Disable)
{
afCombo.value = 0;
}
else if (QualitySettings.anisotropicFiltering == AnisotropicFiltering.Enable)
{
afCombo.value = 1;
}
fovSlider.value = mainCam.fieldOfView;
modelQualSlider.value = QualitySettings.lodBias;
renderDistSlider.value = mainCam.farClipPlane;
shadowDistSlider.value = QualitySettings.shadowDistance;
fullscreenToggle.isOn = Screen.fullScreen;
aoToggle.isOn = aoBool;
dofToggle.isOn = dofBool;
if(QualitySettings.vSyncCount == 0)
{
vSyncToggle.isOn = false;
}
else
{
vSyncToggle.isOn = true;
}
try
{
if (useSimpleTerrain == true)
{
highQualTreeSlider.value = simpleTerrain.treeMaximumFullLODCount;
terrainDensitySlider.value = simpleTerrain.detailObjectDensity;
terrainQualSlider.value = terrain.heightmapMaximumLOD;
}
else
{
highQualTreeSlider.value = terrain.treeMaximumFullLODCount;
terrainDensitySlider.value = terrain.detailObjectDensity;
terrainQualSlider.value = terrain.heightmapMaximumLOD;
}
}
catch
{
return;
}
}
/// <summary>
/// Cancel the video setting changes
/// </summary>
public void cancelVideo()
{
StartCoroutine(cancelVideoMain());
}
/// <summary>
/// Use an IEnumerator to first play the animation and then changethe video settings
/// </summary>
/// <returns></returns>
protected IEnumerator cancelVideoMain()
{
vidPanelAnimator.Play("Video Panel Out");
// Debug.Log(audioPanelAnimator.GetCurrentAnimatorClipInfo(0).Length);
yield return StartCoroutine(CoroutineUtilities.WaitForRealTime((float)vidPanelAnimator.GetCurrentAnimatorClipInfo(0).Length));
try
{
QualitySettings.shadowDistance = shadowDistINI;
mainCam.farClipPlane = renderDistINI;
QualitySettings.antiAliasing = (int)aaQualINI;
Terrain.activeTerrain.detailObjectDensity = densityINI;
mainCam.fieldOfView = fovINI;
QualitySettings.antiAliasing = msaaINI;
QualitySettings.vSyncCount = vsyncINI;
mainPanel.SetActive(true);
vidPanel.SetActive(false);
audioPanel.SetActive(false);
Screen.fullScreen = isFullscreen;
}
catch (Exception e)
{
Debug.Log("A problem occured (chances are the terrain was not assigned ): " + e);
QualitySettings.shadowDistance = shadowDistINI;
mainCam.farClipPlane = renderDistINI;
QualitySettings.antiAliasing = (int)aaQualINI;
mainCam.fieldOfView = fovINI;
QualitySettings.antiAliasing = msaaINI;
QualitySettings.vSyncCount = vsyncINI;
mainPanel.SetActive(true);
vidPanel.SetActive(false);
audioPanel.SetActive(false);
}
}
//Apply the video prefs
/// <summary>
/// Apply the video settings
/// </summary>
public void apply()
{
StartCoroutine(applyVideo());
}
/// <summary>
/// Use an IEnumerator to first play the animation and then change the video settings.
/// </summary>
/// <returns></returns>
protected IEnumerator applyVideo()
{
vidPanelAnimator.Play("Video Panel Out");
yield return StartCoroutine(CoroutineUtilities.WaitForRealTime((float)vidPanelAnimator.GetCurrentAnimatorClipInfo(0).Length));
mainPanel.SetActive(true);
vidPanel.SetActive(false);
audioPanel.SetActive(false);
renderDistINI = mainCam.farClipPlane;
shadowDistINI = QualitySettings.shadowDistance;
fovINI = mainCam.fieldOfView;
isFullscreen = Screen.fullScreen;
try {
if (useSimpleTerrain == true)
{
treeMeshAmtINI = simpleTerrain.treeMaximumFullLODCount;
}
else
{
treeMeshAmtINI = simpleTerrain.treeMaximumFullLODCount;
}
}
catch(Exception e) { Debug.Log(e); }
}
/// <summary>
/// Video Options
/// </summary>
/// <param name="B"></param>
public void toggleVSync(Boolean B)
{
if (B == true)
{
QualitySettings.vSyncCount = 1;
}
else
{
QualitySettings.vSyncCount = 0;
}
}
/// <summary>
/// Update full high quality tree mesh amount.
/// </summary>
/// <param name="f"></param>
public void updateTreeMeshAmt(int f)
{
if (useSimpleTerrain == true)
{
simpleTerrain.treeMaximumFullLODCount = (int)f;
}
else
{
terrain.treeMaximumFullLODCount = (int)f;
}
}
/// <summary>
/// Change the lod bias using
/// <c>
/// QualitySettings.lodBias = LoDBias / 2.15f;
/// </c>
/// LoDBias is only divided by 2.15 because the max is set to 10 on the slider, and dividing by 2.15 results in 4.65, our desired max. However, deleting or changing 2.15 is compeletly fine.
/// </summary>
/// <param name="LoDBias"></param>
public void lodBias(float LoDBias)
{
QualitySettings.lodBias = LoDBias / 2.15f;
}
/// <summary>
/// Update the render distance using
/// <c>
/// mainCam.farClipPlane = f;
/// </c>
/// </summary>
/// <param name="f"></param>
public void updateRenderDist(float f)
{
try
{
mainCam.farClipPlane = f;
}
catch
{
Debug.Log(" Finding main camera now...it is still suggested that you manually assign this");
Camera.main.farClipPlane = f;
}
}
/// <summary>
/// Update the texture quality using
/// <c>QualitySettings.masterTextureLimit </c>
/// </summary>
/// <param name="qual"></param>
public void updateTex(float qual)
{
int f = Mathf.RoundToInt(qual);
QualitySettings.masterTextureLimit = f;
}
/// <summary>
/// Update the shadow distance using
/// <c>
/// QualitySettings.shadowDistance = dist;
/// </c>
/// </summary>
/// <param name="dist"></param>
public void updateShadowDistance(float dist)
{
QualitySettings.shadowDistance = dist;
}
/// <summary>
/// Change the max amount of high quality trees using
/// <c>
/// terrain.treeMaximumFullLODCount = (int)qual;
/// </c>
/// </summary>
/// <param name="qual"></param>
public void treeMaxLod(float qual)
{
if (useSimpleTerrain == true)
{
simpleTerrain.treeMaximumFullLODCount = (int)qual;
}
else
{
terrain.treeMaximumFullLODCount = (int)qual;
}
}
/// <summary>
/// Change the height map max LOD using
/// <c>
/// terrain.heightmapMaximumLOD = (int)qual;
/// </c>
/// </summary>
/// <param name="qual"></param>
public void updateTerrainLod(float qual)
{
try { if (useSimpleTerrain == true) { simpleTerrain.heightmapMaximumLOD = (int)qual; } else { terrain.heightmapMaximumLOD = (int)qual; } }
catch { Debug.Log("Terrain not assigned"); return; }
}
/// <summary>
/// Change the fov using a float. The defualt should be 60.
/// </summary>
/// <param name="fov"></param>
public void updateFOV(float fov)
{
mainCam.fieldOfView = fov;
}
/// <summary>
/// Toggle on or off Depth of Field. This is meant to be used with a checkbox.
/// </summary>
/// <param name="b"></param>
public void toggleDOF(Boolean b)
{
tempScript = (MonoBehaviour)mainCamObj.GetComponent(DOFScriptName);
if (b == true)
{
tempScript.enabled = true;
dofBool = true;
}
else
{
tempScript.enabled = false;
dofBool = false;
}
}
/// <summary>
/// Toggle on or off Ambient Occulusion. This is meant to be used with a checkbox.
/// </summary>
/// <param name="b"></param>
public void toggleAO(Boolean b)
{
tempScript = (MonoBehaviour)mainCamObj.GetComponent(AOScriptName);
if (b == true)
{
tempScript.enabled = true;
aoBool = true;
}
else
{
tempScript.enabled = false;
aoBool = false;
}
}
/// <summary>
/// Set the game to windowed or full screen. This is meant to be used with a checkbox
/// </summary>
/// <param name="b"></param>
public void setFullScreen(Boolean b)
{
if (b == true)
{
Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, true);
isFullscreen = true;
}
else
{
Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, false);
isFullscreen = false;
}
}
/// <summary>
/// Method for moving to the next resoution in the allRes array. WARNING: This is not finished/buggy.
/// </summary>
//Method for moving to the next resoution in the allRes array. WARNING: This is not finished/buggy.
public void nextRes()
{
//Iterate through all of the resoultions.
for (int i = 0; i < allRes.Length; i++)
{
//If the resoultion matches the current resoution height and width then go through the statement.
if (allRes[i].height == currentRes.height && allRes[i].width == currentRes.width)
{
Debug.Log("found " + i);
//If the user is playing fullscreen. Then set the resoution to one element higher in the array, set the full screen boolean to true, reset the current resolution, and then update the resolution label.
if (isFullscreen == true) { Screen.SetResolution(allRes[i + 1].width, allRes[i + 1].height, true); isFullscreen = true; currentRes = Screen.currentResolution; resolutionLabel.text = Screen.currentResolution.width.ToString() + " x " + Screen.currentResolution.height.ToString(); }
//If the user is playing in a window. Then set the resoution to one element higher in the array, set the full screen boolean to false, reset the current resolution, and then update the resolution label.
if (isFullscreen == false) { Screen.SetResolution(allRes[i + 1].width, allRes[i + 1].height, false); isFullscreen = false; currentRes = Screen.currentResolution; resolutionLabel.text = Screen.currentResolution.width.ToString() + " x " + Screen.currentResolution.height.ToString(); }
Debug.Log("Res after: " + currentRes);
}
}
}
/// <summary>
/// Method for moving to the last resoution in the allRes array. WARNING: This is not finished/buggy.
/// </summary>
//Method for moving to the last resoution in the allRes array. WARNING: This is not finished/buggy.
public void lastRes()
{
//Iterate through all of the resoultions.
for (int i = 0; i < allRes.Length; i++)
{
if (allRes[i].height == currentRes.height && allRes[i].width == currentRes.width)
{
Debug.Log("found " + i);
//If the user is playing fullscreen. Then set the resoution to one element lower in the array, set the full screen boolean to true, reset the current resolution, and then update the resolution label.
if (isFullscreen == true) { Screen.SetResolution(allRes[i - 1].width, allRes[i - 1].height, true); isFullscreen = true; currentRes = Screen.currentResolution; resolutionLabel.text = Screen.currentResolution.width.ToString() + " x " + Screen.currentResolution.height.ToString(); }
//If the user is playing in a window. Then set the resoution to one element lower in the array, set the full screen boolean to false, reset the current resolution, and then update the resolution label.
if (isFullscreen == false) { Screen.SetResolution(allRes[i - 1].width, allRes[i - 1].height, false); isFullscreen = false; currentRes = Screen.currentResolution; resolutionLabel.text = Screen.currentResolution.width.ToString() + " x " + Screen.currentResolution.height.ToString(); }
Debug.Log("Res after: " + currentRes);
}
}
}
/// <summary>
/// Force aniso on using quality settings
/// </summary>
//Force the aniso on.
public void forceOnANISO()
{
QualitySettings.anisotropicFiltering = AnisotropicFiltering.ForceEnable;
}
/// <summary>
/// Per texture aniso using quality settings
/// </summary>
//Use per texture aniso settings.
public void perTexANISO()
{
QualitySettings.anisotropicFiltering = AnisotropicFiltering.Enable;
}
/// <summary>
/// Disable aniso using quality setttings
/// </summary>
//Disable aniso all together.
public void disableANISO()
{
QualitySettings.anisotropicFiltering = AnisotropicFiltering.Disable;
}
/// <summary>
/// The method for changing aniso settings
/// </summary>
/// <param name="anisoSetting"></param>
public void updateANISO(int anisoSetting)
{
if (anisoSetting == 0)
{
disableANISO();
}
else if (anisoSetting == 1)
{
forceOnANISO();
}
else if (anisoSetting == 2)
{
perTexANISO();
}
}
/// <summary>
/// The method for setting the amount of shadow cascades
/// </summary>
/// <param name="cascades"></param>
public void updateCascades(float cascades)
{
int c = Mathf.RoundToInt(cascades);
if (c == 1)
{
c = 2;
}
else if (c == 3)
{
c = 2;
}
QualitySettings.shadowCascades = c;