Skip to content

Commit

Permalink
Update ProjectSettingsWindow to not lose settings on BuildTarget update
Browse files Browse the repository at this point in the history
Fixes #2214
  • Loading branch information
keveleigh committed Jul 10, 2018
1 parent a813c9b commit 0593c92
Showing 1 changed file with 21 additions and 10 deletions.
Expand Up @@ -63,6 +63,8 @@ public class ProjectSettingsWindow : AutoConfigureWindow<ProjectSettingsWindow.P
/// </summary>
private readonly InputManagerAxis[] obsoleteInputAxes = { };

private bool updateToolkitAxes;

#region Nested Types

public enum ProjectSetting
Expand Down Expand Up @@ -115,6 +117,8 @@ private class InputManagerAxis

protected override void ApplySettings()
{
SaveMenuSettings();

// Apply individual settings
if (Values[ProjectSetting.BuildWsaUwp])
{
Expand Down Expand Up @@ -148,7 +152,7 @@ protected override void LoadSettings()
case ProjectSetting.WsaUwpBuildToD3D:
case ProjectSetting.DotNetScriptingBackend:
case ProjectSetting.SetDefaultSpatialMappingLayer:
Values[(ProjectSetting)i] = true;
Values[(ProjectSetting)i] = EditorPrefsUtility.GetEditorPref(Names[(ProjectSetting)i], true);
break;
case ProjectSetting.TargetOccludedDevices:
Values[(ProjectSetting)i] = EditorPrefsUtility.GetEditorPref(Names[(ProjectSetting)i], false);
Expand All @@ -163,12 +167,10 @@ protected override void LoadSettings()
throw new ArgumentOutOfRangeException();
}
}

}

private void UpdateSettings(BuildTarget currentBuildTarget)
{
EditorPrefsUtility.SetEditorPref(Names[ProjectSetting.SharingServices], Values[ProjectSetting.SharingServices]);
if (Values[ProjectSetting.SharingServices])
{
string sharingServiceDirectory = Directory.GetParent(Path.GetFullPath(Application.dataPath)).FullName + "\\External\\HoloToolkit\\Sharing\\Server";
Expand Down Expand Up @@ -230,11 +232,9 @@ private void UpdateSettings(BuildTarget currentBuildTarget)
PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.PrivateNetworkClientServer, false);
}

bool useToolkitAxes = Values[ProjectSetting.UseInputManagerAxes];

if (useToolkitAxes != EditorPrefsUtility.GetEditorPref(Names[ProjectSetting.UseInputManagerAxes], false))
if (updateToolkitAxes)
{
EditorPrefsUtility.SetEditorPref(Names[ProjectSetting.UseInputManagerAxes], useToolkitAxes);
bool useToolkitAxes = Values[ProjectSetting.UseInputManagerAxes];

// Grabs the actual asset file into a SerializedObject, so we can iterate through it and edit it.
inputManagerAsset = new SerializedObject(AssetDatabase.LoadAssetAtPath("ProjectSettings/InputManager.asset", typeof(UnityEngine.Object)));
Expand Down Expand Up @@ -349,8 +349,6 @@ private void UpdateSettings(BuildTarget currentBuildTarget)
}
}

EditorPrefsUtility.SetEditorPref(Names[ProjectSetting.TargetOccludedDevices], Values[ProjectSetting.TargetOccludedDevices]);

PlayerSettings.SetScriptingBackend(BuildTargetGroup.WSA,
Values[ProjectSetting.DotNetScriptingBackend]
? ScriptingImplementation.WinRTDotNET
Expand Down Expand Up @@ -579,7 +577,7 @@ private void RefreshLocalAxesList()
private bool SetSpatialMappingLayer()
{
UnityEngine.Object[] tagAssets = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset");
if ((tagAssets == null) ||
if ((tagAssets == null) ||
(tagAssets.Length == 0))
{
return false;
Expand Down Expand Up @@ -613,5 +611,18 @@ private bool SetSpatialMappingLayer()
spatialMappingLayer.stringValue = SpatialMappingLayerName;
return tagsManager.ApplyModifiedProperties();
}

/// <summary>
/// Saves the selected items into EditorPrefs.
/// </summary>
private void SaveMenuSettings()
{
updateToolkitAxes = Values[ProjectSetting.UseInputManagerAxes] != EditorPrefsUtility.GetEditorPref(Names[ProjectSetting.UseInputManagerAxes], false);

for (int i = (int)ProjectSetting.BuildWsaUwp; i <= (int)ProjectSetting.SetDefaultSpatialMappingLayer; i++)
{
EditorPrefsUtility.SetEditorPref(Names[(ProjectSetting)i], Values[(ProjectSetting)i]);
}
}
}
}

0 comments on commit 0593c92

Please sign in to comment.