Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Help IMGUI

Iniciado por Tizon, Junio 18, 2017, 01:47:46 PM

Tema anterior - Siguiente tema
Hola a todos, y perdón por esta consulta que seguramente resulte tonta.
 
He descubierto un control que me interesa bastante, el TreeView. El caso es que cuando lo implemento, me salta error. Miro en la documentación y me dice que cuelga de la IMGUI, así que tiro como me indica la documentación un using Unit***itor.IMGUI, pero no me lo encuentra. He tratado de verificar que la IMGUI ni esté obsoleta, pero el caso es que por lo que parece sigue activa, así que no sé que me falta para que me lo coja. Si alguien puede orientarme estaría muy agradecido.
 
Muchas gracias a todos.

Por curiosidad lo he probado, he sacado el código del manual de Unity, esto es lo que he puesto y funciona. Espero que te sirva.
 
 
 

using UnityEngine;
using Unit***itor;
using System;
using System.Collections;
using System.Collections.Generic;
using Unit***itor.IMGUI.Controls;
class SimpleTreeView : TreeView
{
    public SimpleTreeView(TreeViewState treeViewState)
        : base(treeViewState)
    {
        Reload();
    }
    protected override TreeViewItem BuildRoot()
    {
        // BuildRoot is called every time Reload is called to ensure that TreeViewItems
        // are created from data. Here we create a fixed set of items. In a real world example,
        // a data model should be passed into the TreeView and the items created from the model.
        // This section illustrates that IDs should be unique. The root item is required to
        // have a depth of -1, and the rest of the items increment from that.
        var root = new TreeViewItem { id = 0, depth = -1, displayName = "Root" };
        var allItems = new List<TreeViewItem>
        {
            new TreeViewItem {id = 1, depth = 0, displayName = "Animals"},
            new TreeViewItem {id = 2, depth = 1, displayName = "Mammals"},
            new TreeViewItem {id = 3, depth = 2, displayName = "Tiger"},
            new TreeViewItem {id = 4, depth = 2, displayName = "Elephant"},
            new TreeViewItem {id = 5, depth = 2, displayName = "Okapi"},
            new TreeViewItem {id = 6, depth = 2, displayName = "Armadillo"},
            new TreeViewItem {id = 7, depth = 1, displayName = "Reptiles"},
            new TreeViewItem {id = 8, depth = 2, displayName = "Crocodile"},
            new TreeViewItem {id = 9, depth = 2, displayName = "Lizard"},
        };
        // Utility method that initializes the TreeViewItem.children and .parent for all items.
        SetupParentsAndChildrenFromDepths(root, allItems);
        // Return root of the tree
        return root;
    }
}
         
         
using System.Collections.Generic;
using UnityEngine;
using Unit***itor.IMGUI.Controls;
using Unit***itor;
using System;
using System.Collections;
class SimpleTreeViewWindow : EditorWindow
{
    // SerializeField is used to ensure the view state is written to the window
    // layout file. This means that the state survives restarting Unity as long as the window
    // is not closed. If the attribute is omitted then the state is still serialized/deserialized.
    [SerializeField] TreeViewState m_TreeViewState;
    //The TreeView is not serializable, so it should be reconstructed from the tree data.
    SimpleTreeView m_SimpleTreeView;
    void OnEnable()
    {
        // Check whether there is already a serialized view state (state
        // that survived assembly reloading)
        if (m_TreeViewState == null)
            m_TreeViewState = new TreeViewState();
        m_SimpleTreeView = new SimpleTreeView(m_TreeViewState);
    }
    void OnGUI()
    {
        m_SimpleTreeView.OnGUI(new Rect(0, 0, position.width, position.height));
    }
    // Add menu named "My Window" to the Window menu
    [MenuItem("TreeView Examples/Simple Tree Window")]
    static void ShowWindow()
    {
        // Get existing open window or if none, make a new one:
        var window = GetWindow<SimpleTreeViewWindow>();
        window.titleContent = new GUIContent("My Window");
        window.Show();
    }
}

 
 

Gracias por la respuesta @Miguel_Angel
 
Precisamente he visto esos ejemplos y quería jugar con ellos.
 
El problema me viene en el using Unit***itor.IMGUI.Controls; Me dice que no lo reconoce, y evidentemente, cuando lo edito, no encuentra el IMGUI, por lo que al no poderlo cargar, ya no me reconoce los controles, incluido el TreeView, que es con el que quiero jugar un poco.
 
Al menos me queda claro que es un problema de mi Unity, no de que sea obsoleto. Lo que no sé es que tengo que cargar para que me reconozca el using al IMGUI.

Cita de: Tizon date=1497873885Gracias por la respuesta @Miguel_Angel
   
   
      Precisamente he visto esos ejemplos y quería jugar con ellos.
   
   
      El problema me viene en el using Unit***itor.IMGUI.Controls; Me dice que no lo reconoce, y evidentemente, cuando lo edito, no encuentra el IMGUI, por lo que al no poderlo cargar, ya no me reconoce los controles, incluido el TreeView, que es con el que quiero jugar un poco.
   
   
      Al menos me queda claro que es un problema de mi Unity, no de que sea obsoleto. Lo que no sé es que tengo que cargar para que me reconozca el using al IMGUI.
   


Yo estoy usando la versión 5.6.1f1. Igual si pruebas otra versión no te da problemas. A mi por lo menos no me da ningún error, sin hacer nada, simplemente copiando y pegando funciona.

Cita de: Miguel_Angel date=1497886466Yo estoy usando la versión 5.6.1f1. Igual si pruebas otra versión no te da problemas. A mi por lo menos no me da ningún error, sin hacer nada, simplemente copiando y pegando funciona.
   


Pues es verdad. He actualizado y me ha funcionado.
 
Menos mal, por qué mirando la documentación lo veía documentado en versiones anteriores a la mía, así que si no me lo dices, no se me ocurre actualizarlo. Muchas gracias!!!

Etiquetas: