- Home /
Persistent selection
I have a script that extends the editor so that I can add some objects to a grid, which is drawn using Debug.DrawLine. The script is a custom editor of another script, so that I can only use it when an object which contains the other one is selected. I want to make this tool into a mode that persists as long as a menu item or a checkbox in a custom window (which I have already made) is checked, so that the drawing of the debug lines would not depend on having a specific object selected. How to achieve this?
Answer by Avaista · Jul 14, 2012 at 05:07 PM
Might I recommend you check out Gizmos. http://docs.unity3d.com/Documentation/ScriptReference/Gizmos.html
"All gizmo drawing has to be done in either OnDrawGizmos or OnDrawGizmosSelected functions of the script."
Edit: I should clarify. I think that Gizmos will be more along the lines(sorry for the pun) of what you are looking for.
They can either be drawn when selected, or all the time. A public boolean can be used to turn this permanent state on and off.
public bool drawMyGrid = false;
OnDrawGizmos()
{
if(drawMyGrid)
{
OMGDrawMyGrid_PleaseDearGodImReallySorryAboutTheLengthOfTheNameOfThisFunctionImJustReallyBoredToday();
}
}
If you reallym ust have it in the editor window, you could use a public static bool. These do not save state well(read: at all) but can be used to turn on and off things from the editor window. It also has the benefit of being able to affect all instance of the gizmo bearing behavior.
Good Luck!