UndoScope.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Animation
  4. {
  5. internal class UndoScope : IDisposable
  6. {
  7. private bool m_Disposed;
  8. private ICacheUndo m_CacheUndo;
  9. public UndoScope(ICacheUndo cacheUndo, string operationName, bool incrementGroup)
  10. {
  11. Debug.Assert(cacheUndo != null);
  12. if(cacheUndo.isUndoOperationSet == false)
  13. {
  14. m_CacheUndo = cacheUndo;
  15. if(incrementGroup)
  16. m_CacheUndo.IncrementCurrentGroup();
  17. m_CacheUndo.BeginUndoOperation(operationName);
  18. }
  19. }
  20. ~UndoScope()
  21. {
  22. if (!m_Disposed)
  23. Debug.LogError("Scope was not disposed! You should use the 'using' keyword or manually call Dispose.");
  24. }
  25. public void Dispose()
  26. {
  27. if (m_Disposed)
  28. return;
  29. m_Disposed = true;
  30. if (m_CacheUndo != null)
  31. m_CacheUndo.EndUndoOperation();
  32. }
  33. }
  34. }