UndoEx.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Collections.Generic;
  5. namespace O3DWB
  6. {
  7. public static class UndoEx
  8. {
  9. #region Public Static Functions
  10. public static void RecordForToolAction(UnityEngine.Object objectToRecord)
  11. {
  12. Undo.RecordObject(objectToRecord, UndoActionNames.ToolActionName);
  13. }
  14. public static void RecordForToolAction<T>(List<T> objectsToRecord) where T : UnityEngine.Object
  15. {
  16. foreach (UnityEngine.Object objectToRecord in objectsToRecord)
  17. {
  18. Undo.RecordObject(objectToRecord, UndoActionNames.ToolActionName);
  19. }
  20. }
  21. public static void IncrementCurrentGroup()
  22. {
  23. Undo.IncrementCurrentGroup();
  24. }
  25. public static void DestroyObjectImmediate(UnityEngine.Object gameObject)
  26. {
  27. Undo.DestroyObjectImmediate(gameObject);
  28. }
  29. public static void SetTransformParent(Transform transform, Transform newParentTransform)
  30. {
  31. if (transform.parent != newParentTransform)
  32. Undo.SetTransformParent(transform, newParentTransform, UndoActionNames.ToolActionName);
  33. }
  34. public static T AddComponent<T>(GameObject gameObject) where T : Component
  35. {
  36. return Undo.AddComponent<T>(gameObject);
  37. }
  38. public static void RegisterCreatedGameObject(GameObject gameObject)
  39. {
  40. Undo.RegisterCreatedObjectUndo(gameObject, UndoActionNames.ToolActionName);
  41. }
  42. public static void RegisterCreatedScriptableObject(ScriptableObject scriptableObject)
  43. {
  44. Undo.RegisterCreatedObjectUndo(scriptableObject, UndoActionNames.ToolActionName);
  45. }
  46. public static void RecordStateForGameObjects(List<GameObject> gameObjectsToRecord)
  47. {
  48. Undo.RecordObjects(gameObjectsToRecord.ToArray(), UndoActionNames.ToolActionName);
  49. }
  50. #endregion
  51. }
  52. }
  53. #endif