I have an editor script and I want to call some code when the user manipulate’s a transform’s position or rotation. My current idea is to check when the user’s mouse goes from mouse down to mouse up in an Update method and then check Selection.activeTransform to see if changes were made.
Is there a built-in callback we can use? If not, how can we check whether the user is holding down the left mouse button in the scene-view from an editor script?
You could probably achieve this by retaining the previously known position and rotation and then testing for changes:
Not tested, but offers the general idea:
public class MyFoo : MonoBehaviour {
Transform _transform;
Vector3 _lastPosition;
Quaternion _lastRotation;
void Awake() {
_transform = transform;
}
void Update() {
if (_transform.position != _lastPosition ||
_transform.rotation != _lastRotation) {
_lastPosition = _transform.position;
_lastRotation = _transform.rotation;
// Position has changed, do your stuff!
}
}
}