Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 10/01/2014 in all areas

  1. 1 point
    Here's a script to add 2 menu items to the editor (just put it in your Editor directory), and shortcut keys to do what you want: SHIFT+H: Hide Unselected objects CTRL+SHIFT+H: Unhide all using UnityEngine; using UnityEditor; using System.Collections.Generic; public class RadiangamesMenus : ScriptableObject { [MenuItem("Custom/Visibility/Unhide All %#h")] static void UnhideAll() { UnhideAllObjects(); } [MenuItem("Custom/Visibility/Hide Unselected #h")] static void HideUnselected() { HideUnselectedObjects(); } public static void UnhideAllObjects() { object[] obj = GameObject.FindObjectsOfType(typeof(GameObject)); foreach (object o in obj) { GameObject go = (GameObject)o; if (go != null) { ToggleHidden(go, false, true); } } } public static void HideUnselectedObjects() { InvertSelection(); foreach (object o in Selection.objects) { GameObject go = (GameObject)o; if (go != null) { ToggleHidden(go, true); } } InvertSelection(); } public static void ToggleHidden(GameObject go, bool should_hide = false, bool should_unhide = false) { Renderer[] renderers = go.GetComponentsInChildren<Renderer>(); foreach (Renderer r in renderers) { if (should_hide) { r.enabled = false; } else if (should_unhide) { r.enabled = true; } else { r.enabled = !r.enabled; } } } public static void InvertSelection() { List<GameObject> oldSelection = new List<GameObject>(); List<GameObject> newSelection = new List<GameObject>(); foreach (GameObject obj in Selection.GetFiltered(typeof(GameObject), SelectionMode.ExcludePrefab)) oldSelection.Add(obj); foreach (GameObject obj in FindObjectsOfType(typeof(GameObject))) { if (!oldSelection.Contains(obj)) newSelection.Add(obj); } Selection.objects = newSelection.ToArray(); } }
×