Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using FullInspector.Internal;
using System;
using System.Linq;
using System.Collections.Generic;
using FullInspector.Internal;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace FullInspector.Modules {
public class ViewAllSceneObjectsEditorWindow : EditorWindow {
Expand All @@ -13,6 +17,37 @@ public static void ShowWindow() {
private string _searchString = string.Empty;
private int _totalDisplayed;

private IOrderedEnumerable<GameObject> _allGameObjects;
private Dictionary<string, int> _totalSceneObjects;

private readonly Dictionary<string, bool> _scenesFoldoutState = new Dictionary<string, bool>();


private void OnEnable() {
RefreshObjects();
}


private void RefreshObjects() {
_allGameObjects = Resources.FindObjectsOfTypeAll<GameObject>().
Where(o => o != null && !EditorUtility.IsPersistent(o)).
OrderBy(o => o.scene.name);

_totalSceneObjects = new Dictionary<string, int> {[string.Empty] = 0};

foreach (var go in _allGameObjects) {
if (go.scene.name == null) {
_totalSceneObjects[string.Empty]++;
} else {
if (_totalSceneObjects.ContainsKey(go.scene.name)) {
_totalSceneObjects[go.scene.name]++;
} else {
_totalSceneObjects[go.scene.name] = 0;
}
}
}
}

public void Update() {
Repaint();
}
Expand All @@ -34,21 +69,52 @@ public void OnGUI() {
GUILayout.Label("Found " + _totalDisplayed, GUILayout.ExpandWidth(false));
_totalDisplayed = 0;
GUILayout.EndHorizontal();
if (GUILayout.Button("Refresh", GUILayout.ExpandWidth(true))) {
RefreshObjects();
}

_scroll = EditorGUILayout.BeginScrollView(_scroll);

foreach (var obj in Resources.FindObjectsOfTypeAll<GameObject>()) {
// Skip all non-scene objects
if (EditorUtility.IsPersistent(obj)) {
continue;
var currentParsingScene = default(Scene);
var didDrawDefaultSceneHeader = false;
var isFiltering = _searchString != string.Empty;

foreach (var obj in _allGameObjects) {

var currentSceneName = obj.scene.name;
if (currentSceneName == null) {
currentSceneName = string.Empty;
}

if (!_scenesFoldoutState.ContainsKey(currentSceneName)) {
_scenesFoldoutState[currentSceneName] = true;
}

if (!_totalSceneObjects.ContainsKey(currentSceneName)) {
RefreshObjects();
}

if (_searchString != string.Empty && !obj.name.ToUpper().Contains(_searchString.ToUpper())) {
var sceneHeader = didDrawDefaultSceneHeader ? "Scene: " + currentSceneName : "No scene";
sceneHeader += " (Total: " + _totalSceneObjects[currentSceneName] + ")";

if (!didDrawDefaultSceneHeader) {
didDrawDefaultSceneHeader = true;
_scenesFoldoutState[currentSceneName] = EditorGUILayout.Foldout(_scenesFoldoutState[currentSceneName], sceneHeader, true);
} else if (currentParsingScene != obj.scene) {
currentParsingScene = obj.scene;
_scenesFoldoutState[currentSceneName] = EditorGUILayout.Foldout(_scenesFoldoutState[currentSceneName], sceneHeader, true);
}

if (isFiltering && !obj.name.ToUpper().Contains(_searchString.ToUpper())) {
continue;
}

_totalDisplayed++;

if (!_scenesFoldoutState[currentSceneName]) {
continue;
}

GUILayout.BeginHorizontal();
var contentColor = GUI.contentColor;
var bgColor = GUI.backgroundColor;
Expand All @@ -61,7 +127,7 @@ public void OnGUI() {

EditorGUI.BeginDisabledGroup(!enabledPingButton);
if (enabledPingButton) {
GUI.backgroundColor = Color.blue;
GUI.backgroundColor = EditorGUIUtility.isProSkin ? Color.blue : Color.cyan;
}
if (GUILayout.Button("ping", GUILayout.Width(40))) {
EditorGUIUtility.PingObject(obj);
Expand All @@ -70,7 +136,11 @@ public void OnGUI() {

GUI.backgroundColor = Color.red;
if (GUILayout.Button("X", GUILayout.Width(20))) {
fiUtility.DestroyObject(obj);
var scene = obj.gameObject.scene;
Undo.DestroyObjectImmediate(obj);
if (scene.IsValid() && scene.isLoaded) {
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(scene);
}
}

GUI.contentColor = contentColor;
Expand Down