void ISpriteEditorDataProvider.SetSpriteRects(SpriteRect[] spriteRects) { if (spriteImportMode != SpriteImportMode.Multiple && spriteImportMode != SpriteImportMode.None && spriteRects.Length == 1) { m_SpriteSingle.CopyFromSpriteRect(spriteRects[0]); } else if (spriteImportMode == SpriteImportMode.Multiple) { for (int i = m_SpritesMultiple.Count - 1; i >= 0; --i) { var spriteID = m_SpritesMultiple[i].spriteID; if (spriteRects.FirstOrDefault(x => x.spriteID == spriteID) == null) { m_SpritesMultiple.RemoveAt(i); } } for (int i = 0; i < spriteRects.Length; i++) { var spriteRect = spriteRects[i]; var index = m_SpritesMultiple.FindIndex(x => x.spriteID == spriteRect.spriteID); if (-1 == index) { m_SpritesMultiple.Add(new SpriteDataExt(spriteRect)); } else { m_SpritesMultiple[index].CopyFromSpriteRect(spriteRects[i]); } } } }
void ISpriteEditorDataProvider.SetSpriteRects(SpriteRect[] spriteRects) { if (spriteImportMode != SpriteImportMode.Multiple && spriteImportMode != SpriteImportMode.None && spriteRects.Length == 1) { m_SpriteSingle.CopyFromSpriteRect(spriteRects[0]); } else if (spriteImportMode == SpriteImportMode.Multiple) { Dictionary <GUID, SpriteRect> newSprites = new Dictionary <GUID, SpriteRect>(); foreach (var newSprite in spriteRects) { newSprites.Add(newSprite.spriteID, newSprite); } for (int i = m_SpritesMultiple.Count - 1; i >= 0; --i) { var spriteID = m_SpritesMultiple[i].spriteID; if (newSprites.TryGetValue(spriteID, out SpriteRect smd)) { m_SpritesMultiple[i].CopyFromSpriteRect(smd); newSprites.Remove(spriteID); } else { m_SpritesMultiple.RemoveAt(i); } } // Add new ones foreach (var newSprite in newSprites.Values) { m_SpritesMultiple.Add(new SpriteDataExt(newSprite)); } } }
void ISpriteEditorDataProvider.SetSpriteRects(SpriteRect[] spriteRects) { if (spriteImportMode != SpriteImportMode.Multiple && spriteImportMode != SpriteImportMode.None && spriteRects.Length == 1) { m_SpriteSingle.CopyFromSpriteRect(spriteRects[0]); } else if (spriteImportMode == SpriteImportMode.Multiple) { Dictionary <GUID, SpriteRect> newSprites = new Dictionary <GUID, SpriteRect>(); foreach (var newSprite in spriteRects) { newSprites.Add(newSprite.spriteID, newSprite); } HashSet <long> internalIdUsed = new HashSet <long>(); for (int i = m_SpritesMultiple.Count - 1; i >= 0; --i) { var spriteID = m_SpritesMultiple[i].spriteID; if (newSprites.TryGetValue(spriteID, out SpriteRect smd)) { m_SpritesMultiple[i].CopyFromSpriteRect(smd); internalIdUsed.Add(m_SpritesMultiple[i].internalID); newSprites.Remove(spriteID); } else { m_SpritesMultiple.RemoveAt(i); } } // Add new ones var nameIdTable = GetSerializedNameFileIdTable(GetSerializedObject()); // First pass map by id var values = newSprites.Values.ToArray(); foreach (var newSprite in values) { var newSpriteRect = new SpriteDataExt(newSprite); var nameIdPair = nameIdTable.FirstOrDefault(x => x.GetFileGUID() == newSprite.spriteID); if (nameIdPair != null && !internalIdUsed.Contains(nameIdPair.internalID)) { newSpriteRect.internalID = nameIdPair.internalID; internalIdUsed.Add(nameIdPair.internalID); m_SpritesMultiple.Add(newSpriteRect); newSprites.Remove(newSprite.spriteID); } } //Second pass map by name foreach (var newSprite in newSprites.Values) { var newSpriteRect = new SpriteDataExt(newSprite); var nameIdPair = nameIdTable.FirstOrDefault(x => x.name == newSprite.name); if (nameIdPair != null && !internalIdUsed.Contains(nameIdPair.internalID)) { newSpriteRect.internalID = nameIdPair.internalID; } internalIdUsed.Add(newSpriteRect.internalID); m_SpritesMultiple.Add(newSpriteRect); } } }