void IOutfitObserver.OnStateChange(Outfit sender) { if (sender.Owner != gameObject) { Debug.LogWarningFormat(this, "Unexpected loss of outfit ownership. Outfit auto-released." + " Outfit: {0}, New owner: {1}", sender.name, sender.Owner ? sender.Owner.name : "None"); sender.RemoveObserver(this); SetOutfit(null); return; } switch (sender.Status) { case OutfitStatus.Stored: case OutfitStatus.Unmanaged: Debug.LogErrorFormat(this, "Unsupported outfit status change. Outfit auto-released." + " Outfit: {0}, Status: {1}", sender.name, sender.Status); sender.RemoveObserver(this); SetOutfit(null); return; } }
void IOutfitObserver.OnDestroy(Outfit sender, DestroyType typ, Outfit referenceOutfit) { if (m_Outfit && m_Outfit == sender) { Debug.LogError("Outfit destroyed while owned by body. Forced an unlink.", this); sender.RemoveObserver(this); SetOutfit(null, typ == DestroyType.Bake); } else { // Overkill? Debug.LogError("Internal error: Body is observing external outfit: " + sender.name, this); sender.RemoveObserver(this); } }
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; }
void IOutfitObserver.OnDestroy(Outfit sender, DestroyType typ, Outfit referenceOutfit) { if (m_Outfit == sender) { Debug.LogError("Outfit destroyed while owned by body. Soft reset performed.", this); SoftReset(); } else { // Overkill? Debug.LogError("Internal error: Body is observing external outfit: " + sender.name, this); sender.RemoveObserver(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); }