- Home /
Show/hide wireframe for the current selected object?
The wireframe selection makes it really hard to see the items being edited. A solution is to go in the preferences and modify the alpha, but this is something that requires a lot of work every time a modification is needed.
In the docs, there is a reference to SetSelectedWireframeHidden and a script at http://docs.unity3d.com/ScriptReference/EditorUtility.SetSelectedWireframeHidden.html - unfortunately, this throws compilations errors left right and center.
// Shows / hides the wireframe of the objects in the scene.
class ShowHideWireFrame extends Editor {
@MenuItem("Examples/Show WireFrame %s")
static function Show() {
for (var s : GameObject in Selection.gameObjects) {
var rend = s.GetComponent.<Renderer>();
if(rend)
EditorUtility.SetSelectedWireframeHidden(rend, false);
}
}
@MenuItem("Examples/Show WireFrame %s", true)
static function CheckShow() {
return Selection.activeGameObject != null;
}
@MenuItem("Examples/Hide WireFrame %h")
static function Hide() {
for (var h : GameObject in Selection.gameObjects) {
var rend = h.GetComponent.<Renderer>();
if(rend)
EditorUtility.SetSelectedWireframeHidden(rend, true);
}
}
@MenuItem("Examples/Hide WireFrame %h", true)
static function CheckHide() {
return Selection.activeGameObject != null;
}
}
Has anyone been able to make this work?
Answer by FlaflaTwo · Oct 04, 2016 at 01:13 AM
I just ran into this problem, and my solution was to use GetComponentsInChildren
instead of GetComponent
on line 25. This is necessary because the renderers I was trying to disable wireframe for were children of the currently selected object. Modified code below:
using UnityEngine;
using UnityEditor;
public class ShowHideWireframeExample : EditorWindow
{
[MenuItem( "Example/Show WireFrame %s" )]
static void ShowWireframe( )
{
foreach( GameObject s in Selection.gameObjects )
{
Renderer rend = s.GetComponent<Renderer>( );
if( rend )
EditorUtility.SetSelectedWireframeHidden( rend, false );
}
}
[MenuItem( "Example/Show WireFrame %s", true )]
static bool ShowWireframeValidate( )
{
return Selection.activeGameObject != null;
}
[MenuItem( "Example/Hide WireFrame %h" )]
static void HideWireframe( )
{
foreach( GameObject s in Selection.gameObjects )
{
Renderer[] rends = s.GetComponentsInChildren<Renderer>();
foreach(Renderer rend in rends) {
if( rend )
EditorUtility.SetSelectedWireframeHidden( rend, true );
}
}
}
[MenuItem( "Example/Hide WireFrame %h", true )]
static bool HideWireframeValidate( )
{
return Selection.activeGameObject != null;
}
}
Your answer
Follow this Question
Related Questions
Bind to OnWillSaveAssets and force to save my scene 0 Answers
Move slider as moving object moves between nodes 1 Answer
How to get notification of moving a GameObject in the hierachy when editing the scene? 1 Answer
How to assign ScriptableObject reference via Editor script? 0 Answers
How can i use the Instancing in max to Place/Replace/Instantiate in Unity 3 Answers