Ejemplo n.º 1
0
 /// <summary>
 /// Helper function for setting up the internals of an AttachmentPoint
 /// </summary>
 /// <param name="plugin">The global plugin</param>
 /// <param name="target">The attachment point to setup</param>
 /// <param name="context">The optional context <see cref="CreateAttachmentPoint"/></param>
 public static void SetupAttachmentPoint(IPlugin plugin, AttachmentPoint target, IAttachmentPoint context)
 {
     if (context != null)
     {
         AnchorId anchorId;
         Vector3  locationFromAnchor;
         plugin.CreateAttachmentPointFromSpawner(context.AnchorId, context.LocationFromAnchor, target.ObjectPosition,
                                                 out anchorId, out locationFromAnchor);
         FragmentId fragmentId = context.FragmentId;
         target.Set(fragmentId, target.ObjectPosition, anchorId, locationFromAnchor);
     }
     else
     {
         FragmentId currentFragmentId = plugin.GetMostSignificantFragmentId();
         AnchorId   anchorId;
         Vector3    locationFromAnchor;
         plugin.CreateAttachmentPointFromHead(target.ObjectPosition,
                                              out anchorId, out locationFromAnchor);
         FragmentId fragmentId = currentFragmentId;
         target.Set(fragmentId, target.ObjectPosition, anchorId, locationFromAnchor);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Absorb the contents of another fragment, emptying it.
        /// </summary>
        /// <param name="other">The fragment to lose all its contents to this.</param>
        public void AbsorbOtherFragment(Fragment other)
        {
            Debug.Assert(other != this, $"Trying to merge to and from the same fragment {FragmentId}");
            int otherCount = other.attachmentList.Count;

            for (int i = 0; i < otherCount; ++i)
            {
                AttachmentPoint att = other.attachmentList[i];
                att.Set(FragmentId, att.CachedPosition, att.AnchorId, att.LocationFromAnchor);
                if (att.StateHandler != null)
                {
                    updateStateAllAttachments += att.StateHandler;
                }
                att.HandleStateChange(State);
                attachmentList.Add(att);
            }
            other.ReleaseAll();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Run through all attachment points, get their adjustments from the plugin and apply them.
        /// </summary>
        /// <remarks>
        /// This must be called between plugin.Refreeze() and plugin.RefreezeFinish().
        /// </remarks>
        public void AdjustAll(IPlugin plugin)
        {
            int count = attachmentList.Count;

            for (int i = 0; i < count; ++i)
            {
                AttachmentPoint attach = attachmentList[i];

                AnchorId newAnchorId;
                Vector3  newLocationFromAnchor;
                Pose     adjustment;
                if (plugin.ComputeAttachmentPointAdjustment(attach.AnchorId, attach.LocationFromAnchor,
                                                            out newAnchorId, out newLocationFromAnchor, out adjustment))
                {
                    attach.Set(FragmentId, attach.CachedPosition, newAnchorId, newLocationFromAnchor);

                    attach.HandlePoseAdjustment(adjustment);
                }
                else
                {
                    Debug.Log($"No adjustment during refreeze for {attach.AnchorId.ToString()}");
                }
            }
        }