/// <summary> /// Synchronize the mount 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="includeBlocked">Synchronize the mount point 'is blocked' state.</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 includeBlocked = true, bool includeContext = true, bool singleUndo = true, string undoLabel = "Sync MountPoint State") { if (!(to && from && to.MountPointCount > 0 && from.MountPointCount > 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.MountPointCount; i++) { var prevPart = from.GetMountPoint(i); if (prevPart) { var part = to.GetMountPoint(prevPart.LocationType); if (part) { changed = true; // This is close enough. MountPoint.Synchronize(part, prevPart, includeBlocked, includeContext, from.gameObject); } } } if (singleUndo) { Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); } return(changed); }