private void ProcessMountPoints(Outfit outfit, GameObject context)
 {
     if (m_MountPoints)
     {
         for (int i = 0; i < outfit.MountPointCount; i++)
         {
             var item = outfit.GetMountPoint(i);
             if (item)
             {
                 item.Context = context;
             }
         }
     }
 }
        /// <summary>
        /// Synchronize the mount point state of all common mount points.
        /// </summary>
        /// <param name="to">The outfit being synchonized to. (Required)</param>
        /// <param name="from">The outfit being syncronzied from. (Required)</param>
        /// <param name="includeBlocked">Synchronize the mount point 'is blocked' state.</param>
        /// <param name="includeContext">
        /// Synchronize the context unless it is the <paramref name="from"/> object's GameObject.
        /// </param>
        public static void SynchronizeMountPointState(Outfit to, Outfit from, bool includeBlocked, bool includeContext)
        {
            if (!(from && to))
            {
                return;
            }

            for (int i = 0; i < from.MountPointCount; i++)
            {
                var prevPart = from.GetMountPoint(i);
                if (prevPart)
                {
                    var part = to.GetMountPoint(prevPart.LocationType);
                    if (part)
                    {
                        MountPoint.Synchronize(part, prevPart, includeBlocked, includeContext, from.gameObject);
                    }
                }
            }
        }
Esempio n. 3
0
        public sealed override Outfit SetOutfit(Outfit outfit, bool forceRelease)
        {
            // Warning: This method can be called by CheckOutfitLost(), so make sure no code paths trigger that
            // method.

            if (outfit)
            {
                if (outfit == m_Outfit)
                {
                    Debug.LogWarning("Outfit is already set. No action taken.", this);
                    return(null);
                }

                if (outfit && outfit.IsManaged && (outfit.Owner && outfit.Owner != gameObject))
                {
                    Debug.LogErrorFormat(this,
                                         "Outfit is managed by another object.  Can't set outfit.  Outfit: {0}, Owner: {1}",
                                         outfit.name, outfit.Owner.name);
                    return(outfit);
                }
            }

            if (forceRelease && !m_HasOutfit)
            {
                Debug.LogWarning("Force release ignored.  Body has no outfit to release.", this);
                forceRelease = false;
            }

            forceRelease = forceRelease || (m_HasOutfit && !m_Outfit);

            var origOutfit = m_Outfit ? m_Outfit : null;  // Get rid of potential destoryed reference early.

            if (m_Outfit)
            {
                m_Outfit.RemoveObserver(this);  // Keep this early.

                // Note: The state of the outfit it set at the end of the method, just before final release.

                if (m_Outfit.transform.parent == transform)
                {
                    m_Outfit.transform.parent = null;
                }

                // Preserve the outfit's position.
                DefaultMotionRoot.position = m_Outfit.MotionRoot.position;
                DefaultMotionRoot.rotation = m_Outfit.MotionRoot.rotation;

                // Assumption: The body should never be the context of outfit compoenents for an outfit it isn't
                // managing.

                for (int i = 0; i < m_Outfit.BodyPartCount; i++)
                {
                    var item = m_Outfit.GetBodyPart(i);
                    if (item && item.Context == gameObject)
                    {
                        item.Context = null;
                    }
                }

                for (int i = 0; i < m_Outfit.MountPointCount; i++)
                {
                    var item = m_Outfit.GetMountPoint(i);
                    if (item && item.Context == gameObject)
                    {
                        item.Context = null;
                    }
                }
            }

            m_Outfit    = outfit;
            m_HasOutfit = m_Outfit;

            if (m_Outfit)
            {
                m_Outfit.SetState(OutfitStatus.InUse, gameObject);
                m_Outfit.transform.parent = transform;

                // Persist the previous outfit's position.
                m_Outfit.MotionRoot.position = DefaultMotionRoot.position;
                m_Outfit.MotionRoot.rotation = DefaultMotionRoot.rotation;

                m_Outfit.AddObserver(this);  // Keep this late.
            }

            AccessoriesLocal.SetOutfit(outfit, forceRelease);
            SendOutfitChange(origOutfit, forceRelease);

            // Keep this last.  There may be outfit observers that take action when the outfit transitions state.
            // Don't want to trigger them until the outfit is truley free.
            if (origOutfit && origOutfit.Owner == gameObject)
            {
                origOutfit.SetState(OutfitStatus.Unmanaged, null);
            }

            return(origOutfit);
        }