/// <summary> /// Deep copy of the SlotData. /// </summary> public SlotData Copy() { var res = new SlotData(asset); int overlayCount = overlayList.Count; res.overlayList = new List <OverlayData>(overlayCount); for (int i = 0; i < overlayCount; i++) { OverlayData overlay = overlayList[i]; if (overlay != null) { res.overlayList.Add(overlay.Duplicate()); } } return(res); }
/// <summary> /// Combine additional slot with current data. /// </summary> /// <param name="slot">Slot.</param> /// <param name="additional">If set to <c>true</c> slot will not be serialized.</param> public void MergeSlot(SlotData slot, bool additional) { if ((slot == null) || (slot.asset == null)) { return; } int overlayCount = 0; for (int i = 0; i < slotDataList.Length; i++) { if (slotDataList[i] == null) { continue; } if (slot.asset == slotDataList[i].asset) { SlotData originalSlot = slotDataList[i]; overlayCount = slot.OverlayCount; for (int j = 0; j < overlayCount; j++) { OverlayData overlay = slot.GetOverlay(j); OverlayData originalOverlay = originalSlot.GetEquivalentOverlay(overlay); if (originalOverlay != null) { // originalOverlay.CopyColors(overlay); } else { OverlayData overlayCopy = overlay.Duplicate(); if (overlayCopy.colorData.HasName()) { int sharedIndex; if (mergedSharedColors.TryGetValue(overlayCopy.colorData.name, out sharedIndex)) { overlayCopy.colorData = sharedColors[sharedIndex]; } } originalSlot.AddOverlay(overlayCopy); } } return; } } int insertIndex = slotDataList.Length; System.Array.Resize <SlotData>(ref slotDataList, slotDataList.Length + 1); if (additional) { additionalSlotCount += 1; } else { for (int i = 0; i < additionalSlotCount; i++) { slotDataList[insertIndex] = slotDataList[insertIndex - 1]; insertIndex--; } } SlotData slotCopy = slot.Copy(); overlayCount = slotCopy.OverlayCount; for (int j = 0; j < overlayCount; j++) { OverlayData overlay = slotCopy.GetOverlay(j); if (overlay.colorData.HasName()) { int sharedIndex; if (mergedSharedColors.TryGetValue(overlay.colorData.name, out sharedIndex)) { overlay.colorData = sharedColors[sharedIndex]; } } } slotDataList[insertIndex] = slotCopy; MergeMatchingOverlays(); }