Is it possible to control the current transform tool (Pan, translate, rotate or scale) with a simple line like
Editor.transformTool = TransformTool.Rotate;
The reason I want to do this is I'm doing a custom editor script where you can click a button in the inspector, then an object in the scene view, which will affect the object to some variable. If the transform tool is different from pan, the click is ignored by my script and the object is simply selected. I hear there is the function Event.current.Use();, but it doesn't seems to help.
[ EDIT ] Just to be clear, here is the code I'm talking about, without useless stuff :
class ObjectEditor extends Editor
{
private var pick = false;
private var selection : GameObject = null;
function OnInspectorGUI ()
{
var str : String = selection ? selection.name : "null";
// Create a button in the inspector with the name f the selection displayed in it.
// If you click it, you enter the picking mode and the next click in the scene view will pick an object.
GUILayout.BeginHorizontal ();
var r : Rect = EditorGUILayout.BeginHorizontal ("Button");
if (GUI.Button (r, GUIContent.none))
pick = !pick;
GUILayout.Label (str);
EditorGUILayout.EndHorizontal ();
GUILayout.EndHorizontal ();
}
function OnSceneGUI()
{
// If this is a click and if we are in picking mode
// The problem is that if you click in the scene view, you loose
// the focus on your object, so this code isn't executed.
if( Event.current.type == EventType.MouseUp && pick )
{
// We are going to cast a ray through the scene to pick an object.
var R : Ray = HandleUtility.GUIPointToWorldRay( Event.current.mousePosition );
var H : RaycastHit;
if( Physics.Raycast( R, H, Mathf.Infinity ) )
{
pick = false;
selection = H.collider.gameObject;
Repaint(); // Display the name right now.
}
// Supposed to "eat" the event, prenting it to do something else. I guess the selection by Unity occurs before.
Event.current.Use();
}
}
}
[ EDIT 2 ] To be thorough, OnSceneGUI is executed once with a MouseDown in any cases. But then, the focus is lost.