I would like to hide the default transform handles in a custom editor script. But I have no idea how to do that.
It should be the same behaviour as in the TreeCreator. If you select Tree Root Node in the inspector, you can move, rotate and scale the whole tree with handles.
But if e.g. a Branch Group is selected in the inspector, the default handle disappears. How can this be made?
Just found the solution. Unfortunately undocumented, but it works.
Tools.current = -1;
I was a little bit too fast. This also changes the transform tool. But that’s not what I actually want.
Got it. It is actually not allowed (for good reasons). It is a terrible hack, but just in case someone wants to use it too.
using UnityEditor;
using UnityEngine;
using System;
using System.Reflection;
public class ToolsSupport {
public static bool Hidden {
get {
Type type = typeof (Tools);
FieldInfo field = type.GetField ("s_Hidden", BindingFlags.NonPublic | BindingFlags.Static);
return ((bool) field.GetValue (null));
}
set {
Type type = typeof (Tools);
FieldInfo field = type.GetField ("s_Hidden", BindingFlags.NonPublic | BindingFlags.Static);
field.SetValue (null, value);
}
}
}
I love you man!
It’s nice to hear that someone else found it useful!
thanks man, this works great, but is there a way to automatically show / hide the handles based on the Object selected ? How can I monitor the active selected Object, so i can make toggling automatically ?
Ideally I would like to have a static function where i can register object that will hide the handles, so when it’s selected, the script got to know and automatically turn off the default handles.
================ EDIT ===============
Ok, I got it working, just use OnEnable() and OnDisable() to check and hide the handles manually.
thanks man.
Awesome… Thank you!
You’re welcome
It’s awesome to know that there are still people who find this useful.
The non-hacky and “correct” way of doing this is:
Tool LastTool = Tool.None;
void OnEnable()
{
LastTool = Tools.current;
Tools.current = Tool.None;
}
void OnDisable()
{
Tools.current = LastTool;
}
Do this in your editor class. This will remember the tool that was on, then set it to be no tool (thus no handles), and will restore it once they deselect the object.
Of course while they have it selected they could always select a tool again and then the handles you don’t want will reappear. But this is easy to prevent by just adding:
Tools.current = Tool.None;
somewhere in your OnSceneGUI() method. This forces it off constantly.
Hiding it with the hack works… but is not the documented way to do it and requires reflection to sneak into private fields of the Tools class. Doing that could break in the future since that’s private functionality.
David
You are right, I just realized that I also updated my code after I read about it in some release notes. I changed it and never though about it again and that’s the reason why I wasn’t aware of my own update anymore. When I posted this code, there was no public api for it, that’s why this hack was needed.
Even if Unity really does a great job, I don’t understand why there are so many dark corners in the api and why several apis can not even be accessed, like lots of Shuriken modules.
Unfortunately the hacky solution wins over the non-hacky one. In my editor, I am giving the user the ability to move around points using the exact same tools as what is provided for moving around transforms. These points appear when the user selects the game object with this script attached. However, the main gizmo is still visible, and often gets in the way, so I need to be able to disable it, while still allowing the user to switch between move and rotate tools.
I’m not sure if it was part of the API in Feb 2015, but the “hidden” property does the same thing the hack does (it sets “s_Hidden” internally).
Tools.hidden = false;
This is great! Now all we need to do is:
void OnEnable()
{
Tools.hidden = true;
}
void OnDisable()
{
Tools.hidden = false;
}
WOOOOOAH just found this, thanks i was really stuck on this one
There’s a Like button to express appreciation without dragging up a 12-year-old dead thread to the top of the list for everyone.