Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
Colapsar objetos de juego seleccionados en la jerarquía

Estoy colapsando un gameObject principal seleccionado con este script de editor. Todo funciona bien, pero también colapsa otros gameObjects expandidos, lo que no debería suceder. Por ejemplo, bajo dos padres diferentes, si colapso un gameObject principal, incluso el otro gameObject principal se colapsa. ¿Cómo no dejo que esto suceda?

Siento que el problema está en rootGameObjects.AddRange (SceneManager.GetSceneAt (i).GetRootGameObjects ()); donde toma el gameObject raíz en una escena pero no el gameObject seleccionado en la jerarquía.

 using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; using UnityEngine.SceneManagement; public static class CollapseTools { private static int wait = 0; private static int undoIndex; public static void CollapseGameObjects () { EditorApplication.update -= CollapseGameObjects; CollapseGameObjects (new MenuCommand (null)); } [MenuItem ("GameObject/Collapse GameObjects", priority = 40)] private static void CollapseGameObjects (MenuCommand command) { // This happens when this button is clicked via hierarchy's right click context menu // and is called once for each object in the selection. We don't want that, we want // the function to be called only once if (command.context) { EditorApplication.update -= CollapseGameObjects; EditorApplication.update += CollapseGameObjects; return; } List<GameObject> rootGameObjects = new List<GameObject> (); #if UNITY_2018_3_OR_NEWER // Check if a prefab stage is currently open var prefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage (); if (prefabStage != null && prefabStage.stageHandle.IsValid ()) rootGameObjects.Add (prefabStage.prefabContentsRoot); else #endif { int sceneCount = SceneManager.sceneCount; for (int i = 0; i < sceneCount; i++) rootGameObjects.AddRange (SceneManager.GetSceneAt (i).GetRootGameObjects ()); } if (rootGameObjects.Count > 0) { Undo.IncrementCurrentGroup (); Selection.objects = Selection.objects; undoIndex = Undo.GetCurrentGroup (); Selection.objects = rootGameObjects.ToArray (); EditorApplication.update -= CollapseHelper; EditorApplication.update += CollapseHelper; } } private static void CollapseHelper () { if (wait < 1) // Increase the number if script doesn't always work wait++; else { EditorApplication.update -= CollapseHelper; wait = 0; EditorWindow focusedWindow = EditorWindow.focusedWindow; if (focusedWindow != null) focusedWindow.SendEvent (new Event { keyCode = KeyCode.LeftArrow, type = EventType.KeyDown, alt = true }); Undo.RevertAllDownToGroup (undoIndex); } } }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

ingrese la descripción de la imagen aquí

Cuando se trata de Unity, nada supera la reflexión:

 using UnityEditor; using UnityEngine; internal class MyClass : EditorWindow { private void OnGUI() { using (var scope = new EditorGUI.DisabledGroupScope(Selection.activeGameObject == null)) { if (GUILayout.Button("Expand Recursive")) { var type = typeof(EditorWindow).Assembly.GetType("UnityEditor.SceneHierarchyWindow"); var window = GetWindow(type); var exprec = type.GetMethod("SetExpandedRecursive"); exprec!.Invoke(window, new object[] {Selection.activeGameObject.GetInstanceID(), true}); } } } [MenuItem("TEST/TEST")] private static void Init() { GetWindow<MyClass>(); } }

Consulte la clase SceneHierarchyWindow para ver otras cosas a las que podría conectarse.

Ahora tienes otro problema, cuando tienes varias ventanas de jerarquía abiertas, te dejaré resolver esa :)

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda