Last active
August 29, 2015 14:00
-
-
Save tsubaki/11322629 to your computer and use it in GitHub Desktop.
ルートオブジェクト一覧を取得する
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 UnityEngine; | |
using System.Collections; | |
using System; | |
using System.Collections.Generic; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
public class GetRootInstancePrepared : MonoBehaviour { | |
public List<Transform> transformList = new List<Transform>(); | |
#if UNITY_EDITOR | |
[ContextMenu("collection")] | |
private void Collection() | |
{ | |
var transforms = Resources.FindObjectsOfTypeAll<Transform>(); | |
var rootTransforms = Array.FindAll<Transform>( transforms, (item) => item.parent == null && item.hideFlags == HideFlags.None); | |
transformList.Clear(); | |
transformList.AddRange(rootTransforms); | |
} | |
static GetRootInstancePrepared() | |
{ | |
EditorApplication.playmodeStateChanged += () => | |
{ | |
if (!EditorApplication.isPlaying && EditorApplication.isPlayingOrWillChangePlaymode) { | |
var instance = GameObject.FindObjectOfType<GetRootInstancePrepared>(); | |
if( instance == null) | |
return; | |
instance.Collection(); | |
} | |
}; | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment