Skip to content

Instantly share code, notes, and snippets.

@gindemit
Created September 2, 2015 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gindemit/e5f16a5e9a48bed3cb25 to your computer and use it in GitHub Desktop.
Save gindemit/e5f16a5e9a48bed3cb25 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
public class FindObjectsInTheSceneHelper : EditorWindow
{
string className = "Rigidbody";
[MenuItem(MenuItemName.SceneTools + "Find Objects In Current Scene", false, MenuItemSorter.SceneToolsFind)]
private static void Init()
{
FindObjectsInTheSceneHelper window = ScriptableObject.CreateInstance<FindObjectsInTheSceneHelper>();
window.position = new Rect(Screen.width / 2, Screen.height / 2, 250, 50);
window.ShowPopup();
}
void OnGUI()
{
className = EditorGUILayout.TextField("Component:", className);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Find"))
{
GameObject[] gos = GameObjectUtilsEditor.GetAllObjectsInScene(false);
List<Object> objectsToSelect = new List<Object>();
for (int i = 0; i < gos.Length; ++i)
{
if (gos[i].GetComponent(className) != null)
{
objectsToSelect.Add(gos[i]);
}
}
Selection.objects = objectsToSelect.ToArray();
this.Close();
}
if (GUILayout.Button("Close"))
{
this.Close();
}
GUILayout.EndHorizontal();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment