ResolutionOption.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using GameWorld;
  4. using I2.Loc;
  5. using UnityEngine;
  6. public class ResolutionOption : Singleton<ResolutionOption>
  7. {
  8. public ResolutionOption()
  9. {
  10. this.InitResolutions();
  11. for (int i = 0; i < this._resolutions.Length; i++)
  12. {
  13. Resolution resolution = this._resolutions[i];
  14. if (resolution.width == this.Resolution.width && resolution.height == this.Resolution.height)
  15. {
  16. this._index = i;
  17. }
  18. }
  19. this._index = QualitySettings.GetQualityLevel();
  20. }
  21. private void InitResolutions()
  22. {
  23. this._originResolution = new Resolution
  24. {
  25. width = Screen.width,
  26. height = Screen.height
  27. };
  28. float num = (float)Screen.width / (float)Screen.height;
  29. this._resolutions = new Resolution[]
  30. {
  31. new Resolution
  32. {
  33. width = (int)(540f * num),
  34. height = 540
  35. },
  36. new Resolution
  37. {
  38. width = (int)(720f * num),
  39. height = 720
  40. },
  41. this._originResolution
  42. };
  43. this._resolutionStrings.Add("low");
  44. this._resolutionStrings.Add("normal");
  45. this._resolutionStrings.Add("high");
  46. }
  47. private Resolution Resolution
  48. {
  49. get
  50. {
  51. return new Resolution
  52. {
  53. width = Screen.width,
  54. height = Screen.height
  55. };
  56. }
  57. set
  58. {
  59. Screen.SetResolution(value.width, value.height, Screen.fullScreen);
  60. }
  61. }
  62. public string ResolutionString
  63. {
  64. get
  65. {
  66. return ScriptLocalization.Get("mobile/ui/quality_level/" + this._resolutionStrings[this._index]);
  67. }
  68. }
  69. public void SetResolutionByOffset(int step)
  70. {
  71. int num = this._index + step;
  72. if (num >= 0 && num <= this._resolutions.Length - 1)
  73. {
  74. this._index = num;
  75. QualitySettings.SetQualityLevel(num);
  76. this.SetResolutionByQualitylevel();
  77. EventManager.PostEvent<ResolutionOption>("QualityChange", this);
  78. }
  79. }
  80. public void SetResolutionByQualitylevel()
  81. {
  82. Debug.Log("SetResolutionByQualitylevel" + QualitySettings.GetQualityLevel());
  83. this.Resolution = this._resolutions[QualitySettings.GetQualityLevel()];
  84. }
  85. private Resolution[] _resolutions;
  86. private readonly List<string> _resolutionStrings = new List<string>();
  87. private int _index;
  88. private Resolution _originResolution;
  89. }