- Home /
Editor: Force Hand tool
I'm creating a plugin for the Editor that will allow me to edit meshes (vertices, edges, tris). While in edit mode (state where the mesh is editable), I would like to force the Editor to use the Hand tool. The reason is simple: with other tools, the Editor don't trigger Event.MouseUp within my OnSceneGUI.
Example:
// Force the editor to select a gameobject
Selection.activeGameObject = myGameObject;// Force the editor to enter Hand tool?
Application.activeSceneTool = SceneTool.Hand
Is there a way to achieve Tool selection in Unity 3.3?
Forcing the hand tool will also hide the default gizmo thus removing the confusion when selecting vertices / edges / tris.
Answer by mgrenier · Jul 21, 2012 at 06:16 PM
One year later...
// Switch editor tool to Hand tool
// Tool enum contains all 4 tools (Hand, Move, Rotate, Scale)
Tools.current = Tool.View;
Answer by hellcats · May 29, 2011 at 07:38 PM
These need to be called from inside OnSceneGUI.
void EnableToolGizmo() {
FieldInfo field = typeof(SceneView).GetField("s_ToolGizmoDisabled", BindingFlags.Static | BindingFlags.NonPublic);
field.SetValue(typeof(SceneView), false);
}
void DisableToolGizmo() {
FieldInfo field = typeof(SceneView).GetField("s_ToolGizmoDisabled", BindingFlags.Static | BindingFlags.NonPublic);
field.SetValue(typeof(SceneView), true);
}
I've put these lines at the top of my OnSceneGUI method and using System.Reflection;. I'm getting a "Object reference not set to an instance of an object" for the field variable.
Did I missed something?
hmm... Guess they changed it in the latest update. It was undocumented anyway. That's what you get for digging around in the dll.