Created
April 23, 2014 14:54
-
-
Save tsubaki/11218517 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.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