|
2 | 2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
|
3 | 3 |
|
4 | 4 | using System;
|
| 5 | +using System.IO; |
| 6 | +using System.Text.RegularExpressions; |
5 | 7 | using UnityEditor;
|
6 | 8 | using UnityEngine;
|
7 | 9 |
|
@@ -78,21 +80,35 @@ private void UpdateSettings(BuildTarget currentBuildTarget)
|
78 | 80 |
|
79 | 81 | if (Values[ProjectSetting.WsaFastestQuality])
|
80 | 82 | {
|
81 |
| - int settingId = -1; |
82 | 83 | for (var i = 0; i < QualitySettings.names.Length; i++)
|
83 | 84 | {
|
84 |
| - if (QualitySettings.names[i].Equals("Fastest")) |
85 |
| - { |
86 |
| - QualitySettings.SetQualityLevel(i); |
87 |
| - settingId = i; |
88 |
| - break; |
89 |
| - } |
| 85 | + QualitySettings.DecreaseLevel(true); |
90 | 86 | }
|
91 | 87 |
|
92 |
| - if (settingId < 0) |
| 88 | + int currentQualityLevel = QualitySettings.GetQualityLevel(); |
| 89 | + Debug.Log("Current Quality Level: " + currentQualityLevel); |
| 90 | + |
| 91 | + // HACK: Edits QualitySettings.asset Directly |
| 92 | + // TODO: replace with friendlier version that uses built in APIs when Unity fixes or makes available. |
| 93 | + // See: http://answers.unity3d.com/questions/886160/how-do-i-change-qualitysetting-for-my-platform-fro.html |
| 94 | + try |
93 | 95 | {
|
94 |
| - Debug.LogWarning("Failed to find Quality Setting 'Fastest'"); |
| 96 | + // Find the WSA element under the platform quality list and replace it's value with the current level. |
| 97 | + string settingsPath = "ProjectSettings/QualitySettings.asset"; |
| 98 | + string matchPattern = @"(m_PerPlatformDefaultQuality.*Windows Store Apps:) (\d+)"; |
| 99 | + string replacePattern = @"$1 " + currentQualityLevel; |
| 100 | + |
| 101 | + string settings = File.ReadAllText(settingsPath); |
| 102 | + settings = Regex.Replace(settings, matchPattern, replacePattern, RegexOptions.Singleline); |
| 103 | + |
| 104 | + File.WriteAllText(settingsPath, settings); |
95 | 105 | }
|
| 106 | + catch (Exception e) |
| 107 | + { |
| 108 | + Debug.LogException(e); |
| 109 | + } |
| 110 | + |
| 111 | + AssetDatabase.Refresh(); |
96 | 112 | }
|
97 | 113 |
|
98 | 114 | UnityEditorInternal.VR.VREditor.SetVREnabledOnTargetGroup(BuildTargetGroup.WSA, Values[ProjectSetting.WsaEnableVR]);
|
|
0 commit comments