GenericMenu.MenuFunction OnNodeCreate(Type t) { if (m_curTree == null) { return(null); } if (m_curTree.Root != null && !m_treeMap.ContainsKey(m_selectRow)) { return(null); } GenericMenu.MenuFunction func; func = delegate(){ BNode newNode = Activator.CreateInstance(t) as BNode; if (m_curTree.Root == null) { m_curTree.SetRoot(newNode); } else { BNode parent = m_treeMap[m_selectRow]; parent.AddNode(newNode); } Repaint(); }; return(func); }
BNode ReadJsonNode(JsonData json) { string typeName = json["typeFullName"].ToString(); Type type = Type.GetType(typeName); JsonData jsonNode = json["node"]; BNode node = Activator.CreateInstance(type) as BNode; FieldInfo[] fields = type.GetFields(); for (int i = 0; i < fields.Length; i++) { FieldInfo field = fields[i]; string strVal = jsonNode[field.Name].ToString(); object val = null; if (field.FieldType == typeof(int)) { val = int.Parse(strVal); } else if (field.FieldType == typeof(float)) { val = float.Parse(strVal); } else if (field.FieldType == typeof(bool)) { val = bool.Parse(strVal); } else if (field.FieldType == typeof(string)) { val = strVal; } field.SetValue(node, val); } for (int i = 0; i < json["children"].Count; i++) { JsonData childJson = json["children"][i]; BNode childNode = ReadJsonNode(childJson); node.AddNode(childNode); } return(node); }