public void addChild(string name, CCNode node)
 {
     if (children == null)
     {
         children = new Dictionary<string, CCNode>();
     }
     children.Add(name, node);
 }
 public static UiPropertyGrid create(CCNode node, FieldInfo field)
 {
     UiPropertyGrid grid = new UiPropertyGrid();
     if (grid.init(node, field))
     {
         return grid;
     }
     return null;
 }
 private void InitWithCCNode(CCNode node, CCNode selectNode=null)
 {
     Reset();
     mBaseNode = node;
     mSelectNode = selectNode;
     mSelectTreeNode = null;
     mNodesTree.Nodes.Add(CreateTreeNode("base", node));
     mNodesTree.SelectedNode = mNodesTree.Nodes[0];
     if (mSelectTreeNode != null)
         mNodesTree.SelectedNode = mSelectTreeNode;
     
     mNodesTree.ExpandAll();
 }
 bool init(CCNode node, FieldInfo field)
 {
     MethodInfo method = field.FieldType.GetMethod("Parse", new[]{typeof(string)} );
     if ((node == null || field == null || method == null) &&
         field.FieldType.Name.ToLower() != "string")
     {
         return false;
     }
     mInitDone = true;
     mBindField = field;
     mBindNode = node;
     mNameLabel.Text = field.Name;
     mEditor.Text = GetProperty();
     return true;
 }
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>

        static void Test()
        {
            Type type = typeof(CCMenuItemSprite);
            ConstructorInfo info = type.GetConstructor(new Type[] { });

            CCNode node = new CCNode();
            node.position = new CCPoint();

            CCNodeRGBA node1 = new CCNodeRGBA();
            node1.opacity = 1;

            node.addChild("123", node1);

            List<Type> knowtypes = new List<Type>();
            foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (t.Namespace == "UiEditor.UI")
                {
                    knowtypes.Add(t);
                }

            }
            /*
            JsonSerializerSettings setting = new JsonSerializerSettings();
            //setting.ObjectCreationHandling = ObjectCreationHandling.;
            setting.TypeNameHandling = TypeNameHandling.Auto;
            setting.TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple;
            
            string json = JsonConvert.SerializeObject(node, Formatting.Indented, setting);
            //Console.Write(node.ToJson());
            Console.Write(json);

            //JsonConvert.DeserializeObject(json, typeof(CCNode));
            CCNode node2 = JsonConvert.DeserializeObject<CCNode>(json, setting);*/

            string json = node.ToJson();
            Console.Write(json);

            CCNode node3 = CCNode.FromJson<CCNode>(json);
            

            /*DataContractJsonSerializer json = new DataContractJsonSerializer(node.GetType(), knowtypes);
            MemoryStream stream = new MemoryStream();

            json.WriteObject(stream, node);
            string jsonsz = Encoding.UTF8.GetString(stream.ToArray());
            Console.Write(jsonsz);*/
        }
 private CCTreeNode CreateTreeNode(string name, CCNode node)
 {
     List<CCTreeNode> children = new List<CCTreeNode>();
     if (node.children != null)
     {
         foreach (KeyValuePair<string, CCNode> kvp in node.children)
         {
             CCTreeNode treenode = CreateTreeNode(kvp.Key, kvp.Value);
             if (kvp.Value == mSelectNode)
             {
                 mSelectTreeNode = treenode;
             }
             children.Add(treenode);
         }
     }
     return new CCTreeNode(name, children.ToArray(), node);
 }
 public void InitWithCCNode(CCNode node)
 {
     BindCCNode = node;
     Type type = node.GetType();
     FieldInfo[] fields = type.GetFields();
     this.Controls.Clear();
     Label label = new Label();
     label.Text = type.ToString();
     label.Location = new Point(4, 25);
     label.AutoSize = true;
     this.Controls.Add(label);
     for (int i = 0; i < fields.Length; i++)
     {
         if (fields[i].Name.ToLower() == "children")
         {
             continue;
         }
         UiPropertyGrid grid = UiPropertyGrid.create(node, fields[i]);
         grid.Location = new Point(4, 30 * i + 50);
         this.Controls.Add(grid);
     }
 }        
 public CCTreeNode(string name, CCTreeNode[] children, CCNode node)
     : base(name, children)
 {
     this.CCNode = node;
 }
 private void Reset()
 {
     mNodesTree.Nodes.Clear();
     mPropertyWidget.Controls.Clear();
     mBaseNode = null;
 }
        private void OnPastClick(object sender, EventArgs e)
        {
            CCTreeNode tSelNode = (CCTreeNode)mNodesTree.SelectedNode;
            if (tSelNode == null)
                return;
            if (mCopyNode == null)
                return;

            string name = GetInput();
            if (name == null)
            {
                return;
            }

            tSelNode.CCNode.addChild(name, mCopyNode);

            mBaseNode = CCNode.FromJson<CCNode>(mBaseNode.ToJson());
            mBaseNode = CCNode.FromJson<CCNode>(mBaseNode.ToJson());
            InitWithCCNode(mBaseNode);
        }
        private void OnCopyClick(object sender, EventArgs e)
        {
            CCTreeNode tSelNode = (CCTreeNode)mNodesTree.SelectedNode;
            if (tSelNode == null)
                return;

            mCopyNode = tSelNode.CCNode;
        }