DisableUndoScope.cs 962 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Animation
  4. {
  5. internal class DisableUndoScope : IDisposable
  6. {
  7. private bool m_Disposed;
  8. private ICacheUndo m_CacheUndo;
  9. private IUndo m_UndoOverride;
  10. public DisableUndoScope(ICacheUndo cacheUndo)
  11. {
  12. Debug.Assert(cacheUndo != null);
  13. m_CacheUndo = cacheUndo;
  14. m_UndoOverride = m_CacheUndo.undoOverride;
  15. m_CacheUndo.undoOverride = new DisabledUndo();
  16. }
  17. ~DisableUndoScope()
  18. {
  19. if (!m_Disposed)
  20. Debug.LogError("Scope was not disposed! You should use the 'using' keyword or manually call Dispose.");
  21. }
  22. public void Dispose()
  23. {
  24. if (m_Disposed)
  25. return;
  26. m_Disposed = true;
  27. if (m_CacheUndo != null)
  28. m_CacheUndo.undoOverride = m_UndoOverride;
  29. }
  30. }
  31. }