Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active August 29, 2015 14:00
Show Gist options
  • Save tsubaki/11322629 to your computer and use it in GitHub Desktop.
Save tsubaki/11322629 to your computer and use it in GitHub Desktop.
ルートオブジェクト一覧を取得する
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