UndoUtils.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.Profiling;
  4. using UnityEngine.Internal;
  5. using System;
  6. namespace AmplifyShaderEditor
  7. {
  8. public class UndoUtils
  9. {
  10. public static void RegisterUndoRedoCallback( Undo.UndoRedoCallback onUndoRedo )
  11. {
  12. if ( Preferences.User.EnableUndo )
  13. {
  14. Undo.undoRedoPerformed -= onUndoRedo;
  15. Undo.undoRedoPerformed += onUndoRedo;
  16. }
  17. }
  18. public static void UnregisterUndoRedoCallback( Undo.UndoRedoCallback onUndoRedo )
  19. {
  20. if ( Preferences.User.EnableUndo )
  21. {
  22. Undo.undoRedoPerformed -= onUndoRedo;
  23. }
  24. }
  25. public static void RegisterCompleteObjectUndo( UnityEngine.Object objectToUndo, string name )
  26. {
  27. if ( Preferences.User.EnableUndo )
  28. {
  29. Profiler.BeginSample( "Undo_RegisterCompleteObjectUndo" );
  30. Undo.RegisterCompleteObjectUndo( objectToUndo, name );
  31. Profiler.EndSample();
  32. }
  33. }
  34. public static void RegisterCreatedObjectUndo( UnityEngine.Object objectToUndo, string name )
  35. {
  36. if ( Preferences.User.EnableUndo )
  37. {
  38. Profiler.BeginSample( "Undo_RegisterCreatedObjectUndo" );
  39. Undo.RegisterCreatedObjectUndo( objectToUndo, name );
  40. Profiler.EndSample();
  41. }
  42. }
  43. public static void ClearUndo( UnityEngine.Object obj )
  44. {
  45. if ( Preferences.User.EnableUndo )
  46. {
  47. Profiler.BeginSample( "Undo_ClearUndo" );
  48. Undo.ClearUndo( obj );
  49. Profiler.EndSample();
  50. }
  51. }
  52. public static void RecordObject( UnityEngine.Object objectToUndo, string name )
  53. {
  54. if ( Preferences.User.EnableUndo )
  55. {
  56. Profiler.BeginSample( "Undo_RecordObject" );
  57. Undo.RecordObject( objectToUndo, name );
  58. Profiler.EndSample();
  59. }
  60. }
  61. public static void RecordObjects( UnityEngine.Object[] objectsToUndo, string name )
  62. {
  63. if ( Preferences.User.EnableUndo )
  64. {
  65. Profiler.BeginSample( "Undo_RecordObjects" );
  66. Undo.RecordObjects( objectsToUndo, name );
  67. Profiler.EndSample();
  68. }
  69. }
  70. public static void DestroyObjectImmediate( UnityEngine.Object objectToUndo )
  71. {
  72. if ( Preferences.User.EnableUndo )
  73. {
  74. Profiler.BeginSample( "Undo_DestroyObjectImmediate" );
  75. Undo.DestroyObjectImmediate( objectToUndo );
  76. Profiler.EndSample();
  77. }
  78. }
  79. public static void PerformUndo()
  80. {
  81. if ( Preferences.User.EnableUndo )
  82. {
  83. Profiler.BeginSample( "Undo_PerformUndo" );
  84. Undo.PerformUndo();
  85. Profiler.EndSample();
  86. }
  87. }
  88. public static void PerformRedo()
  89. {
  90. if ( Preferences.User.EnableUndo )
  91. {
  92. Profiler.BeginSample( "Undo_PerformRedo" );
  93. Undo.PerformRedo();
  94. Profiler.EndSample();
  95. }
  96. }
  97. public static void IncrementCurrentGroup()
  98. {
  99. if ( Preferences.User.EnableUndo )
  100. {
  101. Profiler.BeginSample( "Undo_IncrementCurrentGroup" );
  102. Undo.IncrementCurrentGroup();
  103. Profiler.EndSample();
  104. }
  105. }
  106. }
  107. }