public void AddElement(ScriptableObject newObject)
    {
        var rows    = GetRows();
        var newItem = DatabaseViewerItem.CreateFromUnityObject(newObject, this);

        rootItem.AddChild(newItem);
        rows.Add(newItem);

        Sort(rows);

        Repaint();
    }
    protected override TreeViewItem BuildRoot()
    {
        Object[] objs = null;

        //scriptable object type can be find fast through the find method, but monobheaviour need to be queried on EVERY PREFABS IN THE PROJECTS
        //TODO : find a better way, this will probably become VERY SLOW on big project with thousand of prefabs
        if (_objectType.isScriptableObject)
        {
            string[] assets = AssetDatabase.FindAssets("t:" + _objectType.type.ToString());
            objs = new Object[assets.Length];

            for (int i = 0; i < assets.Length; ++i)
            {
                objs[i] = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(assets[i]), _objectType.type);
            }
        }
        else
        {
            objs = new Object[0];
            string[] assets = AssetDatabase.FindAssets("t:Prefab");

            for (int i = 0; i < assets.Length; ++i)
            {
                Object obj = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(assets[i]), _objectType.type);
                if (obj != null)
                {
                    ArrayUtility.Add(ref objs, obj);
                }
            }
        }

        TreeViewItem root = new TreeViewItem();

        root.depth    = -1;
        root.id       = -1;
        root.parent   = null;
        root.children = new List <TreeViewItem>();

        if (objs != null)
        {
            for (int i = 0; i < objs.Length; ++i)
            {
                var child = DatabaseViewerItem.CreateFromUnityObject(objs[i], this);

                root.AddChild(child);
            }
        }

        return(root);
    }
Exemple #3
0
        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"
            };

            root.parent = null;

            root.children = new List <TreeViewItem>();


            while (reader.Read())
            {
                List <string> cellValues = new List <string>();


                for (int i = 0; i < reader.FieldCount; i++)
                {
                    cellValues.Add(reader[i].ToString());
                }



                DatabaseViewerItem item = DatabaseViewerItem.CreateFromUnityObject(cellValues);
                //item.icon =
                //item.id = GetNewID();


                root.children.Add(item);
            }



            // Utility method that initializes the TreeViewItem.children and .parent for all items.
            //SetupDepthsFromParentsAndChildren(root);
            //SetupParentsAndChildrenFromDepths (root, root.children);
            //SetupDepthsFromParentsAndChildren(root);
            // Return root of the tree
            return(root);
        }