private void UnlinkCurrentOutfit() { if (m_Outfit) { m_Outfit.RemoveObserver(this); if (m_Outfit.Owner == gameObject) { m_Outfit.SetState(OutfitStatus.Unmanaged, null); } 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; } // Outfit may have been improperly destroyed. So always run these. m_Accessories.SetOutfit(null); m_Outfit = null; m_HasOutfit = false; }
private void LinkOutfit(Outfit outfit) { m_Accessories.SetOutfit(outfit); m_Outfit = outfit; m_HasOutfit = m_Outfit; if (m_HasOutfit) { outfit.SetState(OutfitStatus.InUse, gameObject); outfit.transform.parent = transform; // Persist the 'last' outfit position. outfit.MotionRoot.position = DefaultMotionRoot.position; outfit.MotionRoot.rotation = DefaultMotionRoot.rotation; outfit.AddObserver(this); } }
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); }