Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [4.3.1] - 2022-10-14

### Fixed
- Clean up AndroidManifest.xml every XR build to prevent conflicts with other configurations.
- Remove a spurious error when no XR providers were selected

### Changes
- Removed dependency on `com.unity.subsystemregistration` package for supported editors (2022.2+)

## [4.2.2] - 2022-04-08

### Fixed
* Related Bug: FB [1378643](https://fogbugz.unity3d.com/f/cases/1378643/).

Fixed an issue where packages that contained `XRGeneralSettingsPerBuildTarget` assets could potentially fail to reimport.

* Fixed an issue where `m_RegisteredLoaders` list would not get populated on `Awake` at runtime in a built player.

### Changes
* Updated documentation with new sections `Manual Lifecycle Handling`, `Initializing a Specific Loader`, `Changing the Loader List`, and add examples for the new documentation sections.
  • Loading branch information
Unity Technologies committed Oct 14, 2022
1 parent 0113b92 commit 6c6353b
Show file tree
Hide file tree
Showing 23 changed files with 947 additions and 250 deletions.
4 changes: 4 additions & 0 deletions .buginfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
system: jira
server: jira.unity3d.com
project: XRMB
issuetype: Bug
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ 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.3.1] - 2022-10-14

### Fixed
- Clean up AndroidManifest.xml every XR build to prevent conflicts with other configurations.
- Remove a spurious error when no XR providers were selected

### Changes
- Removed dependency on `com.unity.subsystemregistration` package for supported editors (2022.2+)

## [4.2.2] - 2022-04-08

### Fixed
* Related Bug: FB [1378643](https://fogbugz.unity3d.com/f/cases/1378643/).

Fixed an issue where packages that contained `XRGeneralSettingsPerBuildTarget` assets could potentially fail to reimport.

* Fixed an issue where `m_RegisteredLoaders` list would not get populated on `Awake` at runtime in a built player.

### Changes
* Updated documentation with new sections `Manual Lifecycle Handling`, `Initializing a Specific Loader`, `Changing the Loader List`, and add examples for the new documentation sections.

## [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()`
Expand Down
167 changes: 115 additions & 52 deletions Documentation~/EndUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ public class ManualXRControl
}
```

## Automatic XR loading for specific XR loaders
## Managing XR Loader Lifecycles Manually

The previous section showed how to manage the entire XR system lifecycle. If you require more granular control, you can manage an individual loader's lifecycle instead.

Use the script above, with some minor tweaks, to manage specific loaders at runtime, as shown in the code example below. You can use the following methods in your script:
### API

You can use the following methods in your script to control the lifecycle of XR manually:

|**Method**|**Description**|
|---|---|
Expand All @@ -84,6 +86,14 @@ Use the script above, with some minor tweaks, to manage specific loaders at runt

The following code example demonstrates how to manage individual loaders at runtime.

### Disclaimer

The following circumvents XR Management Lifecycle control. The developer is indicating that they intend to manage the lifecycle of the loaders initialized in this manner manually. APIs that expect to use XR Plug-In Management to acquire subsystems from a loader will not function properly when manually handling loader lifecycles.

If you need a specific loader initialized but want that loader to still be managed by XR Plug-In Management, look into the '[Modifying the Loader List](./EndUser.md#example-modifying-the-loader-list)' section on how to do that.

### Example

```csharp
using System;
using System.Collections;
Expand Down Expand Up @@ -139,6 +149,109 @@ public class RuntimeXRLoaderManager : MonoBehaviour
}
```

## Using XR Plug-In Management to Initialize a Specific Loader

Sometimes, you may want to include multiple loaders in a build and have them fall through in a specific order. By default, XR Plug-In Management will attempt to initialize the loader in alphabetical order based on the loaders' name. If this isn't adequate you can modify the loader list in Edit Mode, Play Mode, and in a built player with some caveats.

1) In Edit Mode, you may modify the loaders list without restriction.

2) You may reorder or remove loaders from the loader list at runtime. A new loader that wasn't known at startup can't be added to the loader list at runtime. Any attempt to add an unknown loader to the list at runtime will fail.

This means that you are able to do the following during runtime:

- Remove loaders from the list of loaders.
- Re-add loaders that were previously removed.
- Reorder the list of loaders.

3) Any operation on the XR Plug-in Manager UI will reset the ordering to the original alphabetical ordering.

### Example: Modifying the Active Loader List at Runtime

If you wish to reorder the set of loaders so XR Plug-In Management attempts to initialize a specific loader first you could do the following at runtime:

```csharp
var generalSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTarget.Standalone);
var settingsManager = generalSettings.Manager;

// Get a readonly reference to the current set of loaders.
var readonlyCurrentLoaders = settingsManager.activeLoaders;

// Modifying the loader list order
var reorderedLoadersList = new List<XRLoader>();
foreach (var loader in readonlyCurrentLoaders)
{
#if UNITY_ANDROID
if (loader is XRFooLoader)
{
// Insert 'Foo' Loaders at head of list
reorderedLoaderList.Insert(loader, 0);
}
else if (loader is XRBarLoader)
{
// Insert 'Bar' Loaders at back of list
reorderedLoaderList.Insert(loader, reorderedLoaderList.Count);
}
#else // !UNITY_ANDROID
if (loader is XRBarLoader)
{
// Insert 'Bar' Loaders at head of list
reorderedLoaderList.Insert(loader, 0);
}
else if (loader is XRFooLoader)
{
// Insert 'Foo' Loaders at back of list
reorderedLoaderList.Insert(loader, reorderedLoaderList.Count);
}
#endif // end UNITY_ANDROID
}

