public override bool ApplyRevert(bool apply) { if (apply) { if (containsMultipleSprites) { var oldNames = new List <string>(); var newNames = new List <string>(); for (int i = 0; i < m_RectsCache.spriteRects.Count; i++) { SpriteRect spriteRect = (SpriteRect)m_RectsCache.spriteRects[i]; if (string.IsNullOrEmpty(spriteRect.name)) { spriteRect.name = "Empty"; } if (!string.IsNullOrEmpty(spriteRect.originalName)) { oldNames.Add(spriteRect.originalName); newNames.Add(spriteRect.name); } } var so = new SerializedObject(m_SpriteDataProvider.targetObject); if (oldNames.Count > 0) { PatchImportSettingRecycleID.PatchMultiple(so, 213, oldNames.ToArray(), newNames.ToArray()); } so.ApplyModifiedPropertiesWithoutUndo(); } m_SpriteDataProvider.SetSpriteRects(m_RectsCache?.spriteRects.ToArray()); if (m_RectsCache != null) { undoSystem.ClearUndo(m_RectsCache); } } else { if (m_RectsCache != null) { undoSystem.ClearUndo(m_RectsCache); m_RectsCache.spriteRects = m_SpriteDataProvider.GetSpriteRects().ToList(); spriteEditor.spriteRects = m_RectsCache.spriteRects; if (spriteEditor.selectedSpriteRect != null) { spriteEditor.selectedSpriteRect = m_RectsCache.spriteRects.FirstOrDefault(x => x.spriteID == spriteEditor.selectedSpriteRect.spriteID); } } } return(true); }
public override bool ApplyRevert(bool apply) { if (apply) { if (containsMultipleSprites) { var oldNames = new List <string>(); var newNames = new List <string>(); for (int i = 0; i < m_RectsCache.spriteRects.Count; i++) { SpriteRect spriteRect = (SpriteRect)m_RectsCache.spriteRects[i]; if (string.IsNullOrEmpty(spriteRect.name)) { spriteRect.name = "Empty"; } if (!string.IsNullOrEmpty(spriteRect.originalName)) { oldNames.Add(spriteRect.originalName); newNames.Add(spriteRect.name); } } var so = new SerializedObject(m_SpriteDataProvider.targetObject); if (oldNames.Count > 0) { AssetImporter assetImporter = m_SpriteDataProvider.targetObject as AssetImporter; if (assetImporter != null) { UnityType spriteType = UnityType.FindTypeByName("Sprite"); assetImporter.RenameSubAssets(spriteType.persistentTypeID, oldNames.ToArray(), newNames.ToArray()); } } so.ApplyModifiedPropertiesWithoutUndo(); } var array = m_RectsCache != null?m_RectsCache.spriteRects.ToArray() : null; m_SpriteDataProvider.SetSpriteRects(array); if (m_RectsCache != null) { undoSystem.ClearUndo(m_RectsCache); } } else { if (m_RectsCache != null) { undoSystem.ClearUndo(m_RectsCache); m_RectsCache.spriteRects = m_SpriteDataProvider.GetSpriteRects().ToList(); spriteEditor.spriteRects = m_RectsCache.spriteRects; if (spriteEditor.selectedSpriteRect != null) { spriteEditor.selectedSpriteRect = m_RectsCache.spriteRects.FirstOrDefault(x => x.spriteID == spriteEditor.selectedSpriteRect.spriteID); } } } return(true); }
public override bool ApplyRevert(bool apply) { if (apply) { var array = m_RectsCache != null?m_RectsCache.spriteRects.ToArray() : null; m_SpriteDataProvider.SetSpriteRects(array); var spriteNames = m_RectsCache?.spriteNames; var spriteFileIds = m_RectsCache?.spriteFileIds; if (spriteNames != null && spriteFileIds != null) { var pairList = new List <SpriteNameFileIdPair>(spriteNames.Count); for (var i = 0; i < spriteNames.Count; ++i) { pairList.Add(new SpriteNameFileIdPair(spriteNames[i], spriteFileIds[i])); } m_NameFileIdDataProvider.SetNameFileIdPairs(pairList.ToArray()); } var outlineDataProvider = m_SpriteDataProvider.GetDataProvider <ISpriteOutlineDataProvider>(); var physicsDataProvider = m_SpriteDataProvider.GetDataProvider <ISpritePhysicsOutlineDataProvider>(); foreach (var rect in array) { if (rect is OutlineSpriteRect outlineRect) { if (outlineRect.outlines.Count > 0) { outlineDataProvider.SetOutlines(outlineRect.spriteID, outlineRect.outlines); physicsDataProvider.SetOutlines(outlineRect.spriteID, outlineRect.outlines); } } } if (m_RectsCache != null) { undoSystem.ClearUndo(m_RectsCache); } } else { if (m_RectsCache != null) { undoSystem.ClearUndo(m_RectsCache); var spriteList = m_SpriteDataProvider.GetSpriteRects().ToList(); m_RectsCache.SetSpriteRects(spriteList); var nameFileIdPairs = m_NameFileIdDataProvider.GetNameFileIdPairs(); m_RectsCache.SetNameFileIdPairs(nameFileIdPairs); spriteEditor.spriteRects = spriteList; if (spriteEditor.selectedSpriteRect != null) { spriteEditor.selectedSpriteRect = m_RectsCache.spriteRects.FirstOrDefault(x => x.spriteID == spriteEditor.selectedSpriteRect.spriteID); } } } return(true); }
public override bool ApplyRevert(bool apply) { if (apply) { if (containsMultipleSprites) { var oldNames = new List <string>(); var newNames = new List <string>(); var ids = new List <long>(); var names = new List <string>(); foreach (var spriteRect in m_RectsCache.spriteRects) { if (string.IsNullOrEmpty(spriteRect.name)) { spriteRect.name = "Empty"; } if (!string.IsNullOrEmpty(spriteRect.originalName)) { oldNames.Add(spriteRect.originalName); newNames.Add(spriteRect.name); } if (spriteRect.m_RegisterInternalID) { ids.Add(spriteRect.internalID); names.Add(spriteRect.name); } spriteRect.m_RegisterInternalID = false; } var so = new SerializedObject(m_SpriteDataProvider.targetObject); if (so.isValid && ids.Count > 0) { ImportSettingInternalID.RegisterInternalID(so, spriteType, ids, names); so.ApplyModifiedPropertiesWithoutUndo(); } AssetImporter assetImporter = m_SpriteDataProvider.targetObject as AssetImporter; if (oldNames.Count > 0 && assetImporter != null) { assetImporter.RenameSubAssets(spriteType.persistentTypeID, oldNames.ToArray(), newNames.ToArray()); so.ApplyModifiedPropertiesWithoutUndo(); } } var array = m_RectsCache != null?m_RectsCache.spriteRects.ToArray() : null; m_SpriteDataProvider.SetSpriteRects(array); var outlineDataProvider = m_SpriteDataProvider.GetDataProvider <ISpriteOutlineDataProvider>(); var physicsDataProvider = m_SpriteDataProvider.GetDataProvider <ISpritePhysicsOutlineDataProvider>(); foreach (var rect in array) { if (rect is OutlineSpriteRect outlineRect) { if (outlineRect.outlines.Count > 0) { outlineDataProvider.SetOutlines(outlineRect.spriteID, outlineRect.outlines); physicsDataProvider.SetOutlines(outlineRect.spriteID, outlineRect.outlines); } } } if (m_RectsCache != null) { undoSystem.ClearUndo(m_RectsCache); } } else { if (m_RectsCache != null) { undoSystem.ClearUndo(m_RectsCache); var spriteList = m_SpriteDataProvider.GetSpriteRects().ToList(); m_RectsCache.SetSpriteRects(spriteList); spriteEditor.spriteRects = spriteList; if (spriteEditor.selectedSpriteRect != null) { spriteEditor.selectedSpriteRect = m_RectsCache.spriteRects.FirstOrDefault(x => x.spriteID == spriteEditor.selectedSpriteRect.spriteID); } } } return(true); }