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); } } }
void ISpriteEditorDataProvider.InitSpriteEditorDataProvider() { var so = new SerializedObject(m_TextureImporter); var spriteSheetSO = so.FindProperty("m_SpriteSheet.m_Sprites"); m_SpritesMultiple = new List <SpriteDataExt>(); m_SpriteSingle = new SpriteDataExt(so); for (int i = 0; i < spriteSheetSO.arraySize; ++i) { var sp = spriteSheetSO.GetArrayElementAtIndex(i); var data = new SpriteDataExt(sp); m_SpritesMultiple.Add(data); } }
internal SpriteDataExt(SpriteDataExt sr) { originalName = sr.originalName; name = sr.name; border = sr.border; tessellationDetail = 0; rect = sr.rect; spriteID = sr.spriteID; m_InternalID = sr.internalID; alignment = sr.alignment; pivot = sr.pivot; spriteOutline = new List <Vector2[]>(); vertices = new List <Vertex2DMetaData>(); indices = new List <int>(); edges = new List <Vector2Int>(); spritePhysicsOutline = new List <Vector2[]>(); spriteBone = new List <SpriteBone>(); }
void ISpriteEditorDataProvider.InitSpriteEditorDataProvider() { var so = GetSerializedObject(); var spriteSheetSO = so.FindProperty("m_SpriteSheet.m_Sprites"); m_SpritesMultiple = new List <SpriteDataExt>(); m_SpriteSingle = new SpriteDataExt(so); if (spriteSheetSO.arraySize > 0) { var sp = spriteSheetSO.GetArrayElementAtIndex(0); for (int i = 0; i < spriteSheetSO.arraySize; ++i) { var data = new SpriteDataExt(sp); m_SpritesMultiple.Add(data); sp.Next(false); } } m_SecondaryTextureDataTransfer = SpriteSecondaryTextureDataTransfer.Load(so); }