void EnumerateTable(LunaTreeViewItem parent, LuaRef parentLuaRef, int depth) { if (depth <= 0) { return; } string parentPath = parent.fullPath; var it = parentLuaRef.GetEnumerator(); while (it.MoveNext()) { var key = it.Current.Key(); var k = key.ToString(); if (k == "_G") { continue; } var v = it.Current.Value(); string fullPath = string.Join(".", parentPath, k); int hash = fullPath.GetHashCode(); if (!treeViewItems.TryGetValue(hash, out var tvi)) { id2v[hash] = v; id2fullPath[hash] = fullPath; string strDisplay = k; if (v.Type <= LuaType.String) { strDisplay += (" : " + v.ToString()); } tvi = new LunaTreeViewItem { id = hash, depth = parent.depth + 1, displayName = strDisplay }; tvi.fullPath = fullPath; tvi.luaType = v.Type; treeViewItems[hash] = tvi; parent.AddChild(tvi); } if (v.IsTable) { tvi.icon = EditorGUIUtility.FindTexture("Folder Icon"); EnumerateTable(tvi, v, depth - 1); } } it.Dispose(); parent.children?.Sort(); }
protected override TreeViewItem BuildRoot() { var root = new TreeViewItem { id = 0, depth = -1, displayName = "_G" }; SetExpanded(0, true); if (luna != null) { string fullPath = "_G"; int hash = fullPath.GetHashCode(); var item = new LunaTreeViewItem { id = hash, depth = 1, displayName = "_G" }; LuaRef luaRef = luna.Global; item.luaType = luaRef.Type; item.fullPath = fullPath; id2v[hash] = luaRef; id2fullPath[hash] = fullPath; treeViewItems[hash] = item; lastExpendedIDs.Clear(); lastExpendedIDs.Add(hash); SetExpanded(hash, true); item.icon = EditorGUIUtility.FindTexture("Folder Icon"); root.AddChild(item); EnumerateTable(item, luaRef, 2); } else { var item = new TreeViewItem { id = 0, depth = 1, displayName = "_G" }; root.AddChild(item); } // Return root of the tree return(root); }