public void AddNode(DesignerTreeNode _node) { Childs.Add(_node); }
public void Init() { TreeNodes = new List<DesignerTreeNode>(); //获取程序集里面所有的任务 Assembly assembly = null; List<Type> list = new List<Type>(); string[] strs = new string[] { "Assembly-CSharp" }; //new string[] { "Assembly-CSharp", "Assembly-UnityScript", "Assembly-UnityScript-firstpass", "Assembly-CSharp-firstpass" }; for (int i = 0; i < strs.Length; i++) { try { assembly = Assembly.Load(strs[i]); if (assembly != null) { Type[] types = assembly.GetTypes(); for (int j = 0; j < types.Length; j++) { if (types[j].IsSubclassOf(typeof(ActionBase))) {//是ActionBase的子类 list.Add(types[j]); } } } } catch { } } list.Sort(new AlphanumComparator<Type>()); //形成树状结构 Dictionary<string, DesignerTreeNode> dictionary = new Dictionary<string, DesignerTreeNode>(); int id = 0; for (int k = 0; k < list.Count; k++) { ActionPathAttribute[] array; string pp = ""; DesignerTreeNode node = null, node_parent = null; if ((array = (list[k].GetCustomAttributes(typeof(ActionPathAttribute), false) as ActionPathAttribute[])).Length > 0) { string[] datas = array[0].path.Split('/'); for (int l = 0; l < datas.Length; l++) { if (l > 0) { pp += "/"; } pp += datas[l]; if (!dictionary.ContainsKey(pp)) { node = new DesignerTreeNode(datas[l], pp, false, id++); if (node_parent == null) { TreeNodes.Add(node); } else { node_parent.AddNode(node); } dictionary.Add(pp, node); } else { node = dictionary[pp]; } node_parent = node; } dictionary[pp].AddTask(list[k]);//末尾节点赋予任务 } } if (!string.IsNullOrEmpty(SearchStr)) { //搜索 Search(SearchStr.ToLower().Replace(" ", ""), TreeNodes); } }
/// <summary> /// 绘制树的叶子结点 /// </summary> /// <param name="window"></param> /// <param name="node"></param> private void DrawCategory(DesignerWindow window, DesignerTreeNode node) { if (node.Visible) { node.Expanded = EditorGUILayout.Foldout(node.Expanded, node.Name, DesignerHelp.TaskFoldoutGUIStyle); // this.SetExpanded(node.ID, node.Expanded); if (node.Expanded) { EditorGUI.indentLevel = EditorGUI.indentLevel + 1; if (node.Tasks != null) { for (int i = 0; i < node.Tasks.Count; i++) { if (node.Tasks[i].Visible) { GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Space((float)(EditorGUI.indentLevel * 10)); if (GUILayout.Button(node.Tasks[i].Type.Name.ToString(), EditorStyles.toolbarButton, new GUILayoutOption[0])) {//点击按钮,添加一个任务 window.addTask(node.Tasks[i].Type, false); } GUILayout.Space(3f); GUILayout.EndHorizontal(); } } } if (node.Childs != null) { this.DrawCategoryTaskList(window, node.Childs); } EditorGUI.indentLevel = EditorGUI.indentLevel - 1; } } }