unity3d - "Undo" after editing objects in a custom editor -


i've made custom editor (extends editorwindow). editor allows edit selected objects.

the problem after press button on editor panel, pressing ctrl/cmd+zdoes nothing, it's not tracked in history.

is there command enable trace actions triggered within custom editor panel?

you can since unity doesn't automatically keeps track of objects modified scripts, have inform editor object record. can rely on unity's undo system serialized properties.

the steps are:

  1. use undo.recordobject track object before modifying it
  2. modify serializedproperty of object
  3. use editorutility.setdirty flag object modified

here's simple example:

public class testwindow : editorwindow {      static transform anobjtransform;     void ongui()      {          anobjtransform = editorguilayout.objectfield ("selected object", anobjtransform, typeof(transform), true) transform;          if (anobjtransform != null && guilayout.button("move right"))         {             undo.recordobject(anobjtransform, "move");             anobjtransform.translate(anobjtransform.right * 10f);              editorutility.setdirty(anobjtransform);         }     }     [menuitem ("test/test window")]     private static void init () {         editorwindow.getwindow<testwindow> ();      } } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -