using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; using UnityEngine; using UnityEngine.Bindings; using UnityEngine.Scripting; using UnityEngine.SubsystemsImplementation; [assembly: InternalsVisibleTo("UnityEngine.TextCoreFontEngineModule")] [assembly: InternalsVisibleTo("UnityEngine.VehiclesModule")] [assembly: InternalsVisibleTo("UnityEngine.VideoModule")] [assembly: InternalsVisibleTo("UnityEngine.VirtualTexturingModule")] [assembly: InternalsVisibleTo("UnityEngine.WindModule")] [assembly: InternalsVisibleTo("UnityEngine.SwitchModule")] [assembly: InternalsVisibleTo("UnityEngine.PS4Module")] [assembly: InternalsVisibleTo("UnityEngine.PS4VRModule")] [assembly: InternalsVisibleTo("UnityEngine.PS5Module")] [assembly: InternalsVisibleTo("UnityEngine.PS5VRModule")] [assembly: UnityEngineModuleAssembly] [assembly: InternalsVisibleTo("UnityEngine.Networking")] [assembly: InternalsVisibleTo("UnityEngine.Cloud")] [assembly: InternalsVisibleTo("UnityEngine.Cloud.Service")] [assembly: InternalsVisibleTo("UnityEngine.VRModule")] [assembly: InternalsVisibleTo("Unity.Analytics")] [assembly: InternalsVisibleTo("UnityEngine.UnityAnalyticsCommon")] [assembly: InternalsVisibleTo("UnityEngine.Advertisements")] [assembly: InternalsVisibleTo("UnityEngine.Purchasing")] [assembly: InternalsVisibleTo("UnityEngine.TestRunner")] [assembly: InternalsVisibleTo("Unity.Automation")] [assembly: InternalsVisibleTo("Unity.Burst")] [assembly: InternalsVisibleTo("Unity.Burst.Editor")] [assembly: InternalsVisibleTo("Unity.DeploymentTests.Services")] [assembly: InternalsVisibleTo("Unity.IntegrationTests")] [assembly: InternalsVisibleTo("Unity.IntegrationTests.ExternalVersionControl")] [assembly: InternalsVisibleTo("Unity.IntegrationTests.UnityAnalytics")] [assembly: InternalsVisibleTo("Unity.IntegrationTests.Timeline")] [assembly: InternalsVisibleTo("Unity.IntegrationTests.Framework")] [assembly: InternalsVisibleTo("UnityEngine.Analytics")] [assembly: InternalsVisibleTo("Unity.RuntimeTests")] [assembly: InternalsVisibleTo("UnityEngine.XRModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityWebRequestWWWModule")] [assembly: InternalsVisibleTo("UnityEngine.InputForUIModule")] [assembly: InternalsVisibleTo("UnityEngine.LocalizationModule")] [assembly: InternalsVisibleTo("UnityEngine.MarshallingModule")] [assembly: InternalsVisibleTo("UnityEngine.MultiplayerModule")] [assembly: InternalsVisibleTo("UnityEngine.NVIDIAModule")] [assembly: InternalsVisibleTo("UnityEngine.ParticleSystemModule")] [assembly: InternalsVisibleTo("UnityEngine.PerformanceReportingModule")] [assembly: InternalsVisibleTo("UnityEngine.Physics2DModule")] [assembly: InternalsVisibleTo("UnityEngine.ProfilerModule")] [assembly: InternalsVisibleTo("UnityEngine.PropertiesModule")] [assembly: InternalsVisibleTo("UnityEngine.RuntimeInitializeOnLoadManagerInitializerModule")] [assembly: InternalsVisibleTo("UnityEngine.ScreenCaptureModule")] [assembly: InternalsVisibleTo("UnityEngine.SpriteShapeModule")] [assembly: InternalsVisibleTo("UnityEngine.VFXModule")] [assembly: InternalsVisibleTo("UnityEngine.TilemapModule")] [assembly: InternalsVisibleTo("UnityEngine.StreamingModule")] [assembly: InternalsVisibleTo("UnityEngine.SubstanceModule")] [assembly: InternalsVisibleTo("UnityEngine.SubsystemsModule")] [assembly: InternalsVisibleTo("UnityEngine.TerrainModule")] [assembly: InternalsVisibleTo("UnityEngine.TerrainPhysicsModule")] [assembly: InternalsVisibleTo("UnityEngine.UIModule")] [assembly: InternalsVisibleTo("UnityEngine.UIElementsModule")] [assembly: InternalsVisibleTo("UnityEngine.UmbraModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityCurlModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityTestProtocolModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityWebRequestAssetBundleModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityWebRequestAudioModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityWebRequestTextureModule")] [assembly: InternalsVisibleTo("UnityEngine.SpriteMaskModule")] [assembly: InternalsVisibleTo("UnityEngine.IMGUIModule")] [assembly: InternalsVisibleTo("Unity.RuntimeTests.Framework")] [assembly: InternalsVisibleTo("Unity.PerformanceTests.RuntimeTestRunner.Tests")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.002")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.003")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.004")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.005")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.006")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.007")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.008")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.009")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.010")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.011")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.012")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.013")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.014")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.001")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.015")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.017")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.018")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.019")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.020")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.021")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.022")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.023")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.024")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridgeDev.001")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridgeDev.002")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridgeDev.003")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridgeDev.004")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridgeDev.005")] [assembly: InternalsVisibleTo("Unity.InternalAPIEngineBridge.016")] [assembly: InternalsVisibleTo("Unity.RuntimeTests.Framework.Tests")] [assembly: InternalsVisibleTo("UnityEngine.Core.Runtime.Tests")] [assembly: InternalsVisibleTo("Unity.Runtime")] [assembly: InternalsVisibleTo("Unity.RuntimeTests.AllIn1Runner")] [assembly: InternalsVisibleTo("Unity.Timeline")] [assembly: InternalsVisibleTo("Assembly-CSharp-testable")] [assembly: InternalsVisibleTo("Assembly-CSharp-firstpass-testable")] [assembly: InternalsVisibleTo("UnityEngine.SpatialTracking")] [assembly: InternalsVisibleTo("GoogleAR.UnityNative")] [assembly: InternalsVisibleTo("Unity.WindowsMRAutomation")] [assembly: InternalsVisibleTo("Unity.RenderPipelines.Universal.2D.Runtime")] [assembly: InternalsVisibleTo("Unity.2D.Sprite.Editor")] [assembly: InternalsVisibleTo("Unity.2D.Sprite.EditorTests")] [assembly: InternalsVisibleTo("Unity.UI.Builder.Editor")] [assembly: InternalsVisibleTo("UnityEditor.UIBuilderModule")] [assembly: InternalsVisibleTo("Unity.UI.Builder.EditorTests")] [assembly: InternalsVisibleTo("Unity.Core")] [assembly: InternalsVisibleTo("Unity.UIElements")] [assembly: InternalsVisibleTo("Unity.UIElements.Editor")] [assembly: InternalsVisibleTo("Unity.UIElements.PlayModeTests")] [assembly: InternalsVisibleTo("UnityEngine.UIElements.Tests")] [assembly: InternalsVisibleTo("Unity.UIElements.EditorTests")] [assembly: InternalsVisibleTo("Unity.UIElements.RuntimeTests")] [assembly: InternalsVisibleTo("UnityEngine.UI")] [assembly: InternalsVisibleTo("Unity.Networking.Transport")] [assembly: InternalsVisibleTo("Unity.ucg.QoS")] [assembly: InternalsVisibleTo("Unity.Services.QoS")] [assembly: InternalsVisibleTo("Unity.Logging")] [assembly: InternalsVisibleTo("Unity.Entities")] [assembly: InternalsVisibleTo("Unity.Entities.Tests")] [assembly: InternalsVisibleTo("Unity.Collections")] [assembly: InternalsVisibleTo("UnityEngine.UIElementsGameObjectsModule")] [assembly: InternalsVisibleTo("UnityEngine.TextCoreTextEngineModule")] [assembly: InternalsVisibleTo("UnityEngine.InputLegacyModule")] [assembly: InternalsVisibleTo("Unity.Subsystem.Registration")] [assembly: InternalsVisibleTo("UnityEngine.AssetBundleModule")] [assembly: InternalsVisibleTo("UnityEngine.HotReloadModule")] [assembly: InternalsVisibleTo("UnityEngine.AnimationModule")] [assembly: InternalsVisibleTo("UnityEngine.AndroidJNIModule")] [assembly: InternalsVisibleTo("UnityEngine.AccessibilityModule")] [assembly: InternalsVisibleTo("UnityEngine.ARModule")] [assembly: InternalsVisibleTo("UnityEngine.InputModule")] [assembly: InternalsVisibleTo("UnityEngine.AudioModule")] [assembly: InternalsVisibleTo("UnityEngine.JSONSerializeModule")] [assembly: InternalsVisibleTo("UnityEngine.AIModule")] [assembly: InternalsVisibleTo("UnityEngine.CoreModule")] [assembly: InternalsVisibleTo("UnityEngine.SharedInternalsModule")] [assembly: InternalsVisibleTo("UnityEngine")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: InternalsVisibleTo("UnityEngine.PhysicsModule")] [assembly: InternalsVisibleTo("UnityEngine.ClothModule")] [assembly: InternalsVisibleTo("UnityEngine.ClusterInputModule")] [assembly: InternalsVisibleTo("UnityEngine.ClusterRendererModule")] [assembly: InternalsVisibleTo("UnityEngine.TextRenderingModule")] [assembly: InternalsVisibleTo("UnityEngine.HierarchyCoreModule")] [assembly: InternalsVisibleTo("UnityEngine.GridModule")] [assembly: InternalsVisibleTo("UnityEngine.GraphToolsFoundationModule")] [assembly: InternalsVisibleTo("UnityEngine.GameCenterModule")] [assembly: InternalsVisibleTo("UnityEngine.ImageConversionModule")] [assembly: InternalsVisibleTo("UnityEngine.GIModule")] [assembly: InternalsVisibleTo("UnityEngine.DirectorModule")] [assembly: InternalsVisibleTo("UnityEngine.DSPGraphModule")] [assembly: InternalsVisibleTo("UnityEngine.CrashReportingModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityAnalyticsModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityWebRequestModule")] [assembly: InternalsVisibleTo("UnityEngine.TLSModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityAnalyticsCommonModule")] [assembly: InternalsVisibleTo("UnityEngine.UnityConnectModule")] [assembly: InternalsVisibleTo("UnityEngine.ContentLoadModule")] [assembly: InternalsVisibleTo("UnityEngine.CommandStateObserverModule")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] namespace UnityEngine { [StructLayout(LayoutKind.Sequential)] [UsedByNativeCode] [NativeHeader("Modules/Subsystems/Subsystem.h")] public class IntegratedSubsystem : ISubsystem { internal static class BindingsMarshaller { public static IntPtr ConvertToNative(IntegratedSubsystem integratedSubsystem) { return integratedSubsystem.m_Ptr; } } [VisibleToOtherModules(new string[] { "UnityEngine.XRModule" })] internal IntPtr m_Ptr; internal ISubsystemDescriptor m_SubsystemDescriptor; public bool running => valid && IsRunning(); internal bool valid => m_Ptr != IntPtr.Zero; internal void SetHandle([Unmarshalled] IntegratedSubsystem subsystem) { IntPtr intPtr = BindingsMarshaller.ConvertToNative(this); if (intPtr == (IntPtr)0) { ThrowHelper.ThrowNullReferenceException((object)this); } SetHandle_Injected(intPtr, subsystem); } public void Start() { IntPtr intPtr = BindingsMarshaller.ConvertToNative(this); if (intPtr == (IntPtr)0) { ThrowHelper.ThrowNullReferenceException((object)this); } Start_Injected(intPtr); } public void Stop() { IntPtr intPtr = BindingsMarshaller.ConvertToNative(this); if (intPtr == (IntPtr)0) { ThrowHelper.ThrowNullReferenceException((object)this); } Stop_Injected(intPtr); } public void Destroy() { IntPtr ptr = m_Ptr; SubsystemManager.RemoveIntegratedSubsystemByPtr(m_Ptr); SubsystemBindings.DestroySubsystem(ptr); m_Ptr = IntPtr.Zero; } internal bool IsRunning() { IntPtr intPtr = BindingsMarshaller.ConvertToNative(this); if (intPtr == (IntPtr)0) { ThrowHelper.ThrowNullReferenceException((object)this); } return IsRunning_Injected(intPtr); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void SetHandle_Injected(IntPtr _unity_self, IntegratedSubsystem subsystem); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Start_Injected(IntPtr _unity_self); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Stop_Injected(IntPtr _unity_self); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool IsRunning_Injected(IntPtr _unity_self); } [UsedByNativeCode("Subsystem_TSubsystemDescriptor")] public class IntegratedSubsystem : IntegratedSubsystem where TSubsystemDescriptor : ISubsystemDescriptor { public TSubsystemDescriptor subsystemDescriptor => (TSubsystemDescriptor)m_SubsystemDescriptor; [Obsolete("The property 'SubsystemDescriptor' is deprecated. Use `subsystemDescriptor` instead. UnityUpgradeable -> subsystemDescriptor", false)] public TSubsystemDescriptor SubsystemDescriptor => subsystemDescriptor; } internal static class SubsystemBindings { [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void DestroySubsystem(IntPtr nativePtr); } internal interface ISubsystemDescriptorImpl : ISubsystemDescriptor { IntPtr ptr { get; set; } } [StructLayout(LayoutKind.Sequential)] [UsedByNativeCode("SubsystemDescriptorBase")] public abstract class IntegratedSubsystemDescriptor : ISubsystemDescriptorImpl, ISubsystemDescriptor { [VisibleToOtherModules(new string[] { "UnityEngine.XRModule" })] internal IntPtr m_Ptr; public string id => SubsystemDescriptorBindings.GetId(m_Ptr); IntPtr ISubsystemDescriptorImpl.ptr { get { return m_Ptr; } set { m_Ptr = value; } } ISubsystem ISubsystemDescriptor.Create() { return CreateImpl(); } internal abstract ISubsystem CreateImpl(); } [StructLayout(LayoutKind.Sequential)] [NativeHeader("Modules/Subsystems/SubsystemDescriptor.h")] [UsedByNativeCode("SubsystemDescriptor")] public class IntegratedSubsystemDescriptor : IntegratedSubsystemDescriptor where TSubsystem : IntegratedSubsystem { internal override ISubsystem CreateImpl() { return Create(); } public TSubsystem Create() { IntPtr ptr = SubsystemDescriptorBindings.Create(m_Ptr); TSubsystem val = (TSubsystem)SubsystemManager.GetIntegratedSubsystemByPtr(ptr); if (val != null) { val.m_SubsystemDescriptor = this; } return val; } } internal static class SubsystemDescriptorBindings { [MethodImpl(MethodImplOptions.InternalCall)] public static extern IntPtr Create(IntPtr descriptorPtr); public static string GetId(IntPtr descriptorPtr) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) ManagedSpanWrapper ret = default(ManagedSpanWrapper); string stringAndDispose; try { GetId_Injected(descriptorPtr, out ret); } finally { stringAndDispose = OutStringMarshaller.GetStringAndDispose(ret); } return stringAndDispose; } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void GetId_Injected(IntPtr descriptorPtr, out ManagedSpanWrapper ret); } public interface ISubsystem { bool running { get; } void Start(); void Stop(); void Destroy(); } public interface ISubsystemDescriptor { string id { get; } ISubsystem Create(); } [Obsolete("Use SubsystemWithProvider instead.", false)] public abstract class Subsystem : ISubsystem { internal ISubsystemDescriptor m_SubsystemDescriptor; public abstract bool running { get; } public abstract void Start(); public abstract void Stop(); public void Destroy() { if (SubsystemManager.RemoveDeprecatedSubsystem(this)) { OnDestroy(); } } protected abstract void OnDestroy(); } [Obsolete("Use SubsystemWithProvider<> instead.", false)] public abstract class Subsystem : Subsystem where TSubsystemDescriptor : ISubsystemDescriptor { public TSubsystemDescriptor SubsystemDescriptor => (TSubsystemDescriptor)m_SubsystemDescriptor; } [Obsolete("Use SubsystemDescriptorWithProvider instead.", false)] public abstract class SubsystemDescriptor : ISubsystemDescriptor { public string id { get; set; } public Type subsystemImplementationType { get; set; } ISubsystem ISubsystemDescriptor.Create() { return CreateImpl(); } internal abstract ISubsystem CreateImpl(); } [Obsolete("Use SubsystemDescriptorWithProvider<> instead.", false)] public class SubsystemDescriptor : SubsystemDescriptor where TSubsystem : Subsystem { internal override ISubsystem CreateImpl() { return Create(); } public TSubsystem Create() { if (SubsystemManager.FindDeprecatedSubsystemByDescriptor(this) is TSubsystem result) { return result; } TSubsystem val = Activator.CreateInstance(base.subsystemImplementationType) as TSubsystem; val.m_SubsystemDescriptor = this; SubsystemManager.AddDeprecatedSubsystem(val); return val; } } internal static class Internal_SubsystemDescriptors { [RequiredByNativeCode] internal static void Internal_AddDescriptor(SubsystemDescriptor descriptor) { SubsystemDescriptorStore.RegisterDeprecatedDescriptor(descriptor); } } [NativeHeader("Modules/Subsystems/SubsystemManager.h")] public static class SubsystemManager { private static List s_IntegratedSubsystems; private static List s_StandaloneSubsystems; private static List s_DeprecatedSubsystems; public static event Action beforeReloadSubsystems; public static event Action afterReloadSubsystems; [Obsolete("Use beforeReloadSubsystems instead. (UnityUpgradable) -> beforeReloadSubsystems", false)] public static event Action reloadSubsytemsStarted; [Obsolete("Use afterReloadSubsystems instead. (UnityUpgradable) -> afterReloadSubsystems", false)] public static event Action reloadSubsytemsCompleted; [RequiredByNativeCode] private static void ReloadSubsystemsStarted() { if (SubsystemManager.reloadSubsytemsStarted != null) { SubsystemManager.reloadSubsytemsStarted(); } if (SubsystemManager.beforeReloadSubsystems != null) { SubsystemManager.beforeReloadSubsystems(); } } [RequiredByNativeCode] private static void ReloadSubsystemsCompleted() { if (SubsystemManager.reloadSubsytemsCompleted != null) { SubsystemManager.reloadSubsytemsCompleted(); } if (SubsystemManager.afterReloadSubsystems != null) { SubsystemManager.afterReloadSubsystems(); } } [RequiredByNativeCode] private static void InitializeIntegratedSubsystem(IntPtr ptr, IntegratedSubsystem subsystem) { subsystem.m_Ptr = ptr; subsystem.SetHandle(subsystem); s_IntegratedSubsystems.Add(subsystem); } [RequiredByNativeCode] private static void ClearSubsystems() { foreach (IntegratedSubsystem s_IntegratedSubsystem in s_IntegratedSubsystems) { s_IntegratedSubsystem.m_Ptr = IntPtr.Zero; } s_IntegratedSubsystems.Clear(); s_StandaloneSubsystems.Clear(); s_DeprecatedSubsystems.Clear(); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void StaticConstructScriptingClassMap(); internal unsafe static void ReportSingleSubsystemAnalytics(string id) { //The blocks IL_0029 are reachable both inside and outside the pinned region starting at IL_0018. ILSpy has duplicated these blocks in order to place them both within and outside the `fixed` statement. try { ManagedSpanWrapper id2 = default(ManagedSpanWrapper); if (!StringMarshaller.TryMarshalEmptyOrNullString(id, ref id2)) { ReadOnlySpan readOnlySpan = id.AsSpan(); fixed (char* ptr = readOnlySpan) { ((ManagedSpanWrapper)(ref id2))..ctor((void*)ptr, readOnlySpan.Length); ReportSingleSubsystemAnalytics_Injected(ref id2); return; } } ReportSingleSubsystemAnalytics_Injected(ref id2); } finally { } } static SubsystemManager() { s_IntegratedSubsystems = new List(); s_StandaloneSubsystems = new List(); s_DeprecatedSubsystems = new List(); StaticConstructScriptingClassMap(); } public static void GetAllSubsystemDescriptors(List descriptors) { SubsystemDescriptorStore.GetAllSubsystemDescriptors(descriptors); } public static void GetSubsystemDescriptors(List descriptors) where T : ISubsystemDescriptor { SubsystemDescriptorStore.GetSubsystemDescriptors(descriptors); } public static void GetSubsystems(List subsystems) where T : ISubsystem { subsystems.Clear(); AddSubsystemSubset(s_IntegratedSubsystems, subsystems); AddSubsystemSubset(s_StandaloneSubsystems, subsystems); AddSubsystemSubset(s_DeprecatedSubsystems, subsystems); } private static void AddSubsystemSubset(List copyFrom, List copyTo) where TBaseTypeInList : ISubsystem where TQueryType : ISubsystem { foreach (TBaseTypeInList item2 in copyFrom) { if (item2 is TQueryType item) { copyTo.Add(item); } } } [VisibleToOtherModules(new string[] { "UnityEngine.XRModule" })] internal static IntegratedSubsystem GetIntegratedSubsystemByPtr(IntPtr ptr) { foreach (IntegratedSubsystem s_IntegratedSubsystem in s_IntegratedSubsystems) { if (s_IntegratedSubsystem.m_Ptr == ptr) { return s_IntegratedSubsystem; } } return null; } internal static void RemoveIntegratedSubsystemByPtr(IntPtr ptr) { for (int i = 0; i < s_IntegratedSubsystems.Count; i++) { if (!(s_IntegratedSubsystems[i].m_Ptr != ptr)) { s_IntegratedSubsystems[i].m_Ptr = IntPtr.Zero; s_IntegratedSubsystems.RemoveAt(i); break; } } } internal static void AddStandaloneSubsystem(SubsystemWithProvider subsystem) { s_StandaloneSubsystems.Add(subsystem); } internal static bool RemoveStandaloneSubsystem(SubsystemWithProvider subsystem) { return s_StandaloneSubsystems.Remove(subsystem); } internal static SubsystemWithProvider FindStandaloneSubsystemByDescriptor(SubsystemDescriptorWithProvider descriptor) { foreach (SubsystemWithProvider s_StandaloneSubsystem in s_StandaloneSubsystems) { if (s_StandaloneSubsystem.descriptor == descriptor) { return s_StandaloneSubsystem; } } return null; } [Obsolete("Use GetSubsystems instead. (UnityUpgradable) -> GetSubsystems(*)", false)] public static void GetInstances(List subsystems) where T : ISubsystem { GetSubsystems(subsystems); } internal static void AddDeprecatedSubsystem(Subsystem subsystem) { s_DeprecatedSubsystems.Add(subsystem); } internal static bool RemoveDeprecatedSubsystem(Subsystem subsystem) { return s_DeprecatedSubsystems.Remove(subsystem); } internal static Subsystem FindDeprecatedSubsystemByDescriptor(SubsystemDescriptor descriptor) { foreach (Subsystem s_DeprecatedSubsystem in s_DeprecatedSubsystems) { if (s_DeprecatedSubsystem.m_SubsystemDescriptor == descriptor) { return s_DeprecatedSubsystem; } } return null; } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void ReportSingleSubsystemAnalytics_Injected(ref ManagedSpanWrapper id); } } namespace UnityEngine.SubsystemsImplementation { [NativeHeader("Modules/Subsystems/SubsystemManager.h")] public static class SubsystemDescriptorStore { private static List s_IntegratedDescriptors = new List(); private static List s_StandaloneDescriptors = new List(); private static List s_DeprecatedDescriptors = new List(); [RequiredByNativeCode] internal static void InitializeManagedDescriptor(IntPtr ptr, IntegratedSubsystemDescriptor desc) { desc.m_Ptr = ptr; s_IntegratedDescriptors.Add(desc); } [RequiredByNativeCode] internal static void ClearManagedDescriptors() { foreach (IntegratedSubsystemDescriptor s_IntegratedDescriptor in s_IntegratedDescriptors) { s_IntegratedDescriptor.m_Ptr = IntPtr.Zero; } s_IntegratedDescriptors.Clear(); } private unsafe static void ReportSingleSubsystemAnalytics(string id) { //The blocks IL_0029 are reachable both inside and outside the pinned region starting at IL_0018. ILSpy has duplicated these blocks in order to place them both within and outside the `fixed` statement. try { ManagedSpanWrapper id2 = default(ManagedSpanWrapper); if (!StringMarshaller.TryMarshalEmptyOrNullString(id, ref id2)) { ReadOnlySpan readOnlySpan = id.AsSpan(); fixed (char* ptr = readOnlySpan) { ((ManagedSpanWrapper)(ref id2))..ctor((void*)ptr, readOnlySpan.Length); ReportSingleSubsystemAnalytics_Injected(ref id2); return; } } ReportSingleSubsystemAnalytics_Injected(ref id2); } finally { } } public static void RegisterDescriptor(SubsystemDescriptorWithProvider descriptor) { descriptor.ThrowIfInvalid(); RegisterDescriptor(descriptor, s_StandaloneDescriptors); } internal static void GetAllSubsystemDescriptors(List descriptors) { descriptors.Clear(); int num = s_IntegratedDescriptors.Count + s_StandaloneDescriptors.Count + s_DeprecatedDescriptors.Count; if (descriptors.Capacity < num) { descriptors.Capacity = num; } AddDescriptorSubset(s_IntegratedDescriptors, descriptors); AddDescriptorSubset(s_StandaloneDescriptors, descriptors); AddDescriptorSubset(s_DeprecatedDescriptors, descriptors); } private static void AddDescriptorSubset(List copyFrom, List copyTo) where TBaseTypeInList : ISubsystemDescriptor { foreach (TBaseTypeInList item in copyFrom) { copyTo.Add(item); } } internal static void GetSubsystemDescriptors(List descriptors) where T : ISubsystemDescriptor { descriptors.Clear(); AddDescriptorSubset(s_IntegratedDescriptors, descriptors); AddDescriptorSubset(s_StandaloneDescriptors, descriptors); AddDescriptorSubset(s_DeprecatedDescriptors, descriptors); } private static void AddDescriptorSubset(List copyFrom, List copyTo) where TBaseTypeInList : ISubsystemDescriptor where TQueryType : ISubsystemDescriptor { foreach (TBaseTypeInList item2 in copyFrom) { if (item2 is TQueryType item) { copyTo.Add(item); } } } internal static void RegisterDescriptor(TDescriptor descriptor, List storeInList) where TDescriptor : TBaseTypeInList where TBaseTypeInList : ISubsystemDescriptor { for (int i = 0; i < storeInList.Count; i++) { if (!(storeInList[i].id != descriptor.id)) { Debug.LogWarning((object)("Registering subsystem descriptor with duplicate ID '" + descriptor.id + "' - overwriting previous entry.")); storeInList[i] = (TBaseTypeInList)(object)descriptor; return; } } ReportSingleSubsystemAnalytics(descriptor.id); storeInList.Add((TBaseTypeInList)(object)descriptor); } internal static void RegisterDeprecatedDescriptor(SubsystemDescriptor descriptor) { RegisterDescriptor(descriptor, s_DeprecatedDescriptors); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void ReportSingleSubsystemAnalytics_Injected(ref ManagedSpanWrapper id); } public abstract class SubsystemDescriptorWithProvider : ISubsystemDescriptor { public string id { get; set; } protected internal Type providerType { get; set; } protected internal Type subsystemTypeOverride { get; set; } internal abstract ISubsystem CreateImpl(); ISubsystem ISubsystemDescriptor.Create() { return CreateImpl(); } internal abstract void ThrowIfInvalid(); } public class SubsystemDescriptorWithProvider : SubsystemDescriptorWithProvider where TSubsystem : SubsystemWithProvider, new() where TProvider : SubsystemProvider { internal override ISubsystem CreateImpl() { return Create(); } public TSubsystem Create() { if (SubsystemManager.FindStandaloneSubsystemByDescriptor(this) is TSubsystem result) { return result; } TProvider val = CreateProvider(); if (val == null) { return null; } TSubsystem val2 = ((base.subsystemTypeOverride != null) ? ((TSubsystem)Activator.CreateInstance(base.subsystemTypeOverride)) : new TSubsystem()); val2.Initialize(this, val); SubsystemManager.AddStandaloneSubsystem(val2); return val2; } internal sealed override void ThrowIfInvalid() { if (base.providerType == null) { throw new InvalidOperationException("Invalid descriptor - must supply a valid providerType field!"); } if (!base.providerType.IsSubclassOf(typeof(TProvider))) { throw new InvalidOperationException($"Can't create provider - providerType '{base.providerType.ToString()}' is not a subclass of '{typeof(TProvider).ToString()}'!"); } if (base.subsystemTypeOverride != null && !base.subsystemTypeOverride.IsSubclassOf(typeof(TSubsystem))) { throw new InvalidOperationException($"Can't create provider - subsystemTypeOverride '{base.subsystemTypeOverride.ToString()}' is not a subclass of '{typeof(TSubsystem).ToString()}'!"); } } internal TProvider CreateProvider() { TProvider val = (TProvider)Activator.CreateInstance(base.providerType); return val.TryInitialize() ? val : null; } } public abstract class SubsystemProvider { internal bool m_Running; public bool running => m_Running; } public abstract class SubsystemProvider : SubsystemProvider where TSubsystem : SubsystemWithProvider, new() { protected internal virtual bool TryInitialize() { return true; } public abstract void Start(); public abstract void Stop(); public abstract void Destroy(); } public class SubsystemProxy where TSubsystem : SubsystemWithProvider, new() where TProvider : SubsystemProvider { public TProvider provider { get; private set; } public bool running { get { return provider.running; } set { provider.m_Running = value; } } internal SubsystemProxy(TProvider provider) { this.provider = provider; } } public abstract class SubsystemWithProvider : ISubsystem { public bool running { get; private set; } internal SubsystemProvider providerBase { get; set; } internal abstract SubsystemDescriptorWithProvider descriptor { get; } public void Start() { if (!running) { OnStart(); providerBase.m_Running = true; running = true; } } protected abstract void OnStart(); public void Stop() { if (running) { OnStop(); providerBase.m_Running = false; running = false; } } protected abstract void OnStop(); public void Destroy() { Stop(); if (SubsystemManager.RemoveStandaloneSubsystem(this)) { OnDestroy(); } } protected abstract void OnDestroy(); internal abstract void Initialize(SubsystemDescriptorWithProvider descriptor, SubsystemProvider subsystemProvider); } public abstract class SubsystemWithProvider : SubsystemWithProvider where TSubsystem : SubsystemWithProvider, new() where TSubsystemDescriptor : SubsystemDescriptorWithProvider where TProvider : SubsystemProvider { public TSubsystemDescriptor subsystemDescriptor { get; private set; } protected internal TProvider provider { get; private set; } internal sealed override SubsystemDescriptorWithProvider descriptor => subsystemDescriptor; protected virtual void OnCreate() { } protected override void OnStart() { provider.Start(); } protected override void OnStop() { provider.Stop(); } protected override void OnDestroy() { provider.Destroy(); } internal sealed override void Initialize(SubsystemDescriptorWithProvider descriptor, SubsystemProvider provider) { base.providerBase = provider; this.provider = (TProvider)provider; subsystemDescriptor = (TSubsystemDescriptor)descriptor; OnCreate(); } } } namespace UnityEngine.SubsystemsImplementation.Extensions { public static class SubsystemDescriptorExtensions { public static SubsystemProxy CreateProxy(this SubsystemDescriptorWithProvider descriptor) where TSubsystem : SubsystemWithProvider, new() where TProvider : SubsystemProvider { TProvider val = descriptor.CreateProvider(); return (val != null) ? new SubsystemProxy(val) : null; } } public static class SubsystemExtensions { public static TProvider GetProvider(this SubsystemWithProvider subsystem) where TSubsystem : SubsystemWithProvider, new() where TDescriptor : SubsystemDescriptorWithProvider where TProvider : SubsystemProvider { return subsystem.provider; } } } namespace UnityEngine.Subsystems { [UsedByNativeCode] [NativeType(Header = "Modules/Subsystems/Example/ExampleSubsystem.h")] public class ExampleSubsystem : IntegratedSubsystem { internal new static class BindingsMarshaller { public static IntPtr ConvertToNative(ExampleSubsystem exampleSubsystem) { return exampleSubsystem.m_Ptr; } } public void PrintExample() { IntPtr intPtr = BindingsMarshaller.ConvertToNative(this); if (intPtr == (IntPtr)0) { ThrowHelper.ThrowNullReferenceException((object)this); } PrintExample_Injected(intPtr); } public bool GetBool() { IntPtr intPtr = BindingsMarshaller.ConvertToNative(this); if (intPtr == (IntPtr)0) { ThrowHelper.ThrowNullReferenceException((object)this); } return GetBool_Injected(intPtr); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void PrintExample_Injected(IntPtr _unity_self); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool GetBool_Injected(IntPtr _unity_self); } [UsedByNativeCode] [NativeType(Header = "Modules/Subsystems/Example/ExampleSubsystemDescriptor.h")] public class ExampleSubsystemDescriptor : IntegratedSubsystemDescriptor { internal static class BindingsMarshaller { public static IntPtr ConvertToNative(ExampleSubsystemDescriptor exampleSubsystemDescriptor) { return exampleSubsystemDescriptor.m_Ptr; } } public bool supportsEditorMode { get { IntPtr intPtr = BindingsMarshaller.ConvertToNative(this); if (intPtr == (IntPtr)0) { ThrowHelper.ThrowNullReferenceException((object)this); } return get_supportsEditorMode_Injected(intPtr); } } public bool disableBackbufferMSAA { get { IntPtr intPtr = BindingsMarshaller.ConvertToNative(this); if (intPtr == (IntPtr)0) { ThrowHelper.ThrowNullReferenceException((object)this); } return get_disableBackbufferMSAA_Injected(intPtr); } } public bool stereoscopicBackbuffer { get { IntPtr intPtr = BindingsMarshaller.ConvertToNative(this); if (intPtr == (IntPtr)0) { ThrowHelper.ThrowNullReferenceException((object)this); } return get_stereoscopicBackbuffer_Injected(intPtr); } } public bool usePBufferEGL { get { IntPtr intPtr = BindingsMarshaller.ConvertToNative(this); if (intPtr == (IntPtr)0) { ThrowHelper.ThrowNullReferenceException((object)this); } return get_usePBufferEGL_Injected(intPtr); } } [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool get_supportsEditorMode_Injected(IntPtr _unity_self); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool get_disableBackbufferMSAA_Injected(IntPtr _unity_self); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool get_stereoscopicBackbuffer_Injected(IntPtr _unity_self); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool get_usePBufferEGL_Injected(IntPtr _unity_self); } }