I’m making a custom editor in which I’m trying to alter the rotations of the children objects of my current selection.
void offsetChildren(Transform go){
foreach(Transform child in go){
child.transform.Rotate(xRotation, yRotation, zRotation, Space.Self);
}
}
Each of the xRotation, yRotation and zRotation are float sliders.
It appears as though this might work, however, my issue is that I’m using this in the editor, via an OnGUI() and my results are not what I expected. As I increase the xRotation, it looks as though its working, however if I let off the slider, the values will continue to increase as applied in the editor. If I then switch to yRotation, the rotations will continue going in the direction they were going in when xRotation was being adjusted. And if I go from increasing to decreasing the values, it will take a while for the change to be reflected in this ongoing update.
If I go with
void offsetChildren(Transform go){
//Quaternion target = Quaternion.Euler(xRotation, yRotation, zRotation);
foreach(Transform child in go){
child.transform.localRotation=Quaternion.Euler(xRotation, yRotation, zRotation);
}
}
It responds in the editor correctly without the weird time increment effect the previous example has, but it seems to be applying the rotations in world, not locally, and it resets the rotations to zero since that is where the sliders start.
I need these adjustments to affect the objects current rotation, not reset it to zero and then adjust it, which is why I thought Rotate would be the way to go since it rotations from where each child currently is.
My other issue is how do I include an undo to all of this? If I close my editor, or simply stop editing the sliders, undo has no effect.
Any suggestions would be greatly appreciated.