Пример #1
0
 /// <summary>
 /// Add an existing attachment point to this fragment.
 /// </summary>
 /// <remarks>
 /// The attachment point might currently belong to another fragment, if
 /// it is being moved from the other to this.
 /// Since this is only used internally, it operates directly on an AttachmentPoint
 /// rather than an interface to avoid an unnecessary downcast.
 /// </remarks>
 /// <param name="attachPoint"></param>
 public void AddAttachmentPoint(AttachmentPoint attachPoint)
 {
     if (attachPoint != null)
     {
         if (attachPoint.StateHandler != null)
         {
             updateStateAllAttachments += attachPoint.StateHandler;
         }
         attachPoint.HandleStateChange(State);
         attachmentList.Add(attachPoint);
     }
 }
Пример #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();
        }
Пример #3
0
        /// <summary>
        /// Notify system attachment point is no longer needed. See <see cref="IAttachmentPointManager.ReleaseAttachmentPoint"/>
        /// </summary>
        /// <param name="attachmentPoint"></param>
        public void ReleaseAttachmentPoint(IAttachmentPoint attachmentPoint)
        {
            AttachmentPoint attachPoint = attachmentPoint as AttachmentPoint;

            if (attachPoint != null)
            {
                if (attachPoint.StateHandler != null)
                {
                    updateStateAllAttachments -= attachPoint.StateHandler;
                }
                attachPoint.HandleStateChange(AttachmentPointStateType.Released);
                attachmentList.Remove(attachPoint);
            }
            else
            {
                Debug.LogError("On release, IAttachmentPoint isn't AttachmentPoint");
            }
        }
Пример #4
0
        /// <summary>
        /// Create and register a new attachment point.
        /// </summary>
        /// <remarks>
        /// The attachment point itself is a fairly opaque handle. Its effects are propagated to the client via the
        /// two handlers associated with it.
        /// The optional context attachment point provides an optional contextual hint to where in the anchor
        /// graph to bind the new attachment point.
        /// See <see cref="IAttachmentPointManager.CreateAttachmentPoint"/>.
        /// </remarks>
        /// <param name="frozenPosition">The position in the frozen space at which to start the attachment point</param>
        /// <param name="context">The optional context into which to create the attachment point (may be null)</param>
        /// <param name="locationHandler">Delegate to handle WorldLocking system adjustments to position</param>
        /// <param name="stateHandler">Delegate to handle WorldLocking connectivity changes</param>
        /// <returns>The new attachment point interface.</returns>
        public IAttachmentPoint CreateAttachmentPoint(Vector3 frozenPosition, IAttachmentPoint context,
                                                      AdjustLocationDelegate locationHandler, AdjustStateDelegate stateHandler)
        {
            FragmentId      fragmentId  = GetTargetFragmentId(context);
            AttachmentPoint attachPoint = new AttachmentPoint(locationHandler, stateHandler);

            attachPoint.ObjectPosition = frozenPosition;
            if (fragmentId.IsKnown())
            {
                SetupAttachmentPoint(plugin, attachPoint, context);

                Fragment fragment = EnsureFragment(fragmentId);
                Debug.Assert(fragment != null, "Valid fragmentId but no fragment found");
                fragment.AddAttachmentPoint(attachPoint);
            }
            else
            {
                AddPendingAttachmentPoint(attachPoint, context);
            }
            return(attachPoint);
        }
Пример #5
0
 /// <summary>
 /// Release all resources for this fragment.
 /// </summary>
 public void ReleaseAll()
 {
     updateStateAllAttachments = null;
     attachmentList.Clear();
 }
Пример #6
0
 /// <summary>
 /// Constructor, sets handlers
 /// </summary>
 /// <param name="locationHandler">Handler for positional adjustments, may be null.</param>
 /// <param name="stateHandler">Handler for connectivity adjustments, may be null.</param>
 public AttachmentPoint(AdjustLocationDelegate locationHandler, AdjustStateDelegate stateHandler)
 {
     this.LocationHandler = locationHandler;
     this.StateHandler    = stateHandler;
 }