private WorldLockingManager()
        {
            CreateUpdaterNode();

            /// It might look nicer to pull these off into internal setup functions,
            /// but by leaving them in the constructor, these fields can be marked "readonly",
            /// which they conceptually are.
            if (Core.Plugin.HasEngine())
            {
                Plugin = new Plugin();
            }
            else
            {
                Plugin = new PluginNoop();
            }
            DiagnosticRecordings.Start(Plugin);

            headPoseTracker = new HeadPoseTrackerCamera();
            /// This should never fail. It's a null-manager.
            anchorManager = AnchorManagerNull.TryCreate(Plugin, headPoseTracker);
            Debug.Assert(anchorManager != null, "Null manager creation should never fail");

            var fm = new FragmentManager(Plugin);

            fragmentManager        = fm;
            attachmentPointManager = fm;
            /// Note the alignmentManager accesses the FragmentManager in its constructor
            /// to register for refit notifications. Either FragmentManager needs to be fully
            /// setup before constructing AlignmentManager, or that registration needs to be deferred.
            alignmentManager = new AlignmentManager(this);
        }
        private IAnchorManager SelectAnchorManager(IPlugin plugin, IHeadPoseTracker headTracker)
        {
            Debug.Log($"Select {shared.anchorSettings.anchorSubsystem} anchor manager.");
            if (AnchorManager != null)
            {
                Debug.Log("Creating new anchormanager, but have old one. Reseting it before replacing.");
                AnchorManager.Reset();
            }
            var anchorSettings = shared.anchorSettings;

#if WLT_ARFOUNDATION_PRESENT
            if (anchorSettings.anchorSubsystem == AnchorSettings.AnchorSubsystem.DONT_USE)
            {
                Debug.Log($"Trying to create ARF anchor manager on {anchorSettings.ARSessionSource.name} and {anchorSettings.ARSessionOriginSource.name}");
                AnchorManagerARF arfAnchorManager = AnchorManagerARF.TryCreate(plugin, headTracker,
                                                                               anchorSettings.ARSessionSource, anchorSettings.ARSessionOriginSource);
                if (arfAnchorManager != null)
                {
                    Debug.Log("Success creating ARF anchor manager");
                    return(arfAnchorManager);
                }
                Debug.Log("Failed to create requested AR Foundation anchor manager!");
            }
#endif // WLT_ARFOUNDATION_PRESENT
#if WLT_ARSUBSYSTEMS_PRESENT
            if (anchorSettings.anchorSubsystem == AnchorSettings.AnchorSubsystem.XRSDK)
            {
                Debug.Log($"Trying to create XR anchor manager");
                AnchorManagerXR xrAnchorManager = AnchorManagerXR.TryCreate(plugin, headTracker);
                if (xrAnchorManager != null)
                {
                    Debug.Log("Success creating XR anchor manager");
                    return(xrAnchorManager);
                }
                Debug.Log("Failed to create requested XR SDK anchor manager!");
            }
#endif // WLT_ARSUBSYSTEMS_PRESENT
#if UNITY_WSA
            if (anchorSettings.anchorSubsystem == AnchorSettings.AnchorSubsystem.WSA)
            {
                AnchorManagerWSA wsaAnchorManager = AnchorManagerWSA.TryCreate(plugin, headTracker);
                if (wsaAnchorManager != null)
                {
                    Debug.Log("Success creating WSA anchor manager");
                    return(wsaAnchorManager);
                }
                Debug.Log("Failed to create requested WSA anchor manager!");
            }
#endif // UNITY_WSA
            if (anchorSettings.anchorSubsystem != AnchorSettings.AnchorSubsystem.Null)
            {
                Debug.Log("Failure creating useful anchor manager of any type. Creating null manager");
                anchorSettings.anchorSubsystem = AnchorSettings.AnchorSubsystem.Null;
            }
            AnchorManagerNull nullAnchorManager = AnchorManagerNull.TryCreate(plugin, headTracker);
            Debug.Assert(nullAnchorManager != null, "Creation of Null anchor manager should never fail.");
            return(nullAnchorManager);
        }
        public static AnchorManagerNull TryCreate(IPlugin plugin, IHeadPoseTracker headTracker)
        {
            AnchorManagerNull anchorManager = new AnchorManagerNull(plugin, headTracker);

            return(anchorManager);
        }
