Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CodeSmile-0000011110110111/a4c1dc03542181040f77dce02286aaee to your computer and use it in GitHub Desktop.
Save CodeSmile-0000011110110111/a4c1dc03542181040f77dce02286aaee to your computer and use it in GitHub Desktop.
Editor On*GUI undo/redo example
protected virtual void OnSceneGUI()
{
HandlesTest testObject = (HandlesTest)target;
// begin monitoring for GUI changes
EditorGUI.BeginChangeCheck();
// do whatever GUI stuff that lets user change something on the testObject
var newPos = Handles.PositionHandle(testObject.transform.position, Quaternion.identity);
// did anything in the GUI change? (ie was the transform handle moved by user)
if (EditorGUI.EndChangeCheck())
{
// something changed, record that change for the object
Undo.RecordObject(testObject, "Change SomePos");
// apply the changed value to the object
testObject.SomePos = newPos;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment