forked from needle-mirror/com.unity.xr.management
-
Notifications
You must be signed in to change notification settings - Fork 1
/
XRGeneralSettingsUpgrade.cs
54 lines (42 loc) · 2.29 KB
/
XRGeneralSettingsUpgrade.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
using UnityEngine;
using UnityEngine.XR.Management;
namespace UnityEditor.XR.Management
{
/// <summary>Helper class to auto update settings across versions.</summary>
public static class XRGeneralSettingsUpgrade
{
/// <summary>Worker API to do the actual upgrade</summary>
/// <param name="path">Path to asset to upgrade</param>
/// <returns>True if settings were successfullly upgraded, else false.</returns>
public static bool UpgradeSettingsToPerBuildTarget(string path)
{
var generalSettings = GetXRGeneralSettingsInstance(path);
if (generalSettings == null)
return false;
if (!AssetDatabase.IsMainAsset(generalSettings))
return false;
XRGeneralSettings newSettings = ScriptableObject.CreateInstance<XRGeneralSettings>() as XRGeneralSettings;
newSettings.Manager = generalSettings.Manager;
generalSettings = null;
AssetDatabase.RemoveObjectFromAsset(newSettings.Manager); // Remove object from asset, before deleting asset
AssetDatabase.DeleteAsset(path);
XRGeneralSettingsPerBuildTarget buildTargetSettings = ScriptableObject.CreateInstance<XRGeneralSettingsPerBuildTarget>() as XRGeneralSettingsPerBuildTarget;
AssetDatabase.CreateAsset(buildTargetSettings, path);
buildTargetSettings.SetSettingsForBuildTarget(EditorUserBuildSettings.selectedBuildTargetGroup, newSettings);
newSettings.name = $"{EditorUserBuildSettings.selectedBuildTargetGroup.ToString()} Settings";
AssetDatabase.AddObjectToAsset(newSettings, path);
AssetDatabase.SaveAssets();
Debug.LogWarningFormat("XR General Settings have been upgraded to be per-Build Target Group. Original settings were moved to Build Target Group {0}.", EditorUserBuildSettings.selectedBuildTargetGroup);
return true;
}
private static XRGeneralSettings GetXRGeneralSettingsInstance(string pathToSettings)
{
XRGeneralSettings ret = null;
if (pathToSettings.Length > 0)
{
ret = AssetDatabase.LoadAssetAtPath(pathToSettings, typeof(XRGeneralSettings)) as XRGeneralSettings;
}
return ret;
}
}
}