示例#1
0
    public void generategroundpath(node node, pathbranch current)
    {
        if (node == null)
        {
            Debug.Log("node null");
            return;
        }

        List <node> neighbor = new List <node>();

        foreach (var item in map.map)
        {
            if (node == item)
            {
                neighbor = item.neighbor;
            }
        }
        float   mindis     = 10000000;
        Vector3 select     = new Vector3(0, 0, 0);
        node    selectnode = null;

        //select last node
        foreach (var item in neighbor)
        {
            if (checker(item.Placer) <= 0 && item.select == false)
            {
                select      = item.position;
                selectnode  = item;
                item.select = true;
            }
        }

        //select many node
        if (selectnode == null)
        {
            foreach (var item in neighbor)
            {
                {
                    //find min score for all neighbor
                    mindis = findminscore(item, mindis);

                    foreach (var item2 in allscore)
                    {
                        if (item.position == item2.position && item.havebase == false && item.select == false)
                        {
                            if (mindis == item2.finaldistant)
                            {
                                if (selectnode != null)
                                {
                                    selectnode.select = false;
                                }

                                select     = item2.position;
                                selectnode = item;
                                if (item.position != final)
                                {
                                    item.select = true;
                                }
                            }
                        }
                    }
                }
            }
        }

        current.waypoint.Add(select);
        if (select != final && selectnode != null)
        {
            generategroundpath(selectnode, current);
        }
        else if (select == final && selectnode != null)
        {
            current.finish = true;
        }
        else
        {
            /*current.waypoint.RemoveAt(current.waypoint.Count-1);
             *
             * foreach (var item in current.waypoint)
             * {
             *  foreach (var item2 in map.map)
             *  {
             *      if(item2.position==item)
             *      {
             *          selectnode = item2;
             *      }
             *  }
             * }
             * Debug.Log(selectnode.name);*/
            //generategroundpath(selectnode, current);
        }
    }
示例#2
0
 public void newbranch(pathbranch current, string name)
 {
     allbranch.Add(new pathbranch(name));
 }
示例#3
0
    public void intothegraph()
    {
        if (groundpath || boss)
        {
            foreach (var item in showbox)
            {
                Destroy(item);
            }
            showbox.Clear();

            //point.Clear();

            setscore();
            allbranch.Add(new pathbranch("start1", start));
            allbranch.Add(new pathbranch("start2", start));
            allbranch.Add(new pathbranch("start3", start));
        }

        foreach (Transform child in transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        foreach (var item in map.map)
        {
            item.select = false;
        }

        node startnode = new node();

        foreach (var item in map.map)
        {
            if ((item.position == start))
            {
                item.select = true;
                startnode   = item;
                break;
            }
        }
        if (startnode != null)
        {
            foreach (var item2 in allbranch)
            {
                if (groundpath)
                {
                    generategroundpath(startnode, item2);
                }
                else if (airpath)
                {
                    showpath();
                }
            }
        }



        pathbranch selectbranch = null;
        int        minpath      = 1000;

        foreach (var item2 in allbranch)
        {
            if (item2.finish && item2.waypoint.Count < minpath)
            {
                minpath      = item2.waypoint.Count;
                selectbranch = item2;
                point.Clear();
                if (useturnvanguard)
                {
                    point.Add(turnvanguard);
                }
                point.AddRange(selectbranch.waypoint);
            }
        }
        point.Add(sattelitepoint);
        showpath();
        complete = true;
    }