Created
July 4, 2015 10:35
-
-
Save romainPechot/f9e3e301229b7bfc1d4d to your computer and use it in GitHub Desktop.
Unity editor window help finder for empty Meshfilter & MeshCollider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class CheckEmptyMesh : EditorWindow | |
{ | |
[MenuItem("Window/Check Empty Mesh")] | |
private static void Init() | |
{ | |
CheckEmptyMesh _window = GetWindow<CheckEmptyMesh>(); | |
_window.title = "Check Empty"; | |
_window.Show(); | |
}// Init() | |
private static Transform root; | |
private static MeshFilter[] emptyMeshes = new MeshFilter[]{}; | |
private static bool foldoutEmptyMeshes = false; | |
private static Vector2 scrollEmptyMeshes = Vector2.zero; | |
private static bool checkForCollider = false; | |
private static MeshCollider[] emptyColliders = new MeshCollider[]{}; | |
private static bool foldoutEmptyCollider = false; | |
private static Vector2 scrollEmptyCollider = Vector2.zero; | |
private void OnGUI() | |
{ | |
// pick root | |
root = (Transform)EditorGUILayout.ObjectField("Root", root, typeof(Transform), true); | |
// clear root | |
if(GUILayout.Button("Clear")) root = null; | |
// warning | |
EditorGUILayout.HelpBox("If no root is picked, it will search the entire scene.", MessageType.Info); | |
// mesh collider ? | |
checkForCollider = EditorGUILayout .Toggle("Mesh Collider",checkForCollider); | |
// search ? | |
if(GUILayout.Button("Search")) | |
{ | |
FindEmptyMeshes(root); | |
if(checkForCollider) FindEmptyCollider(root); | |
} | |
EditorGUILayout.Space(); | |
// show meshes | |
if(emptyMeshes != null && emptyMeshes.Length > 0) | |
{ | |
// foldout | |
foldoutEmptyMeshes = EditorGUILayout.Foldout(foldoutEmptyMeshes, "Empty Meshes Filters"); | |
if(foldoutEmptyMeshes) | |
{ | |
// scrollview | |
scrollEmptyMeshes = EditorGUILayout.BeginScrollView(scrollEmptyMeshes); | |
// indent | |
EditorGUI.indentLevel++; | |
for(int i = 0; i < emptyMeshes.Length; i++) | |
{ | |
if(GUILayout.Button(emptyMeshes[i].name)) Selection.activeGameObject = emptyMeshes[i].gameObject; | |
}//for() | |
// end scrollview | |
EditorGUILayout.EndScrollView(); | |
} | |
} | |
// show collider | |
if(emptyColliders != null && emptyColliders.Length > 0) | |
{ | |
// foldout | |
foldoutEmptyCollider = EditorGUILayout.Foldout(foldoutEmptyCollider, "Empty Meshes Colliders"); | |
if(foldoutEmptyCollider) | |
{ | |
// scrollview | |
scrollEmptyCollider = EditorGUILayout.BeginScrollView(scrollEmptyCollider); | |
EditorGUI.indentLevel++; | |
for(int i = 0; i < emptyColliders.Length; i++) | |
{ | |
if(GUILayout.Button(emptyColliders[i].name)) Selection.activeGameObject = emptyColliders[i].gameObject; | |
}//for() | |
// end scrollview | |
EditorGUILayout.EndScrollView(); | |
} | |
} | |
}// OnGUI() | |
private void FindEmptyMeshes(Transform root) | |
{ | |
List<MeshFilter> lmf = new List<MeshFilter>(); | |
if(root) | |
{ | |
emptyMeshes = root.GetComponentsInChildren<MeshFilter>(true); | |
} | |
else | |
{ | |
emptyMeshes = GameObject.FindObjectsOfType<MeshFilter>(); | |
} | |
lmf = new List<MeshFilter>(emptyMeshes.Length); | |
for(int i = 0; i < emptyMeshes.Length; i++) | |
{ | |
if(emptyMeshes[i].sharedMesh == null) lmf.Add(emptyMeshes[i]); | |
}// for() | |
emptyMeshes = lmf.ToArray(); | |
}// FindEmptyMeshes() | |
private void FindEmptyCollider(Transform root) | |
{ | |
List<MeshCollider> lmc = new List<MeshCollider>(); | |
if(root) | |
{ | |
emptyColliders = root.GetComponentsInChildren<MeshCollider>(true); | |
} | |
else | |
{ | |
emptyColliders = GameObject.FindObjectsOfType<MeshCollider>(); | |
} | |
lmc = new List<MeshCollider>(emptyColliders.Length); | |
for(int i = 0; i < emptyColliders.Length; i++) | |
{ | |
if(emptyColliders[i].sharedMesh == null) lmc.Add(emptyColliders[i]); | |
}// for() | |
emptyColliders = lmc.ToArray(); | |
}// FindEmptyCollider() | |
}// CheckEmptyMesh : EditorWindow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment