@@ -39,6 +39,10 @@ public static GenerationResult CreateMaterialSwap(GameObject targetRoot, CopiedM
3939
4040 try
4141 {
42+ // Set up Undo group for this operation
43+ Undo . SetCurrentGroupName ( "Create Material Swap" ) ;
44+ int undoGroup = Undo . GetCurrentGroup ( ) ;
45+
4246 var ( colorMenu , isNewMenu ) = EnsureColorMenu ( targetRoot ) ;
4347 var groups = MaterialSwapHelperSession . GetCopiedDataGroups ( ) ;
4448
@@ -97,6 +101,9 @@ public static GenerationResult CreateMaterialSwap(GameObject targetRoot, CopiedM
97101
98102 EditorUtility . SetDirty ( targetRoot ) ;
99103
104+ // Collapse all Undo operations into a single operation
105+ Undo . CollapseUndoOperations ( undoGroup ) ;
106+
100107 string resultMessage = isNewMenu
101108 ? $ "Created Color Menu with { groups . Count } color variations (Color{ startingColorNumber } -Color{ startingColorNumber + groups . Count - 1 } )"
102109 : $ "Added { groups . Count } color variations (Color{ startingColorNumber } -Color{ startingColorNumber + groups . Count - 1 } )";
@@ -128,6 +135,10 @@ public static GenerationResult CreateMaterialSwapPerObject(GameObject targetRoot
128135
129136 try
130137 {
138+ // Set up Undo group for this operation
139+ Undo . SetCurrentGroupName ( "Create Material Swap Per Object" ) ;
140+ int undoGroup = Undo . GetCurrentGroup ( ) ;
141+
131142 var ( colorMenu , isNewMenu ) = EnsureColorMenu ( targetRoot ) ;
132143 var groups = MaterialSwapHelperSession . GetCopiedDataGroups ( ) ;
133144
@@ -154,8 +165,11 @@ public static GenerationResult CreateMaterialSwapPerObject(GameObject targetRoot
154165 var colorVariation = new GameObject ( colorName ) ;
155166 colorVariation . transform . SetParent ( colorMenu , false ) ;
156167
168+ // Register the created GameObject with Undo system
169+ Undo . RegisterCreatedObjectUndo ( colorVariation , "Create Color Variation" ) ;
170+
157171#if MODULAR_AVATAR_INSTALLED
158- var menuItem = colorVariation . AddComponent < ModularAvatarMenuItem > ( ) ;
172+ var menuItem = Undo . AddComponent < ModularAvatarMenuItem > ( colorVariation ) ;
159173 ModularAvatarIntegration . ConfigureMenuItemAsToggle ( menuItem , colorName , colorNumber , targetRoot . name ) ;
160174#endif
161175 createdVariations . Add ( colorVariation ) ;
@@ -192,6 +206,9 @@ public static GenerationResult CreateMaterialSwapPerObject(GameObject targetRoot
192206
193207 EditorUtility . SetDirty ( targetRoot ) ;
194208
209+ // Collapse all Undo operations into a single operation
210+ Undo . CollapseUndoOperations ( undoGroup ) ;
211+
195212 string resultMessage = isNewMenu
196213 ? $ "Created Color Menu with { groups . Count } color variations (per-object components)"
197214 : $ "Added { groups . Count } color variations with per-object components";
@@ -310,8 +327,11 @@ private static (GameObject colorVariation, int nextColorNumber, string newColorN
310327 colorVariation = new GameObject ( newColorName ) ;
311328 colorVariation . transform . SetParent ( colorMenu , false ) ;
312329
330+ // Register the created GameObject with Undo system
331+ Undo . RegisterCreatedObjectUndo ( colorVariation , "Create Color Variation" ) ;
332+
313333#if MODULAR_AVATAR_INSTALLED
314- var menuItem = colorVariation . AddComponent < ModularAvatarMenuItem > ( ) ;
334+ var menuItem = Undo . AddComponent < ModularAvatarMenuItem > ( colorVariation ) ;
315335 ModularAvatarIntegration . ConfigureMenuItemAsToggle ( menuItem , newColorName , nextColorNumber , gameObjectName ) ;
316336#endif
317337 }
0 commit comments