Пример #4
0
        private async Task <IAnchorManager> SelectAnchorManager(IPlugin plugin, IHeadPoseTracker headTracker)
        {
#if false
            DebugLogSetup($"Select {shared.anchorSettings.anchorSubsystem} anchor manager.");
            if (AnchorManager != null)
            {
                DebugLogSetup("Creating new anchor manager, but have old one. Reseting it before replacing.");
                AnchorManager.Reset();
            }
            var anchorSettings = shared.anchorSettings;
#else
            if (AnchorManager != null)
            {
                DebugLogSetup("Creating new anchor manager, but have old one. Reseting it before replacing.");
                AnchorManager.Reset();
            }
            var anchorSettings = shared.anchorSettings;
#if UNITY_EDITOR
            if (anchorSettings.NullSubsystemInEditor)
            {
                DebugLogSetup($"Switching from {anchorSettings.anchorSubsystem} to AnchorSubsystem.Null because running in editor.");
                anchorSettings.anchorSubsystem = AnchorSettings.AnchorSubsystem.Null;
            }
#endif // UNITY_EDITOR
            DebugLogSetup($"Select {anchorSettings.anchorSubsystem} anchor manager.");
#endif
#if WLT_ARFOUNDATION_PRESENT
            if (anchorSettings.anchorSubsystem == AnchorSettings.AnchorSubsystem.ARFoundation)
            {
                DebugLogSetup($"Trying to create ARF anchor manager on {anchorSettings.ARSessionSource.name} and {anchorSettings.ARSessionOriginSource.name}");
                AnchorManagerARF arfAnchorManager = await AnchorManagerARF.TryCreate(plugin, headTracker,
                                                                                     anchorSettings.ARSessionSource, anchorSettings.ARSessionOriginSource);

                if (arfAnchorManager != null)
                {
                    DebugLogSetup("Success creating ARF anchor manager");
                    return(arfAnchorManager);
                }
                Debug.LogError("Failed to create requested AR Foundation anchor manager!");
            }
#endif // WLT_ARFOUNDATION_PRESENT
#if WLT_ARSUBSYSTEMS_PRESENT
            if (anchorSettings.anchorSubsystem == AnchorSettings.AnchorSubsystem.XRSDK)
            {
                DebugLogSetup($"Trying to create XR anchor manager");
                AnchorManagerXR xrAnchorManager = await AnchorManagerXR.TryCreate(plugin, headTracker);

                if (xrAnchorManager != null)
                {
                    DebugLogSetup("Success creating XR anchor manager");
                    return(xrAnchorManager);
                }
                Debug.LogError("Failed to create requested XR SDK anchor manager!");
            }
#endif // WLT_ARSUBSYSTEMS_PRESENT
#if UNITY_WSA && !UNITY_2020_1_OR_NEWER
            if (anchorSettings.anchorSubsystem == AnchorSettings.AnchorSubsystem.WSA)
            {
                AnchorManagerWSA wsaAnchorManager = AnchorManagerWSA.TryCreate(plugin, headTracker);
                if (wsaAnchorManager != null)
                {
                    DebugLogSetup("Success creating WSA anchor manager");
                    return(wsaAnchorManager);
                }
                Debug.LogError("Failed to create requested WSA anchor manager!");
            }
#endif // UNITY_WSA
#if WLT_ARCORE_SDK_INCLUDED
            if (anchorSettings.anchorSubsystem == AnchorSettings.AnchorSubsystem.ARCore)
            {
                AnchorManagerARCore arCoreAnchorManager = AnchorManagerARCore.TryCreate(plugin, headTracker);
                if (arCoreAnchorManager != null)
                {
                    DebugLogSetup("Success creating ARCore anchor manager");
                    return(arCoreAnchorManager);
                }
                Debug.LogError("Failed to create requested ARCore anchor manager!");
            }
#endif // WLT_ARCORE_SDK_INCLUDED
            if (anchorSettings.anchorSubsystem != AnchorSettings.AnchorSubsystem.Null)
            {
                DebugLogSetup("Failure creating useful anchor manager of any type. Creating null manager");
                anchorSettings.anchorSubsystem = AnchorSettings.AnchorSubsystem.Null;
                shared.anchorSettings          = anchorSettings;
            }
            AnchorManagerNull nullAnchorManager = AnchorManagerNull.TryCreate(plugin, headTracker);
            Debug.Assert(nullAnchorManager != null, "Creation of Null anchor manager should never fail.");
            /// No-op await here to suppress warnings if no anchor manager system which requires asynchronous startup is compiled in.
            await Task.CompletedTask;
            return(nullAnchorManager);
        }