/// <summary> /// Synchronize the body part state of all common body parts. /// </summary> /// <remarks> /// <para> /// The caller must properly collapse the undo records if <paramref name="singleUndo"/> is false. Otherwise /// performing an undo will result in an invalid outfit state. /// </para> /// </remarks> /// <param name="to">The outfit being synchonized to. (Required)</param> /// <param name="from">The outfit state is syncronzied from. (Required)</param> /// <param name="includeStatus">Persist collider status.</param> /// <param name="includeLayer">Persist the collider layer.</param> /// <param name="includeContext">Persist the context unless it is the previous outfit's GameObject.</param> /// <param name="singleUndo"> /// If true, collapse all undo records into a single undo, otherwise the caller will perform the collapse. /// </param> /// <param name="undoLabel">The label to use for all undo records. (Required)</param> /// <returns>True if the outfit state was altered.</returns> public static bool SynchronizeState(Outfit to, Outfit from, bool includeStatus = true, bool includeLayer = true, bool includeContext = true, bool singleUndo = true, string undoLabel = "Sync BodyPart State") { if (!(to && from && to.BodyPartCount > 0 && from.BodyPartCount > 0)) { return(false); } if (singleUndo) { Undo.IncrementCurrentGroup(); } // Need more than just the body part components... Undo.RecordObjects(Outfit.UnsafeGetUndoObjects(to).ToArray(), undoLabel); bool changed = false; for (int i = 0; i < from.BodyPartCount; i++) { var prevPart = from.GetBodyPart(i); if (prevPart) { var part = to.GetBodyPart(prevPart.PartType); if (part) { changed = true; // This is close enough. BodyPart.Synchronize( part, prevPart, includeStatus, includeLayer, includeContext, from.gameObject); } } } if (singleUndo) { Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); } return(changed); }
public static void ApplyBodyPartColliderStatus(Outfit outfit, RigidbodyBehavior status, bool singleUndo = true, string undoLabel = "Set BP Collider Status") { if (AssetDatabase.Contains(outfit)) { Debug.LogError("Can't modify an outfit asset. Outfit must be in the scene.", outfit); return; } if (outfit.BodyPartCount == 0) { return; } if (singleUndo) { Undo.IncrementCurrentGroup(); } for (int i = 0; i < outfit.BodyPartCount; i++) { var bp = outfit.GetBodyPart(i); if (bp) { var rb = bp.Rigidbody; if (rb) { LizEditorGUIUtil.SetRigidbodyBehavior(rb, status, false, undoLabel); } } } if (singleUndo) { Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); } }