Slide 25
Slide 25 text
͏͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ReferenceFinder : EditorWindow
{
private string _targetComponentName;
private List _foundAssets = new List();
private Vector2 _currentScrollPosition;
private static IEnumerable _cashedComponents;
private static Dictionary> _typeDict;
static MonoScript[] _monoScripts;
private static bool _isFirstTime = true;
//։͔Εํͱɺ։͔Εͨͱ͖ͷڍಈ
[MenuItem("ReferenceFinder/Search")]
private static void Open()
{
//։͔ΕΔࡍʹҰԠऔಘ
_cashedComponents = GetAllTypes();
GetWindow("Components Reference Finder.");
}
private void OnGUI()
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Never change Scene before reset this window");
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("This window can search active scene objects and all prefabs");
EditorGUILayout.EndHorizontal();
//EditorʹΛग़ͯ͠ɺೖྗΛ_targetComponentNameʹ֨ೲ͢Δ
EditorGUILayout.BeginHorizontal();
_targetComponentName =
EditorGUILayout.TextField("Target Component Name: ", _targetComponentName);
EditorGUILayout.EndHorizontal();
if (_foundAssets.Count > 0)
{
_currentScrollPosition = EditorGUILayout.BeginScrollView(_currentScrollPosition);
foreach (var asset in _foundAssets)
{
EditorGUILayout.ObjectField(asset.name, asset, typeof(GameObject), false);
}
EditorGUILayout.EndScrollView();
}
if (GUILayout.Button("Search"))
{
_foundAssets.Clear();
var guids = AssetDatabase.FindAssets("t:GameObject", null);
foreach (var guid in guids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
var loadAsset = AssetDatabase.LoadAssetAtPath(path);
var typeCash = GetType(_targetComponentName) ?? null;
if (typeCash == null)
{
Debug.Log("No Type Found.");
return;
}
var tmp = loadAsset.GetComponentsInChildren(GetType(_targetComponentName) ?? null);
foreach (var kari in tmp)
{
_foundAssets.Add(kari.gameObject);
}
}
var allObj = GetObjectsInAllScene();
foreach (var obj in allObj)
{
var typeCash = GetType(_targetComponentName) ?? null;
var tmp = obj.GetComponentsInChildren(GetType(_targetComponentName) ?? null);
if (typeCash == null)
{
Debug.Log("No Type Found.");
return;
}
foreach (var kari in tmp)
{
_foundAssets.Add(kari.gameObject);