namespace UIWidgets.Examples
{
using System.Collections.Generic;
using UIWidgets;
using UnityEngine;
///
/// Test TreeGraph.
///
public class TestTreeGraph : MonoBehaviour
{
///
/// Graph.
///
[SerializeField]
public TreeGraph Graph;
///
/// Nodes.
///
protected ObservableList> Nodes;
///
/// Start this instance.
///
protected virtual void Start()
{
Graph.Init();
Graph.Nodes = Nodes;
}
///
/// Initializes a new instance of the class.
///
public TestTreeGraph()
{
var config = new List() { 1, 3, 2, };
Nodes = GenerateTreeNodes(config, isExpanded: true);
}
///
/// Generate tree nodes.
///
/// Depth list.
/// Start part of name.
/// Is nodes expanded?
/// Start index in the depth list.
/// Nodes.
public static ObservableList> GenerateTreeNodes(List items, string nameStartsWith = "Node ", bool isExpanded = true, int start = 0)
{
var count = items[start];
var result = new ObservableList>(true, count);
result.BeginUpdate();
for (int i = 0; i < count; i++)
{
var item_name = string.Format("{0}{1}", nameStartsWith, (i + 1).ToString());
var item = new TreeViewItem(item_name, null);
var nodes = items.Count > (start + 1)
? GenerateTreeNodes(items, string.Format("{0} - ", item_name), isExpanded, start + 1)
: null;
result.Add(new TreeNode(item, nodes, isExpanded));
}
result.EndUpdate();
return result;
}
}
}