Created
March 5, 2023 11:20
-
-
Save CodeSmile-0000011110110111/a4c1dc03542181040f77dce02286aaee to your computer and use it in GitHub Desktop.
Editor On*GUI undo/redo example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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