// implements ISpriteEditorModule

        public override void OnModuleActivate()
        {
            spriteImportMode         = SpriteFrameModule.GetSpriteImportMode(spriteEditor.GetDataProvider <ISpriteEditorDataProvider>());
            m_TextureDataProvider    = spriteEditor.GetDataProvider <ITextureDataProvider>();
            m_NameFileIdDataProvider = spriteEditor.GetDataProvider <ISpriteNameFileIdDataProvider>();
            m_SpriteDataProvider     = spriteEditor.GetDataProvider <ISpriteEditorDataProvider>();

            int width, height;

            m_TextureDataProvider.GetTextureActualWidthAndHeight(out width, out height);
            textureActualWidth  = width;
            textureActualHeight = height;

            m_RectsCache           = ScriptableObject.CreateInstance <SpriteRectModel>();
            m_RectsCache.hideFlags = HideFlags.HideAndDontSave;

            var spriteList = m_SpriteDataProvider.GetSpriteRects().ToList();

            m_RectsCache.SetSpriteRects(spriteList);
            spriteEditor.spriteRects = spriteList;

            if (m_NameFileIdDataProvider == null)
            {
                m_NameFileIdDataProvider = new DefaultSpriteNameFileIdDataProvider(spriteList);
            }
            var nameFileIdPairs = m_NameFileIdDataProvider.GetNameFileIdPairs();

            m_RectsCache.SetNameFileIdPairs(nameFileIdPairs);

            if (spriteEditor.selectedSpriteRect != null)
            {
                spriteEditor.selectedSpriteRect = m_RectsCache.spriteRects.FirstOrDefault(x => x.spriteID == spriteEditor.selectedSpriteRect.spriteID);
            }

            AddMainUI(spriteEditor.GetMainVisualContainer());
            undoSystem.RegisterUndoCallback(UndoCallback);
        }
        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);
        }