// Would only fail if the new list contains a loader that was
// not in the original list.
if (!settingsManager.TrySetLoaders(reorderedLoadersList))
Debug.Log("Failed to set the reordered loader list! Refer to the documentation for additional information!");

```

### Example: General Modification the loader list

You may also modify the loader list in other more general ways. The following shows how to use `TryAdd`, `TryRemove`, and `TrySet` in a variety of ways.

```csharp
var generalSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTarget.Standalone);
var settingsManager = generalSettings.Manager;

// Get example loaders as XRLoaders
var fooLoader = new FooLoader() as XRLoader;
var barLoader = new BarLoader() as XRLoader;

// Adding new loaders
// Append the new FooLoader
if (!settingsManager.TryAddLoader(fooLoader))
Debug.Log("Adding new Foo Loader failed! Refer to the documentation for additional information!");

// Insert the new BarLoader at the start of the list
if (!settingsManager.TryAddLoader(barLoader, 0))
Debug.Log("Adding new Bar Loader failed! Refer to the documentation for additional information!");

// Removing loaders
if (!settingsManager.TryRemoveLoader(fooLoader))
Debug.Log("Failed to remove the fooLoader! Refer to the documentation for additional information!");

// Modifying the loader list order
var readonlyCurrentLoaders = settingsManager.activeLoaders;

// Copy the returned read only list
var currentLoaders = new List<XRLoader>(readonlyCurrentLoaders);

// Reverse the list
currentLoaders.Reverse();

if (!settingsManager.TrySetLoaders(currentLoaders))
Debug.Log("Failed to set the reordered loader list! Refer to the documentation for additional information!");
```

You would most likely place this script in a custom pre-process build script, but that isn't required. Regardless of the script's location, you should do this as a setup step before you start a build as XR Plug-in Manager will serialize this list as part of the build execution.

## Customizing build and runtime settings

Any package that needs build or runtime settings should provide a settings data type for use. This data type appears in the **Project Settings** window, underneath a top level **XR** node.
Expand Down Expand Up @@ -202,56 +315,6 @@ Removing a plug-in from the set of assigned plug-ins for a build target:
}
```

### Example: Modifying the loader list

By default, the XR Plug-in Management UI displays loaders in strict alphabetical order, based on their names. In most scenarios, you don't need to change this order. However, if you need the loaders in a different order, you can modify the loaders list from script like so:

```csharp
var generalSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTarget.Standalone);
var settingsManager = generalSettings.Manager;

// Get example loaders as XRLoaders
var fooLoader = new FooLoader() as XRLoader;
var barLoader = new BarLoader() as XRLoader;

// Adding new loaders
// Append the new FooLoader
if (!settingsManager.TryAddLoader(fooLoader))
Debug.Log("Adding new Foo Loader failed! Refer to the documentation for additional information!");

// Insert the new BarLoader at the start of the list
if (!settingsManager.TryAddLoader(barLoader, 0))
Debug.Log("Adding new Bar Loader failed! Refer to the documentation for additional information!");

// Removing loaders
if (!settingsManager.TryRemoveLoader(fooLoader))
Debug.Log("Failed to remove the fooLoader! Refer to the documentation for additional information!");

// Modifying the loader list order
var readonlyCurrentLoaders = settingsManager.activeLoaders;

// Copy the returned read only list
var currentLoaders = new List<XRLoader>(readonlyCurrentLoaders);

// Reverse the list
currentLoaders.Reverse();

if (!settingsManager.TrySetLoaders(currentLoaders))
Debug.Log("Failed to set the reordered loader list! Refer to the documentation for additional information!");
```

You would most likely place this script in a custom build script, but that isn't required. Regardless of the script's location location, you should do this as a setup step before you start a build. This is because the first thing that XR Plug-in Manager does at build time is to serialize the loader list to the build target.

**Note:** A new loader that wasn't known at startup can't be added to the loader list at runtime, which causes the modification operation to fail. You can still modify the list during runtime, whether the app runs in Play mode or as a standalone build.

This means that you are able to do the following during runtime:

- Remove loaders from the list of loaders.
- Re-add loaders that were previously removed.
- Reorder the list of loaders.

**Note**: Any operation on the XR Plug-in Manager UI will reset the ordering to the original alphabetical ordering.

## Installing the XR Plug-in Management package

Please see related Unity documentation for [Configuring XR](https://docs.unity3d.com/Manual/configuring-project-for-xr.html ).
23 changes: 23 additions & 0 deletions Editor/Legacy/XRLegacyStandaloneSubsystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !UNITY_2020_2_OR_NEWER

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;

using UnityEditor;
using UnityEditor.PackageManager;

namespace UnityEditor.XR.Management.Legacy
{
[InitializeOnLoad]
class XRLegacyStandaloneSubsystem
{
static XRLegacyStandaloneSubsystem()
{
PackageManager.Client.Add("com.unity.subsystemregistration");
}
}
}

#endif // !UNITY_2020_2_OR_NEWER
11 changes: 11 additions & 0 deletions Editor/Legacy/XRLegacyStandaloneSubsystem.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Editor/Metadata/XRPackageMetadataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,11 @@ static void UpdateInstallablePackages()
var kpi = new KnownPackageInfo();
kpi.packageId = package.name;

#if UNITY_2022_2_OR_NEWER
kpi.verifiedVersion = package.versions.recommended;
#else
kpi.verifiedVersion = package.versions.verified;
#endif
if (string.IsNullOrEmpty(kpi.verifiedVersion))
kpi.verifiedVersion = package.versions.latestCompatible;
knownPackageInfos.Add(kpi);
Expand Down
Loading

0 comments on commit 6c6353b

Please sign in to comment.