Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created April 23, 2014 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/11218517 to your computer and use it in GitHub Desktop.
Save tsubaki/11218517 to your computer and use it in GitHub Desktop.
ヒエラルキーから選択したオブジェクトを消す
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class HideObjectManager : MonoBehaviour
{
#if UNITY_EDITOR
public List<GameObject> hideObjectList = new List<GameObject> ();
static HideObjectManager GetInstance ()
{
var item = FindObjectOfType<HideObjectManager> ();
if (item == null) {
item = new GameObject ("HideObjectManager").AddComponent<HideObjectManager> ();
item.gameObject.tag = "EditorOnly";
item.gameObject.hideFlags |= HideFlags.HideInHierarchy;
item.gameObject.SetActive (!item.gameObject.activeSelf);
item.gameObject.SetActive (!item.gameObject.activeSelf);
}
return item;
}
[UnityEditor.MenuItem("GameObject/HideObject/Hide")]
static void Hide ()
{
var activeObjects = UnityEditor.Selection.gameObjects;
var hideObject = GetInstance ();
foreach( var item in activeObjects )
{
HideAllChild(item , hideObject);
}
}
static void HideAllChild (GameObject item, HideObjectManager hideObject)
{
item.hideFlags |= HideFlags.HideInHierarchy;
hideObject.hideObjectList.Add (item);
item.gameObject.SetActive (!item.gameObject.activeSelf);
item.gameObject.SetActive (!item.gameObject.activeSelf);
for (int i=0; i < item.transform.childCount; i++) {
var subItem = item.transform.GetChild (i).gameObject;
HideAllChild(subItem, hideObject);
}
}
[UnityEditor.MenuItem("GameObject/HideObject/Show")]
static void Show ()
{
var hideObject = GetInstance ();
foreach (var item in hideObject.hideObjectList) {
item.hideFlags &= ~HideFlags.HideInHierarchy;
item.gameObject.SetActive (!item.gameObject.activeSelf);
item.gameObject.SetActive (!item.gameObject.activeSelf);
}
hideObject.hideObjectList.Clear ();
UnityEditor.EditorApplication.RepaintHierarchyWindow ();
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment