/// <summary>
        /// Bring WorldLocking to a well-defined, empty state
        /// </summary>
        public void Reset()
        {
            AnchorManager.Reset();
            FragmentManager.Reset();
            AlignmentManager.ClearAlignmentAnchors();
            AlignmentManager.SendAlignmentAnchors();

            Plugin.ClearFrozenAnchors();
            Plugin.ResetAlignment(Pose.identity);
        }
Beispiel #2
0
 /// <summary>
 /// Go back to initial state, including removal of self-artifacts from alignment manager.
 /// </summary>
 public virtual void Reset()
 {
     if (PinActive)
     {
         AlignmentManager.RemoveAlignmentAnchor(AnchorId);
         AnchorId = AnchorId.Unknown;
         ReleaseAttachment();
         Debug.Assert(!PinActive);
         SendAlignmentData(AlignmentManager);
     }
 }
 /// <summary>
 /// Create the alignmentManager if needed.
 /// </summary>
 /// <remarks>
 /// The AlignmentManager, though mostly independent, does have a dependency on the WorldLockingManager.
 /// The WorldLockingManager can't be created until Start/OnEnable (whichever comes first). So even
 /// though the AlignmentManager isn't a Unity derived type, it is still limited on how early it can
 /// be created.
 /// </remarks>
 private void CheckInternalWiring()
 {
     if (alignmentManager == null)
     {
         alignmentManager = new AlignmentManager(WorldLockingManager.GetInstance());
         alignmentManager.SaveFileName = SaveFileName;
     }
     if (subTree == null)
     {
         subTree = transform;
     }
 }
Beispiel #4
0
        /// <summary>
        /// Callback on notification of the alignment manager's database to check
        /// if this preset has been persisted, and restore it to operation if it has.
        /// </summary>
        protected virtual void RestoreOnLoad()
        {
            CheckDependencies();

            AnchorId = AlignmentManager.RestoreAlignmentAnchor(AnchorName, ModelingPoseGlobal);
            if (PinActive)
            {
                Pose restorePose;
                bool found = AlignmentManager.GetAlignmentPose(AnchorId, out restorePose);
                Debug.Assert(found);
                lockedPose = restorePose;
            }
            CheckAttachment();
        }
        /// <summary>
        /// Callback on notification of the alignment manager's database to check
        /// if this preset has been persisted, and restore it to operation if it has.
        /// </summary>
        protected virtual void RestoreOnLoad()
        {
            CheckDependencies();

            AnchorId = AlignmentManager.RestoreAlignmentAnchor(AnchorName, ModelingPoseGlobal);
            if (PinActive)
            {
                Pose restorePose;
                bool found = AlignmentManager.GetAlignmentPose(AnchorId, out restorePose);
                Debug.Assert(found);
                lockedPose = restorePose;
            }
            //Debug.Log($"PinActive={PinActive}: id={AnchorId}, n={AnchorName}, mpg={ModelingPoseGlobal}, lp={lockedPose}");
            CheckAttachment();
        }
        /// <summary>
        /// Load the WorldLocking state in a background task
        /// </summary>
        private async Task loadAsync()
        {
            if (hasPendingLoadTask || hasPendingSaveTask)
            {
                return;
            }

            hasPendingLoadTask = true;

            try
            {
                // reset in any case to guarantee clean state even if no files have been read successfully
                Reset();

                string[] tryFileNames = { stateFileNameBase, stateFileNameBase + ".old" };

                foreach (var fileName in tryFileNames)
                {
                    if (File.Exists(fileName))
                    {
                        using (var file = File.OpenRead(fileName))
                        {
                            using (var pds = Plugin.CreateDeserializer())
                            {
                                pds.IncludePersistent = true;
                                pds.IncludeTransient  = false;
                                await pds.ReadRecordFromAsync(file);

                                pds.ApplyRecord();
                            }
                        }
                        await AnchorManager.LoadAnchors();

                        if (AnchorManager.SupportsPersistence)
                        {
                            AlignmentManager.Load();
                        }

                        // finish when reading was successful
                        return;
                    }
                }
            }
            finally
            {
                hasPendingLoadTask = false;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Create the alignmentManager if needed.
        /// </summary>
        /// <remarks>
        /// The AlignmentManager, though mostly independent, does have a dependency on the WorldLockingManager.
        /// The WorldLockingManager can't be created until Start/OnEnable (whichever comes first). So even
        /// though the AlignmentManager isn't a Unity derived type, it is still limited on how early it can
        /// be created.
        /// </remarks>
        private void CheckInternalWiring()
        {
            if (alignmentManager == null)
            {
                alignmentManager = new AlignmentManager(WorldLockingManager.GetInstance());
                alignmentManager.SaveFileName = SaveFileName;

                OnAlignManagerCreated?.Invoke(this, alignmentManager);
            }
            if (subTree == null)
            {
                subTree = transform;
            }
            if (orienter == null)
            {
                orienter = GetComponentInChildren <Orienter>();
                Debug.LogWarning($"No Orienter found on {name}, implicit Orienter found in subtree is {(orienter == null ? "null" : orienter.name)}");
            }
            if (Orienter != null)
            {
                Orienter.AlignmentManager = alignmentManager;
            }
        }
Beispiel #8
0
 /// <summary>
 /// On destroy, unregister for the loaded event.
 /// </summary>
 protected virtual void OnDestroy()
 {
     AlignmentManager.UnregisterForLoad(RestoreOnLoad);
 }