Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [4.2.1] - 2021-12-09
### Fixed
* Resolve FB [1378643](https://fogbugz.unity3d.com/f/cases/1378643/) by enforcing creation of `XRGeneralSettingsPerBuildTarget` using a new API `XRGeneralSettingsPerBuildTarget.GetOrCreate()`
  • Loading branch information
Unity Technologies committed Dec 9, 2021
1 parent de3a8f3 commit 0113b92
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 76 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [4.2.1] - 2021-12-09
### Fixed
* Resolve FB [1378643](https://fogbugz.unity3d.com/f/cases/1378643/) by enforcing creation of `XRGeneralSettingsPerBuildTarget` using a new API `XRGeneralSettingsPerBuildTarget.GetOrCreate()`

## [4.2.0] - 2021-10-05
### Added
* Resolve FB [1369638](https://fogbugz.unity3d.com/f/cases/resolve/1369638) by adding five new APIs to `XRGeneralSettingsPerBuildTarget` for scripting settings checking and creation :
* Resolve FB [1369638](https://fogbugz.unity3d.com/f/cases/resolve/1369638) by adding five new APIs to `XRGeneralSettingsPerBuildTarget` for scripting settings checking and creation :
* `HasSettingsForBuildTarget`
* `CreateDefaultSettingsForBuildTarget`
* `HasManagerSettingsForBuildTarget`
Expand Down
59 changes: 26 additions & 33 deletions Editor/XRGeneralBuildProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ public void OnPreprocessBuild(BuildReport report)
// dirty later builds with assets that may not be needed or are out of date.
CleanOldSettings();

XRGeneralSettingsPerBuildTarget buildTargetSettings = null;
EditorBuildSettings.TryGetConfigObject(XRGeneralSettings.k_SettingsKey, out buildTargetSettings);
if (buildTargetSettings == null)
return;

XRGeneralSettingsPerBuildTarget buildTargetSettings = XRGeneralSettingsPerBuildTarget.GetOrCreate();
XRGeneralSettings settings = buildTargetSettings.SettingsForBuildTarget(report.summary.platformGroup);
if (settings == null)
return;
Expand All @@ -134,39 +130,36 @@ public void OnPreprocessBuild(BuildReport report)
{
var loaders = loaderManager.activeLoaders;
// If there are no loaders present in the current manager instance, then the settings will not be included in the current build.
if (loaders.Count == 0)
return;

var summary = report.summary;
if (loaders.Count > 0)
{
var summary = report.summary;

XRManagementAnalytics.SendBuildEvent(summary.guid, summary.platform, summary.platformGroup, loaders);
XRManagementAnalytics.SendBuildEvent(summary.guid, summary.platform, summary.platformGroup, loaders);

// chances are that our devices won't fall back to graphics device types later in the list so it's better to assume the device will be created with the first gfx api in the list.
// furthermore, we have no way to influence falling back to other graphics API types unless we automatically change settings underneath the user which is no good!
GraphicsDeviceType[] deviceTypes = PlayerSettings.GetGraphicsAPIs(report.summary.platform);
if (deviceTypes.Length > 0)
{
VerifyGraphicsAPICompatibility(loaderManager, deviceTypes[0]);
}
else
{
Debug.LogWarning("No Graphics APIs have been configured in Player Settings.");
}
// chances are that our devices won't fall back to graphics device types later in the list so it's better to assume the device will be created with the first gfx api in the list.
// furthermore, we have no way to influence falling back to other graphics API types unless we automatically change settings underneath the user which is no good!
GraphicsDeviceType[] deviceTypes = PlayerSettings.GetGraphicsAPIs(report.summary.platform);
if (deviceTypes.Length > 0)
{
VerifyGraphicsAPICompatibility(loaderManager, deviceTypes[0]);
}
else
{
Debug.LogWarning("No Graphics APIs have been configured in Player Settings.");
}

PreInitInfo preInitInfo = null;
if (loaders.Count >= 1)
{
PreInitInfo preInitInfo = null;
preInitInfo = new PreInitInfo(loaders[0] as IXRLoaderPreInit, report.summary.platform, report.summary.platformGroup);
}

var loader = preInitInfo?.loader ?? null;
if (loader != null)
{
BootConfig bootConfig = new BootConfig(report);
bootConfig.ReadBootConfig();
string preInitLibraryName = loader.GetPreInitLibraryName(preInitInfo.buildTarget, preInitInfo.buildTargetGroup);
bootConfig.SetValueForKey(kPreInitLibraryKey, preInitLibraryName);
bootConfig.WriteBootConfig();
var loader = preInitInfo?.loader ?? null;
if (loader != null)
{
BootConfig bootConfig = new BootConfig(report);
bootConfig.ReadBootConfig();
string preInitLibraryName = loader.GetPreInitLibraryName(preInitInfo.buildTarget, preInitInfo.buildTargetGroup);
bootConfig.SetValueForKey(kPreInitLibraryKey, preInitLibraryName);
bootConfig.WriteBootConfig();
}
}
}

Expand Down
39 changes: 36 additions & 3 deletions Editor/XRGeneralSettingsPerBuildTarget.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.XR.Management;

Expand Down Expand Up @@ -75,7 +76,9 @@ static void PlayModeStateChanged(PlayModeStateChange state)
XRGeneralSettingsPerBuildTarget buildTargetSettings = null;
EditorBuildSettings.TryGetConfigObject(XRGeneralSettings.k_SettingsKey, out buildTargetSettings);
if (buildTargetSettings == null)
return;
{
buildTargetSettings = GetOrCreate();
}

XRGeneralSettings instance = buildTargetSettings.SettingsForBuildTarget(BuildTargetGroup.Standalone);
if (instance == null || !instance.InitManagerOnStart)
Expand All @@ -86,7 +89,6 @@ static void PlayModeStateChanged(PlayModeStateChange state)

internal static bool ContainsLoaderForAnyBuildTarget(string loaderTypeName)
{

XRGeneralSettingsPerBuildTarget buildTargetSettings = null;
EditorBuildSettings.TryGetConfigObject(XRGeneralSettings.k_SettingsKey, out buildTargetSettings);
if (buildTargetSettings == null)
Expand All @@ -100,6 +102,37 @@ internal static bool ContainsLoaderForAnyBuildTarget(string loaderTypeName)

return false;
}

[MethodImpl(MethodImplOptions.Synchronized)]
internal static XRGeneralSettingsPerBuildTarget GetOrCreate()
{
EditorBuildSettings.TryGetConfigObject<XRGeneralSettingsPerBuildTarget>(XRGeneralSettings.k_SettingsKey, out var generalSettings);
if (generalSettings == null)
{
string searchText = "t:XRGeneralSettings";
string[] assets = AssetDatabase.FindAssets(searchText);
if (assets.Length > 0)
{
string path = AssetDatabase.GUIDToAssetPath(assets[0]);
generalSettings = AssetDatabase.LoadAssetAtPath(path, typeof(XRGeneralSettingsPerBuildTarget)) as XRGeneralSettingsPerBuildTarget;
}
}

if (generalSettings == null)
{
generalSettings = CreateInstance(typeof(XRGeneralSettingsPerBuildTarget)) as XRGeneralSettingsPerBuildTarget;
string assetPath = EditorUtilities.GetAssetPathForComponents(EditorUtilities.s_DefaultGeneralSettingsPath);
if (!string.IsNullOrEmpty(assetPath))
{
assetPath = Path.Combine(assetPath, "XRGeneralSettings.asset");
AssetDatabase.CreateAsset(generalSettings, assetPath);
}
}

EditorBuildSettings.AddConfigObject(XRGeneralSettings.k_SettingsKey, generalSettings, true);

return generalSettings;
}
#endif

/// <summary>
Expand Down
37 changes: 1 addition & 36 deletions Editor/XRSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,47 +74,13 @@ internal bool ResetUi

private Dictionary<BuildTargetGroup, XRManagerSettingsEditor> CachedSettingsEditor = new Dictionary<BuildTargetGroup, XRManagerSettingsEditor>();


private BuildTargetGroup m_LastBuildTargetGroup = BuildTargetGroup.Unknown;

static XRGeneralSettingsPerBuildTarget currentSettings
{
get
{
XRGeneralSettingsPerBuildTarget generalSettings = null;
EditorBuildSettings.TryGetConfigObject(XRGeneralSettings.k_SettingsKey, out generalSettings);
if (generalSettings == null)
{
lock(s_SettingsManager)
{
EditorBuildSettings.TryGetConfigObject(XRGeneralSettings.k_SettingsKey, out generalSettings);
if (generalSettings == null)
{
string searchText = "t:XRGeneralSettings";
string[] assets = AssetDatabase.FindAssets(searchText);
if (assets.Length > 0)
{
string path = AssetDatabase.GUIDToAssetPath(assets[0]);
generalSettings = AssetDatabase.LoadAssetAtPath(path, typeof(XRGeneralSettingsPerBuildTarget)) as XRGeneralSettingsPerBuildTarget;
}
}

if (generalSettings == null)
{
generalSettings = ScriptableObject.CreateInstance(typeof(XRGeneralSettingsPerBuildTarget)) as XRGeneralSettingsPerBuildTarget;
string assetPath = EditorUtilities.GetAssetPathForComponents(EditorUtilities.s_DefaultGeneralSettingsPath);
if (!string.IsNullOrEmpty(assetPath))
{
assetPath = Path.Combine(assetPath, "XRGeneralSettings.asset");
AssetDatabase.CreateAsset(generalSettings, assetPath);
}
}

EditorBuildSettings.AddConfigObject(XRGeneralSettings.k_SettingsKey, generalSettings, true);

}
}
return generalSettings;
return XRGeneralSettingsPerBuildTarget.GetOrCreate();
}
}

Expand Down Expand Up @@ -166,7 +132,6 @@ void InitEditorData(ScriptableObject settings)
}
}


/// <summary>See <see href="https://docs.unity3d.com/ScriptReference/SettingsProvider.html">SettingsProvider documentation</see>.</summary>
public override void OnActivate(string searchContext, VisualElement rootElement)
{
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.unity.xr.management",
"displayName": "XR Plugin Management",
"version": "4.2.0",
"version": "4.2.1",
"unity": "2019.4",
"unityRelease": "15f1",
"description": "Package that provides simple management of XR plug-ins. Manages and offers help with loading, initialization, settings, and build support for XR plug-ins.",
Expand All @@ -24,10 +24,10 @@
"repository": {
"url": "https://github.cds.internal.unity3d.com/unity/xr.sdk.management.git",
"type": "git",
"revision": "c8fb6583d6d04516909a8d2ab999a1dbe90ade50"
"revision": "9c99228887ff65cc0729434b3b9371d22b707cb9"
},
"upmCi": {
"footprint": "f20b2c4ae98c5e1dc40a936e5ead6729be01083d"
"footprint": "d6b9ef69ace3447279fc92e1dafd2c4cefef2015"
},
"samples": [
{
Expand Down

0 comments on commit 0113b92

Please sign in to comment.