|
*Edit: Solution below in edited code. //////////////////////////////////////////////////// I've been trying to incorporate undo functionality for my custom editor script for a few hours now, with no success. I've tried all functions associated with the "undo" class, but I just cannot get it to work. Can someone please explain the proper way to get a slider value tied into the undo system? The (fixed) code I now have:
(comments are locked)
|
I followed the links to get to this code. I tested it and it works, however for some strange reason I get imprecision for the value when I try to undo. 0.1 might become 0.123 et.c. Also, if you select the text box with the value, then drag the slider, you will be creating snapshots for every single frame for some reason. I tried to make the code so it only create a snapshot when the mouse button is released but I couldn't get any input code working (Neither Input.GetMouseButtonXxx nor Event.current.button worked for me)! If you know a way to handle this case you might get a better solution. Edit: You might get this to work if you set Anyhow, there's 5 changes to your code. See comments in code, they are also numbered for ease.
Worth noting is that it seems there is a slight delay from when you press CTRL + Z (Undo shortcut) to the actual value is undone. This doesn't seem to be the case if the text box is selected when you do this. I don't know why this happens. Maybe I am overlooking something or maybe it's some mechanic of UnityEditor that does this. Edit: After further investigation it seems that OnGUI isn't called continously. It is only called when the user interacts with the GUI. This causes the lag inside the editor window since it isn't repainted. I fixed this by adding Repaint to key modifiers although it might not be the best way to go about. It solved this particlular case however and I've updated the code. And the code follows: Thanks, it appears that the "static" and "serializable" changes were the reason I could never get results. The imprecision is not acceptable though, because these sliders are intended to adjust RGB values. It still gets me further than what I had so if nothing else comes along today I will mark your answer as accepted. Thanks again ;)
Mar 15 '11 at 05:12 PM
reissgrant
It might be the imprecision can be solved using wantsMouseMove. I think it can be due the editor not picking up the "last" gui update. What you can do if you want to force gui updates is to call Repaint in Update() instead of using the delegate in init. Have a try with that and report back if it works so people can reap the benefits of collaborative wisdom :)
Mar 15 '11 at 05:21 PM
Statement ♦♦
Ok I found a solution to the imprecision bug, and updated my code in my first post to reflect my solution. Thanks again Statement!
Mar 15 '11 at 05:22 PM
reissgrant
(comments are locked)
|
