### Querying for Running Subsystems Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/docs/mrtk3-overview/architecture/subsystems.md Use `XRSubsystemHelpers` to retrieve running subsystem implementations. The `GetFirstRunningSubsystem` method returns the first started and running instance, while `GetFirstSubsystem` retrieves the first instance regardless of its start state. `GetAllRunningSubsystemsNonAlloc` can be used to collect all running instances into a provided list. ```csharp T mySubsystem = XRSubsystemHelpers.GetFirstRunningSubsystem(); // Gets the first valid implementation of T, even if it hasn't been started. T mySubsystem = XRSubsystemHelpers.GetFirstSubsystem(); // If multiple implementations of T are loaded, get all of them. List allOfThem = new List(); GetAllRunningSubsystemsNonAlloc(allOfThem); ``` -------------------------------- ### Clone Repository with Specific Branch Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/contributions/code-contributions.md Use this command to clone the repository and immediately switch to the 'main' branch, ensuring you start on the correct branch. ```bash git clone --branch main YOUR_GIT_URL ``` -------------------------------- ### Get Subsystem Configuration Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/org.mixedrealitytoolkit.tools/SubsystemWizard/Templates/ApplyConfigTemplate.txt Retrieves the configuration object for a specific subsystem using XRSubsystemHelpers.GetConfiguration. This is typically done in the subsystem provider's constructor. ```csharp protected %CONFIGNAME% Config { get; } public %SUBSYSTEMNAME%Provider() : base() { Config = XRSubsystemHelpers.GetConfiguration<%CONFIGNAME%, %SUBSYSTEMNAME%>(); // TODO: Apply the configuration to the provider. } ``` -------------------------------- ### Accessing Subsystem Descriptor Capabilities Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/docs/mrtk3-overview/architecture/subsystems.md Retrieve the descriptor for a running subsystem to access its capability information. This example shows how to check if a `HandsSubsystem` implementation reports physical data. ```csharp // Get the first running hands subsystem. var handsSubsystem = XRSubsystemHelpers.GetFirstRunningSubsystem(); // If we found one... if (handsSubsystem != null) { // Read the capability information off the implementation's descriptor. bool isPhysicalData = handsSubsystem.subsystemDescriptor.IsPhysicalData; } ``` -------------------------------- ### Get Subsystem Configuration Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/docs/mrtk3-overview/architecture/subsystems.md Retrieve the configuration object for a specific subsystem type. Ensure the generic type parameters TConfig and TSubsystem are correctly specified. ```csharp XRSubsystemHelpers.GetConfiguration() ``` -------------------------------- ### Run Play Mode Tests with Custom Arguments Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/contributions/code-contributions.md Run play mode tests locally in batch mode with specified Unity version and project path. This allows for testing against different Unity versions or project configurations. ```powershell ./Tooling/Tests/run_playmode_tests.ps1 -unityVersion 2021.3.5f1 -projectPath ../my/project/path ``` -------------------------------- ### Subsystem Configuration Class Template Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/org.mixedrealitytoolkit.tools/SubsystemWizard/Templates/SubsystemConfigTemplate.txt Defines a configuration asset for a subsystem. Use this as a base for custom subsystem configurations. ```csharp // TODO: [Optional] Add copyright and license statement(s). using MixedReality.Toolkit; using UnityEngine; namespace %NAMESPACE% { /// /// The configuration object for all %SUBSYSTEMBASECLASSNAME% implementations. /// [CreateAssetMenu( fileName = "%SUBSYSTEMBASECLASSNAME%Config.asset", menuName = "Custom/Subsystems/%SUBSYSTEMBASECLASSNAME% Config")] public class %SUBSYSTEMBASECLASSNAME%Config : BaseSubsystemConfig { // TODO: Add subsystem specific configuration properties. } } ``` -------------------------------- ### Subsystem Configuration Info Class Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/org.mixedrealitytoolkit.tools/SubsystemWizard/Templates/SubsystemDescriptorTemplate.txt Defines the configuration parameters for a subsystem. Inherits from MRTKSubsystemCinfo and can include subsystem-specific properties. Override Equals for custom comparison. ```csharp using MixedReality.Toolkit; using MixedReality.Toolkit.Subsystems; using System; namespace %NAMESPACE% { /// /// Encapsulates the parameters for creating a new . /// public class %SUBSYSTEMBASECLASSNAME%Cinfo : MRTKSubsystemCinfo { // TODO: Add subsystem specific properties. /// /// Tests for equality. /// /// The other to compare against. /// `True` if every field in is equal to this , otherwise false. public override bool Equals(MRTKSubsystemCinfo other) { // TODO: Add comparison of subsystem specific property values. return base.Equals(other); } } ``` -------------------------------- ### Subsystem Base Class Template Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/org.mixedrealitytoolkit.tools/SubsystemWizard/Templates/SubsystemBaseClassTemplate.txt This C# code defines the base class for a custom MRTK subsystem. It inherits from MRTKSubsystem and includes a constructor and a nested abstract Provider class. Use this as a starting point for your own subsystem implementations. ```csharp // TODO: [Optional] Add copyright and license statement(s). using MixedReality.Toolkit.Subsystems; using UnityEngine.Scripting; using UnityEngine.SubsystemsImplementation; namespace %NAMESPACE% { [Preserve] public class %SUBSYSTEMBASECLASSNAME% : MRTKSubsystem<%SUBSYSTEMBASECLASSNAME%, %SUBSYSTEMBASECLASSNAME%Descriptor, %SUBSYSTEMBASECLASSNAME%.Provider>, I%SUBSYSTEMBASECLASSNAME% { /// /// Construct the %SUBSYSTEMBASECLASSNAME%. /// public %SUBSYSTEMBASECLASSNAME%() { } [Preserve] public abstract class Provider : MRTKSubsystemProvider<%SUBSYSTEMBASECLASSNAME%>, I%SUBSYSTEMBASECLASSNAME% { #region I%SUBSYSTEMBASECLASSNAME% implementation // TODO: Implement abstract Provider class. #endregion I%SUBSYSTEMBASECLASSNAME% implementation } #region I%SUBSYSTEMBASECLASSNAME% implementation // TODO: Calls into abstract Provider (ex: public int MaxValue => provider.MaxValue; #endregion I%SUBSYSTEMBASECLASSNAME% implementation /// /// Registers a %SUBSYSTEMBASECLASSNAME% implementation based on the given subsystem parameters. /// /// The parameters defining the %SUBSYSTEMBASECLASSNAME% /// functionality implemented by the subsystem provider. /// /// true if the subsystem implementation is registered. Otherwise, false. /// public static bool Register(%SUBSYSTEMBASECLASSNAME%Cinfo subsystemParams) { %SUBSYSTEMBASECLASSNAME%Descriptor Descriptor = %SUBSYSTEMBASECLASSNAME%Descriptor.Create(subsystemParams); SubsystemDescriptorStore.RegisterDescriptor(Descriptor); return true; } } } ``` -------------------------------- ### Run Play Mode Tests Locally Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/contributions/code-contributions.md Execute play mode tests locally in batch mode using the provided PowerShell script. This helps identify issues that may only occur in non-graphics batch mode. ```powershell ./Tooling/Tests/run_playmode_tests.ps1 ``` -------------------------------- ### Create a New Feature Branch Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/contributions/code-contributions.md Create a new branch for your changes or fixes to keep your work organized and separate from the main development line. ```bash git checkout -b foobar_fix ``` -------------------------------- ### Subsystem Descriptor Class Source: https://github.com/mixedrealitytoolkit/mixedrealitytoolkit-unity/blob/main/org.mixedrealitytoolkit.tools/SubsystemWizard/Templates/SubsystemDescriptorTemplate.txt Defines the descriptor for a subsystem, specifying its interface and provider type. Includes a factory method for creation and validation. ```csharp /// /// Specifies a functionality description that may be registered for each implementation that provides the /// interface. /// public class %SUBSYSTEMBASECLASSNAME%Descriptor : MRTKSubsystemDescriptor<%SUBSYSTEMBASECLASSNAME%, %SUBSYSTEMBASECLASSNAME%.Provider> { /// /// Constructs a %SUBSYSTEMBASECLASSNAME%Descriptor based on the given parameters. /// /// The parameters required to initialize the descriptor. %SUBSYSTEMBASECLASSNAME%Descriptor(%SUBSYSTEMBASECLASSNAME%Cinfo cinfo) : base(cinfo) { // TODO: Initialize subsystem specific properties. } // TODO: Add subsystem specific properties. /// /// Creates a %SUBSYSTEMBASECLASSNAME%Descriptor based on the given parameters validating that the /// id and implentationType properties are specified. /// /// The parameters required to initialize the descriptor. /// /// The created %SUBSYSTEMBASECLASSNAME%Descriptor. /// internal static %SUBSYSTEMBASECLASSNAME%Descriptor Create(%SUBSYSTEMBASECLASSNAME%Cinfo cinfo) { // Validates cinfo. if (!XRSubsystemHelpers.CheckTypes<%SUBSYSTEMBASECLASSNAME%, %SUBSYSTEMBASECLASSNAME%.Provider>( cinfo.Name, cinfo.SubsystemTypeOverride, cinfo.ProviderType)) { throw new ArgumentException("Could not create %SUBSYSTEMBASECLASSNAME%Descriptor."); } return new %SUBSYSTEMBASECLASSNAME%Descriptor(cinfo); } } } ```