PROGRAMING📚/🔖Unity3D
[UNITY::북마크]하이어라키상(hierarchy)의 선택한 오브젝트를 제외한 오브젝트 모두 끄기
__이니__
2025. 5. 29. 10:41
https://github.com/hahahohohun/PublicCode/blob/main/Tools/Tools/ECCustomTools.cs
PublicCode/Tools/Tools/ECCustomTools.cs at main · hahahohohun/PublicCode
Contribute to hahahohohun/PublicCode development by creating an account on GitHub.
github.com
https://funfunhanblog.tistory.com/403
[유니티 커스텀 에디터] 하이어라키상(hierarchy)의 선택한 오브젝트를 제외한 오브젝트 모두 끄기
선택한 오브젝트를 제외한 오브젝트의 SetActive를 false처리한다. 단축키는 Ctrl + Shift + Q ----------------------------------------------------------------------------------- 2021.12.13 단축키를 사용하기전에 애초에 꺼
funfunhanblog.tistory.com
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ECCustomTools : MonoBehaviour
{
public static bool _bActive = true;
public static List<GameObject> _undolist = new List<GameObject>();
private void Awake()
{
_bActive = true;
_undolist.Clear();
}
[MenuItem("GameObject/IsolateActive %#q")]
public static void IsolateActive()
{
_bActive = !_bActive;
var list = Selection.GetTransforms(SelectionMode.TopLevel);
if (!_bActive)
{
foreach (var item in list)
{
Transform traParent = item.parent;
if (traParent != null)
{
for (int i = 0; i < traParent.childCount; i++)
{
SetActive(traParent.GetChild(i).gameObject, list);
}
}
else
{
GameObject[] all_Objs = SceneManager.GetActiveScene().GetRootGameObjects();
foreach (GameObject g in all_Objs)
{
SetActive(g, list);
}
}
}
}
else
{
foreach (var item in _undolist)
{
item.SetActive(true);
}
_undolist.Clear();
}
}
private static void SetUndo(GameObject obj)
{
Undo.RegisterCompleteObjectUndo(obj, "GameObject/IsolateActive");
_undolist.Add(obj);
obj.SetActive(false);
}
private static void SetActive(GameObject obj, Transform[] list)
{
bool bSame = false;
foreach (var cur in list)
{
if (cur == obj.transform)
{
bSame = true;
break;
}
}
if (!bSame && obj.activeSelf)
{
SetUndo(obj);
}
}
}