//read json
 public void ReadJson(JsonData json)
 {
     this.m_strName = json["name"].ToString();
     this.m_cRoot = null;
     if( json.Keys.Contains("node") )
     {
         string typename = json["node"]["type"].ToString();
         Type t = Type.GetType(typename);
         this.m_cRoot = Activator.CreateInstance(t) as BNode;
         this.m_cRoot.ReadJson(json["node"]);
     }
 }
예제 #2
0
        //replace child
        public void ReplaceChild(BNode prenode, BNode node)
        {
            int index = this.m_lstChildren.FindIndex((a) => { return(a == prenode); });

            this.m_lstChildren[index] = node;
        }
예제 #3
0
        //insert child
        public void InsertChild(BNode prenode, BNode node)
        {
            int index = this.m_lstChildren.FindIndex((a) => { return(a == prenode); });

            this.m_lstChildren.Insert(index, node);
        }
예제 #4
0
 //add child
 public void AddChild(BNode node)
 {
     this.m_lstChildren.Add(node);
 }
예제 #5
0
 //remove child
 public void RemoveChild(BNode node)
 {
     this.m_lstChildren.Remove(node);
 }
 //insert child
 public void InsertChild( BNode prenode , BNode node )
 {
     int index = this.m_lstChildren.FindIndex((a)=>{return a == prenode;});
     this.m_lstChildren.Insert(index,node);
 }
 //is contain child
 public bool ContainChild(BNode node)
 {
     return this.m_lstChildren.Contains(node);
 }
예제 #8
0
 //clear root node
 public void Clear()
 {
     this.m_cRoot = null;
 }
 //menu delete node
 private void menu_delete_node(object arg)
 {
     if(this.m_cParent != null )
     {
         this.m_cParent.RemoveChild(this);
     }
     this.m_cParent = null;
     BTreeWin.select = null;
     BTreeWin.cur_node = null;
     BTreeWin.sInstance.Repaint();
 }
 //replace child
 public void ReplaceChild( BNode prenode , BNode node )
 {
     int index = this.m_lstChildren.FindIndex((a)=>{return a == prenode;});
     this.m_lstChildren[index] = node;
 }
 //remove child
 public void RemoveChild( BNode node )
 {
     this.m_lstChildren.Remove(node);
 }
 //set root node
 public void SetRoot( BNode node )
 {
     this.m_cRoot = node;
 }
 //clear root node
 public void Clear()
 {
     this.m_cRoot = null;
 }
예제 #14
0
 //is contain child
 public bool ContainChild(BNode node)
 {
     return(this.m_lstChildren.Contains(node));
 }
 //add child
 public void AddChild( BNode node )
 {
     this.m_lstChildren.Add(node);
 }
    void OnGUI()
    {
        //////////////////// draw the tree /////////////////////
        this.m_cScrollPos = GUI.BeginScrollView(new Rect(0,0,position.width-240 , position.height) , this.m_cScrollPos , new Rect(0,0,this.maxSize.x,this.maxSize.y));

        Texture2D tex1 = new Texture2D(1,1);
        tex1.SetPixel(0,0,Color.black);
        tex1.Apply();
        Texture2D tex2 = new Texture2D(1,1);
        tex2.SetPixel(0,0,Color.gray);
        tex2.Apply();
        for(int i = 0 ; i<1000 ; i++ )
        {
            if(i%2==0)
                GUI.DrawTexture(new Rect(0,i*NODE_HEIGHT,BTreeWin.sInstance.position.width,NODE_HEIGHT),tex1);
            else
                GUI.DrawTexture(new Rect(0,i*NODE_HEIGHT,BTreeWin.sInstance.position.width,NODE_HEIGHT),tex2);
        }

        if(cur_tree != null && cur_tree.m_cRoot != null)
        {
            int xx = 0;
            int yy = 0;
            cur_tree.m_cRoot.Render(xx,ref yy);
        }

        GUI.EndScrollView();
        //////////////////// draw the tree /////////////////////

        //////////////////// draw editor gui /////////////////////
        GUI.BeginGroup(new Rect(position.width-GUI_WIDTH,0,300,1000));
        int x = 0;
        int y = 0;
        List<BTree> lst = BTreeMgr.sInstance.GetTrees();
        if(GUI.Button(new Rect(x,y,200,40),"Load"))
        {
            cur_tree = null;
            cur_node = null;
            cur_tree_index = -1;
            last_tree_index = -1;
            select_create_node_id = -1;
            select = null;

            BTreeMgr.sInstance.EditorLoad();
        }
        y+=40;
        if(GUI.Button(new Rect(x,y,200,40),"Save Editor BTree"))
        {
            BTreeMgr.sInstance.EditorSave();
            AssetDatabase.Refresh();
        }
        y+=40;
        if(GUI.Button(new Rect(x,y,200,40),"Save BTree"))
        {
        //			BTreeMgr.sInstance.SaveEx();
            AssetDatabase.Refresh();
        }
        y+=40;
        GUI.Label(new Rect(x,y,200,20) , "=======================");
        y+=20;

        this.m_strInputName = GUI.TextField(new Rect(x,y+10,100,20), this.m_strInputName);
        if( GUI.Button(new Rect(x+100,y,100,40) , "create tree"))
        {
            if(this.m_strInputName != "")
            {
                cur_node = null;
                BTree tree = new BTree();
                tree.m_strName = this.m_strInputName;
                BTreeMgr.sInstance.Add(tree);
                lst = BTreeMgr.sInstance.GetTrees();
                cur_tree = tree;
                for(int i = 0 ; i<lst.Count ; i++ )
                {
                    if(lst[i].m_strName == tree.m_strName)
                    {
                        cur_tree_index = i;
                        break;
                    }
                }
                last_tree_index = cur_tree_index;
                Repaint();
            }
        }
        y+=40;
        if(GUI.Button(new Rect(x,y,200,40), "remove tree"))
        {
            cur_node = null;
            BTreeMgr.sInstance.Remove(cur_tree);
            lst = BTreeMgr.sInstance.GetTrees();
            cur_tree = null;
            cur_tree_index = -1;
            last_tree_index = -1;
            Repaint();
        }
        y+=40;
        GUI.Label(new Rect(x,y,200,20) , "=======================");
        y+=20;

        string[] treeNames = new string[lst.Count];
        for(int i = 0 ; i<lst.Count ; i++ )
        {
            treeNames[i] = lst[i].m_strName;
        }
        cur_tree_index = EditorGUI.Popup(new Rect(x,y,200,45),cur_tree_index,treeNames);
        if(cur_tree_index != last_tree_index)
        {
            last_tree_index = cur_tree_index;
            cur_tree = lst[cur_tree_index];
            cur_node = null;
        }
        y+=40;
        GUI.Label(new Rect(x,y,200,20) , "=======================");
        y+=20;

        if(cur_tree != null)
        {
            GUI.Label(new Rect(x,y,200,20),"TreeName: "+cur_tree.m_strName);
            y+=20;
            cur_tree.m_strName = GUI.TextField(new Rect(x,y,100,20),cur_tree.m_strName);
            y+=20;
        }
        select_create_node_id = EditorGUI.Popup(new Rect(x,y,100,40),select_create_node_id,BNodeFactory.sInstance.GetNodeLst());
        if(GUI.Button(new Rect(x+100,y,100,40),"create root"))
        {
            if(select_create_node_id >= 0 )
            {
                BNode node = BNodeFactory.sInstance.Create(select_create_node_id);
                if(cur_tree != null )
                    cur_tree.m_cRoot = node;
            }
        }
        y+=40;
        if(GUI.Button(new Rect(x,y,200,40),"clear"))
        {
            if(cur_tree != null )
                cur_tree.Clear();
        }
        y+=40;
        GUI.Label(new Rect(x,y,200,20) , "=======================");
        y+=20;
        if(cur_node != null )
        {
            GUI.Label(new Rect(x,y,300,20),"Node Type: " + cur_node.GetType().FullName );
            y+=20;
            GUI.Label(new Rect(x,y,200,20),"Node Name: " + cur_node.GetName() );
            y+=20;
            GUI.Label(new Rect(x,y,200,15) , "=======================");
            y+=15;
            cur_node.RenderEditor(x,y);
        }
        //
        GUI.EndGroup();
        //////////////////// draw editor gui /////////////////////
    }
예제 #17
0
 //set root node
 public void SetRoot(BNode node)
 {
     this.m_cRoot = node;
 }