Skip to content

Instantly share code, notes, and snippets.

@sunny352
Created February 25, 2016 09:28
Show Gist options
  • Save sunny352/513fffc7d09741f28e3d to your computer and use it in GitHub Desktop.
Save sunny352/513fffc7d09741f28e3d to your computer and use it in GitHub Desktop.
Unity编辑器环境下获取当前场景所有对象(无论是否Active)
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