Created
February 25, 2016 09:28
-
-
Save sunny352/513fffc7d09741f28e3d to your computer and use it in GitHub Desktop.
Unity编辑器环境下获取当前场景所有对象(无论是否Active)
This file contains 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 System; | |
using System.Reflection; | |
using UnityEditor; | |
using UnityEngine; | |
public class EditorTools | |
{ | |
//获取场景内所有对象,无论是否Active | |
//http://wonderm.coding.io/2015/08/31/Unity-Editor-SelectAll/ | |
//感谢 白昼 | |
public static UnityEngine.Object[] GetAll() | |
{ | |
Assembly assembly = Assembly.GetAssembly(typeof(EditorWindow)); | |
Type hierarchy = assembly.GetType("UnityEditor.SceneHierarchyWindow"); | |
MethodInfo info = hierarchy.GetMethod("SelectAll", BindingFlags.NonPublic | BindingFlags.Instance); | |
var obj = ScriptableObject.CreateInstance("SceneHierarchyWindow"); | |
info.Invoke(obj, null); | |
return Selection.objects; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment