Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

232
Vistas
Mostrando un árbol binario en el problema de la unidad

Hice una función en Unity que toma un Binode y lo convierte en un árbol 2d, pero aquí el problema: mi supuesta idea para mostrar el árbol es esta:

haga una función recursiva, y cada vez que el nivel suba en 1, y también enviará a la función un bool (es el derecho o es el izquierdo del nodo anterior) y luego, si es cierto, obtendrá la raíz del nodo árbol y - la y por nivel * 55, entonces será x = nivel * 55, si está a la derecha, y si está a la izquierda, x = nivel * -55.

ahora el problema es digamos que tengo un árbol que tiene 3 niveles, entonces si pongo un nodo derecho en el árbol izquierdo, simplemente lo pondrá donde está el nodo más derecho y se superpondrá, un poco difícil de explicar en el texto pero espero que entiendas.

aquí está el repositorio: git

Imagen

código:

 public void GenrateTreeUI(BinNode<int> t, bool right, int Level) { if (Level == 0) { cir = Instantiate(CirclePrefab, new Vector2(0, 0), Quaternion.identity); t.SetGO(cir); cir.transform.SetParent(canvas.transform); cir.GetComponent<Image>().color = Color.black; roottr = cir.GetComponent<RectTransform>(); Value = cir.GetComponentInChildren<TMP_Text>(); roottr.anchoredPosition = new Vector2(-11, 213); Value.text = t.GetValue().ToString(); Value.color = Color.white; } else { if (!right) { cir = Instantiate(CirclePrefab, new Vector2(0, 0), Quaternion.identity); cir.transform.SetParent(canvas.transform); t.SetGO(cir); cir.GetComponentInChildren<TMP_Text>().text = t.GetValue().ToString(); cir.GetComponent<RectTransform>().anchoredPosition = new Vector2(roottr.anchoredPosition.x - Level * 55, roottr.anchoredPosition.y - (Level * 55)); } else { cir = Instantiate(CirclePrefab, new Vector2(0, 0), Quaternion.identity); cir.transform.SetParent(canvas.transform); t.SetGO(cir); cir.GetComponentInChildren<TMP_Text>().text = t.GetValue().ToString(); cir.GetComponent<RectTransform>().anchoredPosition = new Vector2(roottr.anchoredPosition.x + Level * 55, roottr.anchoredPosition.y - Level * 55); } } if (t.HasLeft()) { GenrateTreeUI(t.GetLeft(), false, Level + 1); GenrateWire(cir.GetComponent<RectTransform>().anchoredPosition, GetFutreNode(t.GetLeft(), Level, false)); } if (t.HasRight()) { GenrateTreeUI(t.GetRight(), true, Level + 1); GenrateWire(cir.GetComponent<RectTransform>().anchoredPosition, GetFutreNode(t.GetRight(), Level, true)); } }

¡gracias por la ayuda!

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda