private void ProcessBodyParts(Outfit outfit, GameObject context)
 {
     if (m_BodyParts)
     {
         for (int i = 0; i < outfit.BodyPartCount; i++)
         {
             var item = outfit.GetBodyPart(i);
             if (item)
             {
                 item.Context = context;
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Synchronize the body part state of all common body parts.
        /// </summary>
        /// <param name="to">The outfit being synchonized to. (Required)</param>
        /// <param name="from">The outfit state is syncronzied from. (Required)</param>
        /// <param name="includeStatus">Synchronize the collider status.</param>
        /// <param name="includeLayer">Synchronize the collider layer.</param>
        /// <param name="includeContext">
        /// Synchronize the context unless it is the <paramref name="from"/> object's GameObject.
        /// </param>
        public static void SynchronizeBodyPartState(
            Outfit to, Outfit from, bool includeStatus, bool includeLayer, bool includeContext)
        {
            if (!(from && to))
            {
                return;
            }

            for (int i = 0; i < from.BodyPartCount; i++)
            {
                var prevPart = from.GetBodyPart(i);
                if (prevPart)
                {
                    var part = to.GetBodyPart(prevPart.PartType);
                    if (part)
                    {
                        BodyPart.Synchronize(
                            part, prevPart, includeStatus, includeLayer, includeContext, from.gameObject);
                    }
                }
            }
        }
Exemplo 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);
        }